Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Ethan D on Sun 12/04/2009 17:40:54

Title: Is there a limit on global variables?
Post by: Ethan D on Sun 12/04/2009 17:40:54
I just want to know if having a lot of global variables could become a problem and if so how many would be a problem?
Title: Re: Is there a limit on global variables?
Post by: RickJ on Sun 12/04/2009 18:11:00
Variables declared in the script are only limited by system resources.   Variables declared in the global script are made global using the export and import keywords

There is an editor pane that allows one to do the same thing that can be done in the script.   I declare my global variables in the global script so I don't know if this feature has an artificial limit or not.   
Title: Re: Is there a limit on global variables?
Post by: Trent R on Sun 12/04/2009 18:12:22
No. A variable takes up so little space, and today's computers have so much space...

Someone will probably come by and tell you how many bytes each one is.

[Edit]: While Rick was posting... :P

~Trent
Title: Re: Is there a limit on global variables?
Post by: Ethan D on Sun 12/04/2009 18:16:58
Alright thanks for the help.
Title: Re: Is there a limit on global variables?
Post by: monkey0506 on Sun 12/04/2009 18:34:54
Quote from: Trent R on Sun 12/04/2009 18:12:22Someone will probably come by and tell you how many bytes each one is.

char: 1 byte
short: 2 bytes
int: 4 bytes
String: 4 bytes + 1 byte per character in string
float: 4 bytes
bool: 4 bytes*
Any pointer: 4 bytes
Any enumerated type: 4 bytes*

So basically, if you have 512 MB of RAM then your computer wouldn't be able to handle more than 536870912 combined int, String, and float variables**. Of course to define that in the script, even if you were defining 1000 variables per line would still result in 536870 lines of script...so I think you would have fair warning that you were doing something foolish. Even as an array with 1000000 elements you would still have to define 536 of them.

So essentially your answer then becomes no. I can't say for sure if the Global Variables pane in the editor has a built-in limit, but even if it does you can always define them in the script.

*This is not actually documented anywhere. I'm basing this off my experience which shows that enums are stored as integer values.
**This is of course ignoring the fact that your system will require the use of at least some of your RAM.
Title: Re: Is there a limit on global variables?
Post by: Trent R on Sun 12/04/2009 18:51:47
Touche.
Title: Re: Is there a limit on global variables?
Post by: Trent R on Fri 24/04/2009 17:15:47
Sorry to raise an old post, but CJ PMed this to Miori who then posted it in another topic.

Quote from: CJ in PM on Fri 24/04/2009 13:44:53
GlobalInts and GlobalStrings are obsolete, and you should not be using them in new scripts. Use the Global Variables pane instead to create global variables -- this does not have a limit to how many you can create.


~Trent
Title: Re: Is there a limit on global variables?
Post by: Ethan D on Fri 24/04/2009 21:32:19
Thanks