Game Development Community

Append trouble

by Jeff Trier · in Torque Game Engine · 05/25/2003 (2:27 pm) · 4 replies

I have a set of global variables that need to keep track of how many units are in each squad. To keep the code repitition down I am attempting to use append to string a global variable together for checking.

I can't seem to figure out why if (("$Squad" @ %SquadID @ "Count") < $SquadUnitMax){ is always true, even if %SquadID = 1 and $Squad1Count passes beyond $SquadUnitMax.

I have done echos to make sure everything is ok, and it seems to be... I am missing something.

if (("$Squad" @ %SquadID @ "Count") < $SquadUnitMax){ // if there is room in that Squad
			echo("Yay there's room");

			// -- Add Joining code here

			%AppendVar = "$Squad" @ %SquadID @ "Count";
			echo(%AppendVar);
			echo(%AppendVar @ "=" @ $Squad1Count);
			switch$(%AppendVar){
				case "$Squad1Count" :
					$Squad1Count += 1;
				case "$Squad2Count" :
					$Squad2Count += 1;
				case "$Squad3Count" :
					$Squad3Count += 1;
				case "$Squad4Count" :
					$Squad4Count += 1;
				case "$Squad5Count" :
					$Squad5Count += 1;
				case "$Squad6Count" :
					$Squad6Count += 1;
				case "$Squad7Count" :
					$Squad7Count += 1;
				case "$Squad8Count" :
					$Squad8Count += 1;
				case "$Squad9Count" :
					$Squad9Count += 1;
				case "$Squad10Count" :
					$Squad10Count += 1;
			}
		}
		else {
			echo("No Room in Squad");
		}


If anyone can jog my brain, that would be great.

Thanks,
-Jeff

About the author

Originally a Classical/Metal musician, I've always been attracted to anything involving computers, including: Networking, PC Building and Repair, software design and coding. I've been involved with game design and development for over 10 years.


#1
05/25/2003 (4:24 pm)
Duh... I changed to an array instead. Much easier, and its working now. Still not sure why the condition was always true though.

Oh well!


-Jeff
#2
05/25/2003 (5:00 pm)
Wouldn't it be better to have an array, $SquadCount[], instead of a big switch statement? Could solve a lot of problems (simple code == easy to debug code).
#3
05/25/2003 (5:03 pm)
Hehe, that's what I finally came to. :)

Thanks,
-Jeff
#4
05/27/2003 (9:16 am)
In case you were wondering, I believe that you needed to use:

if ((eval("$Squad" @ %SquadID @ "Count")) < $SquadUnitMax){

However, an array is definitely a better approach.