variable in other scene is returning nil even when set #46
-
so i have two scenes; in suspensionarm.lua, im only putting data (variables) under basevehicle i put a node named "wheels" to contain the suspensionarms when i try to assign a node to v.ray (declared as suspensionarm.ray = nil in its script or not) it still prints nil, why is this happening? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Hey @TrainzMarcel. Now, if you had the Lua script instance that is attached to the Object instead of the Object itself, it wouldn't matter if the property was declared or not to Godot and you would be able to set/get it without any fuzz, Lua table style. You can get the Lua script instance today by using Ok, so for now, either declare the property using Thanks for the insight! |
Beta Was this translation helpful? Give feedback.
-
Oh, also, next time you could paste your code using code blocks instead of posting an image. This is useful so that people could copy/paste the code to test it out. You use triple backticks (```) + language name to start a syntax-colored code block (like: ```lua). Then another triple backticks to end the block. It appears like this: -- This will appear as lua code
local msg = "Hello Lua"
print(msg) |
Beta Was this translation helpful? Give feedback.
-
FYI, I created issue #47 regarding automatic unboxing of Lua script instances. |
Beta Was this translation helpful? Give feedback.
Hey @TrainzMarcel.
Well, setting something to
nil
in Lua is the same as deleting it from the table. So to declare an Object property with default value ofnull
, you should usesuspensionarm.ray = Object.null
. This would declare a property in the script's manifest, so it could be accessed by GDScript or by Godot Objects in Lua viaget/get_indexed/set/set_indexed
.Now, if you had the Lua script instance that is attached to the Object instead of the Object itself, it wouldn't matter if the property was declared or not to Godot and you would be able to set/get it without any fuzz, Lua table style. You can get the Lua script instance today by using
GD.get_lua_instance(v)
. But now that I'm thin…