If" function problem
by Christian · in Torque Game Engine · 02/21/2007 (2:38 pm) · 9 replies
This is a condensed version of a function to recognize the target to go to the correct quest. Every time no matter who the target, it always goes through all the "if" statements. I'm not sure why, since %peanuts always comes out correct. I'm guessing I missed something simple.
function whobeclicked(%target)
{
%peanuts = %target.getshapename();
echo(%peanuts);
if (%peanuts == GoodNCP01)
{
echo(%peanuts);
showqueststuff();
questname.text = "testa";
questtext.settext("test A works");
}
if (%peanuts == GoodNCP02)
{
echo(%peanuts);
showqueststuff();
questname.text = "testb";
questtext.settext("testbworks");
}
}
#2
02/21/2007 (3:05 pm)
That one gets me every time...
#3
02/21/2007 (3:06 pm)
Thank you for the fast answer. It works now. First time used a string.
#4
but in the following segment of code, it the text always stays the same. When the "TWOTWOTWOTWO" get's echo'd, it's like it completely ignores the questname.text = "Completed"; and questtext.settext("Congrats dude, you did it");
02/21/2007 (10:01 pm)
An addendum to question to this - questtext.settext("Congrats dude, you did it"); works in the console log.but in the following segment of code, it the text always stays the same. When the "TWOTWOTWOTWO" get's echo'd, it's like it completely ignores the questname.text = "Completed"; and questtext.settext("Congrats dude, you did it");
if (%peanuts $= GoodNCP01)
{
if ($questnumber1 == "2")
{
echo("TWOTWOTWOTWO");
questname.text = "Completed";
questtext.settext("Congrats dude, you did it");
}
else
if ($questnumber1 =="1")
{
echo("ONEONEONEONE");
questname.text = "In Progress";
questtext.settext("you are progressing through this long quest, a journey, a mission, a task, a job, a quagmire");
}
else
echo("ZEROZEROZEROZERO");
questname.text = "Trouble with #3";
questtext.settext("Kill GoodNCP03 2 times");
$questnumber =1;
}
#5
02/21/2007 (10:43 pm)
I think a switch statement would better suit this situation:if (%peanuts $= GoodNCP01)
{
switch ($questnumber1)
{
Case: 1
echo("ONEONEONEONE");
// Add rest of your code here
Case: 2
echo("TWOTWOTWOTWO");
// Add rest of your code here
default:
questname.text = "Trouble with #3";
questtext.settext("Kill GoodNCP03 2 times");
$questnumber =1;
}
}
#6
I put the ":" after 1/2 (So it's Case 1: instead of Case: 1). That didn't fix it though.
02/21/2007 (11:09 pm)
Hmmm, the switch statement gives me the following error:if (%peanuts $= GoodNCP01)
{
switch ($questnumber1)
{
Case: 1
## ## echo("ONEONEONEONE");
questname.text = "In Progress";I put the ":" after 1/2 (So it's Case 1: instead of Case: 1). That didn't fix it though.
#7
So i would guess you do need it as case #:
02/21/2007 (11:26 pm)
Here is an example from ::onEnterLiquidswitch(%type)
{
case 0: //Water
case 1: //Ocean Water
case 2: //River Water
case 3: //Stagnant Water
case 4: //Lava
%obj.setDamageDt(%this, $DamageLava, "Lava");
case 5: //Hot Lava
%obj.setDamageDt(%this, $DamageHotLava, "Lava");
case 6: //Crusty Lava
%obj.setDamageDt(%this, $DamageCrustyLava, "Lava");
case 7: //Quick Sand
}So i would guess you do need it as case #:
#8
Keep in mind the default case will be called for any value other than 1 & 2. You'll have to adjust the code to suit your needs, I was just trying to give you a neater solution.
02/22/2007 (12:48 am)
Sorry, my bad. Caylo is correct, I made a typo. It should look like:if (%peanuts $= GoodNCP01)
{
switch ($questnumber1)
{
case 1:
echo("ONEONEONEONE");
// Add rest of your code here
case 2:
echo("TWOTWOTWOTWO");
// Add rest of your code here
default:
questname.text = "Trouble with #3";
questtext.settext("Kill GoodNCP03 2 times");
$questnumber =1;
}
}Keep in mind the default case will be called for any value other than 1 & 2. You'll have to adjust the code to suit your needs, I was just trying to give you a neater solution.
#9
02/22/2007 (1:17 am)
Works now, ty!
Torque 3D Owner Pat Wilson