Game Development Community

defaultParseArgs() global variable

by James Ghitelman · in Torque Developer Network · 04/28/2013 (2:03 pm) · 3 replies

I was going through the FPS tutorial when I noticed what I consider to be an odd programming choice. In core/parseArgs.cs, in the function defaultParseArgs(), why is the for loop defining "i" as a global variable? It's a waste of memory. Also, I don't know how scope works in torquescript, can I define a local variable "i" or do all my for loops now have to use "count" or some equally arcane variable? Can I safely edit it to local or is there some good reason that it's global? I'm just a bit mystified.

About the author

Recent Threads


#1
04/28/2013 (2:22 pm)
Spitting out my coffee
What the.....
Not only the $i but also these:
$arg = $Game::argv[$i];
$nextArg = $Game::argv[$i+1];
$hasNextArg = $Game::argc - $i > 1;
$logModeSpecified = false;
I'm sure there is some kind of reasonable... Reason for this..... I just don't see it lol, good catch tho!

However you can have a local variable with the same name without being afraid of breaking the engine, local and global variable names can overlap.
#2
04/28/2013 (2:32 pm)
Just want to elaborate for clarity:
$i = 3;
%i = 2;
echo($i); // outputs 3
echo(%i); // outputs 2
So you don't have to worry about local variable names.

I don't have any clue as to why they are global or whether you can change them to local, but try it and see if it works.
#3
04/28/2013 (6:45 pm)
As long as my local "i" isn't conflicting with the global "i" I don't really care. I would never name a global variable something non-descriptive like "i", so it's not a problem. I just thought it was weird. I'm not even entirely sure what parseArgs.cs does. Presumably parsing commandline arguments? When I understand what it does I'll try changing it and seeing if it stops doing it.