Putting msg.post in a function causing target script's self reference to become nil (SOLVED)

I ran into an issue where using the same two lines of code results in different behavior. Image one shows the expected behavior and image two shows that the self reference (in another script) reads the url to be nil.

It is worth noting that there is no code that ever writes or overwrites that variable; we only ever read that value. I’m new to Lua, so there must be something that I am doing wrong - but I just can’t seem to spot it. If anyone has any insight, I would love to learn about it - thanks. :slightly_smiling_face:


It seems like in phasemanager.script you have function with name go_next_phase().
in both phasemanager.script and your script from the screenshot these functions are global and one overrides another.
To avoid it add local keyword:

local function go_next_phase(self)
...
end
3 Likes

Thanks for the quick solution! I didn’t realize there could be function name collisions like that even though they are in different scripts. I will be more careful when defining functions from now on.

1 Like

If your define functions as local (which is recommended) there will be no name collisions because the function names are local to the script file or scope.

Check this part of the manual for more info!