Full Version: global variables
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
The suggestion is about adding the possibility of creating global variables, I think it would be good to create variables that manage the score, and another to save the value of objects created with tables and be able to access their values from other files in a more comfortable way.
Hello Marcus.

You are going to introduce global variables in a future update, while I am creating the pong game I am finding it quite difficult to work without global variables.

It may also be me who doesn't know how to work correctly without the globals, in any case I am going to publish little by little the code that I make for the pong game and could you give me some tips so that I can work as comfortably as possible without the globals? global variables.
I don't like the idea of sharing variables between files, so I have to think some more about it.

You could create "getter" and "setter" functions to read and modify these variables, maybe?

visible vMyString = "default"

function GetMyString()
   return vMyString

function SetMyString(value)
   vMyString = value

For a global array/table you probably just need a getter, since tables are of reference type.

Hope this helps!
Thanks Marcus, that code helps me solve the problem I had. Smile

When I finish Pong I will start another game and in that one I will use lists, we will see if this solution that you have shown me also works with lists.