Possible switch/case issue
by Mark Roberts · in Torque Game Engine · 09/23/2004 (5:10 pm) · 4 replies
OK, first off I am likely dillusional here as I have been beating my head on this issue for two days now only to find I wasn't even looking in the right place. =) Anyhow, I have a simple routine which checks a couple dynamically set values from datablocks for players and bots. Essentially as part of the scripted datablock I declared a hasShield variable and set it to false. Then per bot or player I set that flag based on having the shield equiped. For bots I simply set this at the start via a select with which weapons I give them. Below is the code I had been using for this part.
I didn't notice anything unusual for a while, then while making some combat mechanics changes I noticed some of my bots were blocking with crossbows and swords (both should be using the default value of false for hasShield). After hours of pouring over my checks and combat code I remarked the single shield add here and found none of my bots had shields any longer. Looking up things and doing a grep on source files I found 30 or 40 script places where selects were used, most with select$ rather then using a numeric. But some of the numerics were different, they had a space between the select and the (%index). Some however did not and were like mine. Just to see I tested it with a space (no other changes) and it worked much to my suprise. So I went through and changed all my selects just in case (although other ones seemed to be working fine :baffle:).
I guess I am posting here to see if I am crazy from staring at this code for too many hours working on this problem? Or is this a feature i should have known before or somehow slipped through? Anyhow, I am happy it is working today, I will see if it stays working tomorrow but I thought I would drop this out here and see if others had seen this before or if I just had something else going funny that is sporatic and therefore I only think it is fixed. =)
Thanks for reading, and either way I know I will be putting that space in just to be sure from here on out. hehe
Mark
%index = mFloor(getRandom()*(3-0.0001));
if (%index > 2)
%index = 2;
switch(%index)
{
case 0:
%player.mountImage(CrossbowImage, 0, 0);
%player.dataBlock.attackRange = 15;
case 1:
%player.mountImage(SwordImage, 0, 0);
%player.dataBlock.canParry = true;
case 2:
%player.mountImage(AxeImage, 0, 0);
%player.dataBlock.canParry = true;
%player.dataBlock.hasShield = true;
default:
%player.mountImage(SwordImage, 0, 0);
%player.dataBlock.canParry = true;
}I didn't notice anything unusual for a while, then while making some combat mechanics changes I noticed some of my bots were blocking with crossbows and swords (both should be using the default value of false for hasShield). After hours of pouring over my checks and combat code I remarked the single shield add here and found none of my bots had shields any longer. Looking up things and doing a grep on source files I found 30 or 40 script places where selects were used, most with select$ rather then using a numeric. But some of the numerics were different, they had a space between the select and the (%index). Some however did not and were like mine. Just to see I tested it with a space (no other changes) and it worked much to my suprise. So I went through and changed all my selects just in case (although other ones seemed to be working fine :baffle:).
I guess I am posting here to see if I am crazy from staring at this code for too many hours working on this problem? Or is this a feature i should have known before or somehow slipped through? Anyhow, I am happy it is working today, I will see if it stays working tomorrow but I thought I would drop this out here and see if others had seen this before or if I just had something else going funny that is sporatic and therefore I only think it is fixed. =)
Thanks for reading, and either way I know I will be putting that space in just to be sure from here on out. hehe
Mark
#2
Glad I broek down and posted this just to be sure, at least one mistake was found even if it wasn't the one I was hunting for. =)
09/23/2004 (5:52 pm)
Thanks for the heads up there. I had been using chaging values for a while but my players use one datablock, my bots have 4 or 5 I was using so i never noticed the error on all being the same (cause my numbers usually were different due to my number of blocks in use). Saved me a headache down the road i am sure, I will work on another solution as you suggest maybe to clear this up. I hadn't planned to have to set every value for each spawn but I guess better to do a routine to init now and set it to defaults there then change them on the fly per player rather then datablock.Glad I broek down and posted this just to be sure, at least one mistake was found even if it wasn't the one I was hunting for. =)
#3
switch$(%blah)
(Unless the above was a simple typo)
As far as spaces behind the keyword or not, I use it both ways just fine.
09/24/2004 (6:01 pm)
For your switch statement you do need to have the dollar sign attached:switch$(%blah)
(Unless the above was a simple typo)
As far as spaces behind the keyword or not, I use it both ways just fine.
#4
09/24/2004 (6:42 pm)
Quote:For your switch statement you do need to have the dollar sign attached:Huh? Unless I'm completely mistaken, switch$() is for string variables and switch() for numeric variables, and %index looks to be a number in the example above.
switch$(%blah)
Torque Owner Stephen Clark
%player.canParry=true; (or whatever) Instead of
%player.datablock.canParry.
Beauty of typeless script!
-s
check these threads:
http://www.garagegames.com/mg/forums/result.thread.php?qt=12095
http://www.garagegames.com/mg/forums/result.thread.php?qt=21501
http://www.garagegames.com/mg/forums/result.thread.php?qt=17337