![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | arkiel |
Godot 3.0
I think I may have gotten a bad tutorial.
I wanted to be able to change motionspeed in the inspector, so I created
export(int) var MOTION_SPEED
This causes MOTION_SPEED to appear as a script variable in the inspector. Very Unity-esque.
I modified my motion vectors in the appropriate place with:
motion = motion*MOTION_SPEED
However, when I try to run the script, this line returns "Invalid operands ‘Vector2’ and ‘Nil’ in operator ‘*’. If MOTION_SPEED is hardcoded with a number, this problem vanishes and the hardcoded multiplier controls. But no inspector manipulation.
So I read up on the export variable cheat sheet, and found out about setget. So now my exported variable is like this:
export(int) var MOTION_SPEED setget setterfunc, getterfunc
and setterfunc and getterfunc are implemented.
func getterfunc():
return MOTION_SPEED
func setterfunc(newvalue):
MOTION_SPEED = newvalue
I really don’t understand either of these functions, or why calling them would be necessary. I dimly recognize that assuming two-way communication with a process called ‘export’ is maybe a little naive, but like I said, I think I got a bad video tutorial which implied a bare export var varname would be good enough to get an entry in the inspector that you could change to alter the number used in the script.
tl;dr export var is not working how I was lead to believe it would. Failing to hardcode a value returns Nil, so the inspector value isn’t getting sent over. Setter and getter don’t alter this. If a variable is both exported and hardcoded, e.g.,
export(int) var MOTION_SPEED = 10 setget setterfunc, getterfunc
the 10 value will control and no amount of screwing with the inspector entry will change things.
Am I just going crazy? Is this a Godot 2.0 vs. 3.0?
Here is the tutorial and location and origin of my ‘export creates i/o variable in inspector’ assumption: https://youtu.be/0UiAEdEAQ74?t=5m38s