Game Development Community

Help with code

by Danny Mejia · in Torque Game Builder · 08/24/2006 (11:53 am) · 3 replies

Function gear::onMouseDown(%this, %modifier, %worldPosition, %mouseClicks)
{
/*

rotatoin code her

*/

if(p1.bucketType && p2.bucketType= 'red')
{
ball1.dismount();
ball1.mount(b2,0,0,0,false,false,false,true);
}
}

am try to move a ball from on pad to the other I have 20 pads on screen and need to check if the pad is of the same type. do the IF statment dose not work. What wrong with it?

#1
08/24/2006 (12:11 pm)
To compare strings, you would do something like p2.bucketType $= "red"
#2
08/24/2006 (2:35 pm)
Plus, your logic isn't correct as far as I can tell. You are doing a unary logic check to see if p1.bucketType is defined (>0), and then doing an assignment to p2.bucketType to a tagged string, not any comparisions at all.

Guessing at what you really want to do:

--p1.bucketType AND p2.bucketType must contain the string "red"

try:

if (  (p1.bucketType $= "red") &&
      (p2.bucketType $= "red") )
{
  ball1.dismount();
  ball1.mount(b2, 0, 0, 0, false, false, false, true);
}
#3
08/26/2006 (5:57 pm)
If you just want to compare if they are the same:

if { p1.buckType $= p2.buckType)
{
  // code here
}

Would work ...