Global or local variables?

I’ve read somewhere that we shouldn’t use global variables and global functions.Since my game use storyboard,and other local functions need to acces my variables,the variables needs to be global.All my variables are declared in the  scene:createScene function.

What should I do in this case?If I continue using global variables how will my game be affected?Is there anyway to change from global to local,without me having to move the variables in other functions.

Thanks!

I think the bad thing about the global variables it’s the Ram management , but it is only a warning  in your case i don’t saw any options , in my apps i use Global too because storyBoard/composer need access the variables  and i don’t have any problem with it .

But what if you have over 20 variables,including sprite animation?

using global variables or funcs will not break your game. You may not have realised but you’ve been throughout your game already, eg. display.newImage() or math.ceil() . Rob does a good tutorial on how to avoid using global vars here using LUA’s require function which is ironic because that is global aswell!

I think the bad thing about the global variables it’s the Ram management , but it is only a warning  in your case i don’t saw any options , in my apps i use Global too because storyBoard/composer need access the variables  and i don’t have any problem with it .

But what if you have over 20 variables,including sprite animation?

using global variables or funcs will not break your game. You may not have realised but you’ve been throughout your game already, eg. display.newImage() or math.ceil() . Rob does a good tutorial on how to avoid using global vars here using LUA’s require function which is ironic because that is global aswell!