NaaLaa
global variables - Printable Version

+- NaaLaa (https://www.naalaa.com/forum)
+-- Forum: NaaLaa (https://www.naalaa.com/forum/forum-1.html)
+--- Forum: Suggestions (https://www.naalaa.com/forum/forum-7.html)
+--- Thread: global variables (/thread-4.html)



global variables - aliensoldier - 11-18-2023

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.


RE: global variables - aliensoldier - 01-24-2024

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.


RE: global variables - Marcus - 01-24-2024

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?

Code:
visible vMyString = "default"

function GetMyString()
   return vMyString
endfunch

function SetMyString(value)
   vMyString = value
endfunc

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

Hope this helps!


RE: global variables - aliensoldier - 01-25-2024

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.