Strings with If and Switch statements
by Katrina Rose · in Torque Game Engine · 08/04/2004 (11:37 am) · 5 replies
Hi,
I am on a team developing a 3D Shooter for the U.S. Army (No not Americas Army) with the Torque Engine. I have used the inventory system from Steven Beffy Moses, and I am trying to improve on some aspects of the system. For some reason none of my if statements or switch statements work with strings. I am a C#.NET programmer and C++ is somewhat understandable, so I don't see what I am doing wrong. Here is the code I am trying to use:
switch (%obj.getname())
{
case "m9Pickup" : playSlot1.setBitmap("game/client/ui/Slot1");
case "m16Pickup" : playSlot2.setBitmap("game/client/ui/Slot2");
}
*When the program is executed %obj.getname() is "m16Pickup", but the "m9Pickup" part is executed. I have tried the following statements, and get the same results.
if (%obj.getname() == "m9Pickup")
playSlot1.setBitmap("game/client/ui/Slot1");
if (%obj.getname() == "m16Pickup")
playSlot2.setBitmap("game/client/ui/Slot2");
* When the program is executed in the first "if" statement %obj.getname() is "m16Pickup" (clearly not equal), but playSlot1.setBitmap("game/client/ui/Slot1") is executed. This does not make any sense to me. Please will someone shed some light on this?
I am on a team developing a 3D Shooter for the U.S. Army (No not Americas Army) with the Torque Engine. I have used the inventory system from Steven Beffy Moses, and I am trying to improve on some aspects of the system. For some reason none of my if statements or switch statements work with strings. I am a C#.NET programmer and C++ is somewhat understandable, so I don't see what I am doing wrong. Here is the code I am trying to use:
switch (%obj.getname())
{
case "m9Pickup" : playSlot1.setBitmap("game/client/ui/Slot1");
case "m16Pickup" : playSlot2.setBitmap("game/client/ui/Slot2");
}
*When the program is executed %obj.getname() is "m16Pickup", but the "m9Pickup" part is executed. I have tried the following statements, and get the same results.
if (%obj.getname() == "m9Pickup")
playSlot1.setBitmap("game/client/ui/Slot1");
if (%obj.getname() == "m16Pickup")
playSlot2.setBitmap("game/client/ui/Slot2");
* When the program is executed in the first "if" statement %obj.getname() is "m16Pickup" (clearly not equal), but playSlot1.setBitmap("game/client/ui/Slot1") is executed. This does not make any sense to me. Please will someone shed some light on this?
About the author
#2
In Torque Script, string compares are $= not ==. Hope this helps! GL.
08/04/2004 (11:44 am)
To add to the previous poster:In Torque Script, string compares are $= not ==. Hope this helps! GL.
#3
So do you work for the Government Applications or Public Applications, or some other project group? The Government Applications divison just opened an office in Cary, NC which is not too far from me: Greensboro, NC
08/04/2004 (12:05 pm)
Roger that.So do you work for the Government Applications or Public Applications, or some other project group? The Government Applications divison just opened an office in Cary, NC which is not too far from me: Greensboro, NC
#4
08/04/2004 (12:43 pm)
Government Contractor. We are not part of the U.S. Army.
#5
08/04/2004 (12:44 pm)
Thanks for all your help. I got my code to work fine now. You guys are awsome.
Torque Owner Owen Ortmayer