Community Forum

Is it possible to have an updateable running when still in the placementScreen?

Forum Overview >> Scripting

Created28.04.2017 22:08

Tim Derks (timmiej93) 28.04.2017 22:10
Like the title says, I'd like to have an updateable (basically just the update(dt) function) running as soon as the "new()" function of a placeable is called, so while still in the placementScreen. I want to do this to make it possible to raise or lower the height of a placeable.

Is this possible? When I try to add an updateable manually in the "new()" function, referring to a different object (or self for that matter)(lua table that contains a new() and update(dt) function), I get an error telling me that "No network objects allowed in addUpdateable"

Emil Drefers (Unknown) 02.05.2017 06:48

you don't need to add the placeable to the "updateables", because Placeable inherits from Object
local Placeable_mt = Class(Placeable, Object);
and Object does call update().

I think you would need to change the PlacementScreen to enable another "dimension of position adjustment".
But really not sure what you wanna do there exactly.


Tim Derks (timmiej93) 02.05.2017 19:59
Hi Emil,

That would indeed be preferred, but that's a little bit more difficult for me since there's no documentation available for the GUI.
To clarify, I'd like to be able to change the height of a placeable before it's actually placed. So instead of snapping to the ground, I'd like to give the option to set a manual height, either raised above, or lowered into the ground.


Emil Drefers (Unknown) 03.05.2017 06:59

a function that is frequently called during the placing process is:
function Placeable:getCanBePlacedAt(x, y, z, distance)
You could change something of your Placeable within that function.

But "placeable.nodeId" will always be placed at terrain height.
Maybe you can do something with the hierachy inside your placeable.

By the way, what kind of object/placeable are you modding?
Honestly I can't imagine what object would be placed on the ground or 'in the air'?


Tim Derks (timmiej93) 03.05.2017 22:39
Hi Emil,

The plan indeed is to have a child of the base node translate up and down, with the base node being invisible.
The object I'm making is a light fixture that is normally placed against a wall. Instead of having it fixed at height X, I'd like to give the person playing the game the option to place it at the correct height for them.

About the Placeable:getCanBePlacedAt(x,y,z, distance) method, how exactly would that work? I've been messing around with it, but it doesn't seem to do anything for me. When I use it in a placeable, I get the x,y,z and distance values, but returning true or false doesn't change if i'm able to place the placeable or not, which is what I was expecting.


Note: Log in to post. Create a new account here.