I clearly state
obj = true
then in another scene after using director, print obj, and it is nil. Does this switch mess it up? also, i do not declare the variable until i create it. [import]uid: 59735 topic_id: 17577 reply_id: 317577[/import]
I clearly state
obj = true
then in another scene after using director, print obj, and it is nil. Does this switch mess it up? also, i do not declare the variable until i create it. [import]uid: 59735 topic_id: 17577 reply_id: 317577[/import]
Hey, BoltVisual, is obj a global variable or a local variable? If it’s a local variable, when the scene changes, it will be removed from memory (and therefore, it would be nil in the new scene unless it is stated again before you call print obj.)
If obj is a global variable, so long as obj = true is stated before the new scene is loaded, it should return true.
Naomi [import]uid: 67217 topic_id: 17577 reply_id: 66849[/import]
The variable is global! I have it printing before a scene change then right at the load of the next and it resets to nil! [import]uid: 59735 topic_id: 17577 reply_id: 66857[/import]
Okay, i figured that whatever i set obj1 equal to in main.lua, it automatically will become this upon a scene transition. Still no fix. Also, should i be using this _G thing somewhere? [import]uid: 59735 topic_id: 17577 reply_id: 66880[/import]
Hey Bolt,
If your variable is like this;
[lua]variable = 1[/lua]
Then do it like this instead;
[lua]_G.variable = 1
print (_G.variable)[/lua]
I have found that with director you often have to use _G. to have a global work as intended.
Peach [import]uid: 52491 topic_id: 17577 reply_id: 66882[/import]
Thanks so so much!!! You are my hero! Ive been working on this for hours!!! Thank you! [import]uid: 59735 topic_id: 17577 reply_id: 66887[/import]
Hey, Peach, that’s good to know. I use director, but I don’t use _G. So far, I have not had any issues with any of my global variables, but if/when I do, now I know what to do. Thanks!
Naomi [import]uid: 67217 topic_id: 17577 reply_id: 66914[/import]
No problem at all Bolt, this was something I also had to contend with in the past
Naomi, I believe that perhaps the most recent versions of director do not require this, however some people prefer old versions for various reasons - I think 1.3 was the last that required the use of _G. - but don’t quote me on that, I’m a little foggy
Peach [import]uid: 52491 topic_id: 17577 reply_id: 66944[/import]