Switch statement wonkiness
by Simon Love · in Torque Game Builder · 01/16/2007 (7:58 am) · 4 replies
Greetings to all,
Usually, when I run into a problem, I try to work it out with the C++ source or with TDN, the forums, etc. but, this one just has me completely stumped.
Here is my code, followed by a short description of the problem.
The variable %memetype has been defined and tested(echo(%memetype) before and after the switch return the correct value), it contains a numerical value between 0 and 2.
However, the Switch statement simply doesn't get executed, the default is not called, nothing happens.
If I put variables included in the parameters list (%srcobject for instance) in %memetype's place, the switch statement is called and behaves accordingly, but as soon as I try to execute the switch statement on a variable that has been declared within the OnCollision function, it's as if the switch statement isn't even there.
I have also tried switch$ (For strings) and it does the exact same thing.
I know I can easily bypass the problem with if statements, but still, I'd like to know why it behaves in such a way.
Any ideas? Am I missing something retardedly obvious or am I going insane?
Thanx in advance.
Simon Love
Broken Toy Software
Usually, when I run into a problem, I try to work it out with the C++ source or with TDN, the forums, etc. but, this one just has me completely stumped.
Here is my code, followed by a short description of the problem.
function MM_NPC::OnCollision(%srcObject, %dstObject, %srcRef, %dstRef, %time, %normal,%contacts, %points)
{
... //a few variable definitions here, nothing fancy...%bleh = 0; and so on.
switch (%memetype)
{
case 0:
if (%srcobject.canhear)
Treat_Meme_Infection(0);
case 1:
if (%srcobject.cansee)
Treat_Meme_Infection(1);
case 2:
if ((%srcobject.cansee)&&(%srcobject.canread))
Treat_Meme_Infection(2);
default:
echo("WHAT THE Food???");//Obviously it doesn't say Food in the code I have at home :)
}The variable %memetype has been defined and tested(echo(%memetype) before and after the switch return the correct value), it contains a numerical value between 0 and 2.
However, the Switch statement simply doesn't get executed, the default is not called, nothing happens.
If I put variables included in the parameters list (%srcobject for instance) in %memetype's place, the switch statement is called and behaves accordingly, but as soon as I try to execute the switch statement on a variable that has been declared within the OnCollision function, it's as if the switch statement isn't even there.
I have also tried switch$ (For strings) and it does the exact same thing.
I know I can easily bypass the problem with if statements, but still, I'd like to know why it behaves in such a way.
Any ideas? Am I missing something retardedly obvious or am I going insane?
Thanx in advance.
Simon Love
Broken Toy Software
About the author
I am here to help. I've worked at every imaginable position in game development, having entered the field originally as an audio guy.
#2
%memetype was defined by accessing another object's variable, but even if I define it like so
it does not process the switch.
P.S.:also tried %memetype = "1";, same thing :)
01/16/2007 (9:23 am)
I have tried switch$ and case "0" "1", etc...same results.%memetype was defined by accessing another object's variable, but even if I define it like so
%memetype = 1;
it does not process the switch.
P.S.:also tried %memetype = "1";, same thing :)
#3
But are you sure it is the switch breaking? and not the IFs actually as they would prevent anything from happening?
01/16/2007 (9:29 am)
If you use strings, you need to use the string switch functionality. (yupp, there is a different one for strings ^^)But are you sure it is the switch breaking? and not the IFs actually as they would prevent anything from happening?
#4
Can't believe I didn't think of that!!! I feel like a noob, now :)
For the record, I am aware that string switch functionality is done with Switch$ instead of regular old switch. :)
Allright, gotta get back to it, then! Gotta be a way to make these if's work.
Hoping this short thread will help others.
01/16/2007 (9:43 am)
Well, thank you Marc. I simply commented out the Ifs, and the switch goes through correctly.Can't believe I didn't think of that!!! I feel like a noob, now :)
For the record, I am aware that string switch functionality is done with Switch$ instead of regular old switch. :)
Allright, gotta get back to it, then! Gotta be a way to make these if's work.
Hoping this short thread will help others.
Associate Tom Eastman (Eastbeast314)
If that doesn't work, I guess I'd ask how you are defining %memetype.
Hope that's a start ;)