Game Development Community

[SOLVED]Little help with operator...

by Vlad I · in Torque Game Builder · 05/08/2012 (5:43 am) · 5 replies

I'm just trying to force an object to be visible if I clicked two other objects.
In short if 2 objects deleted do this.
Here is what I have, but it doesn't wait for the second object to be clicked on. It sets visible straight foward on either 1 click:
function DummyTest01 :: onMouseDown (%this, %modifier, %worldPosition, %clicks)
{
   if(isObject(BoxA01) && isObject(BoxA02))
   { 
      BoxA03.setVisible(true); // or safedelte it

      BoxA01.safedelete();
      BoxA02.safedelete();
   }
   
     // return;
}

What operator should I use? Or should I set up a global smth. like
$totalNumberOfBoxes = 0;  
      
    // I'm assuming that each box has the class name "Boxes".  
    function Boxes::onAdd(%this)  
    {  
      %this.setUseMouseEvents( true ); // enabling mouse event  
      $totalNumberOfBoxes++;  
    }  
      
    function Boxes::onMouseDown( %this, %modifier, %worldPosition, %clicks)   
    {  
      %this.safeDelete();  
      $totalNumberOfBoxes--;  
      if( $totalNumberOfBoxes == 0 )  
        schedule( 0, 0, MakeBoxA03appear);  
    }   
      
    function MakeBoxA03appear()  
    {  
            BoxA03.setVisible(true); // or safedelte it
    }

#1
05/08/2012 (8:06 pm)
What code are you currently to "delete" BoxA01 and BoxA02 when they're clicked on? The problem might be that they're still objects even if you can't see them.

You should be able to, upload clicking either BoxA01 and BoxA02, call setVisible(false) on the object. Then when you want to see if BoxA03 should appear call:

if(!BoxA01.getVisible() &&!BoxA02.getVisible())  
   {   
      BoxA03.setVisible(true);
  
      ... whatever else you want to do ...
   }
#2
05/09/2012 (1:03 am)
I'm trying your method with out success , here is what I got:
function DummyTest01 :: onMouseDown (%this, %modifier, %worldPosition, %clicks)
{
   if(isObject(%this))
   { 
    %this.safedelete();
    schedule( 0, 0, MakeBoxA03appear);    
   }
   
     // return;
}
function MakeBoxA03appear()
{
if(!BoxA01.getVisible() &&!BoxA02.getVisible())    
   {     
      BoxA03.setVisible(true);  
    
      //... whatever else you want to do ...  
   } 
}
BoxA01 and BoxA02 are using class DummyTest01 .
#3
05/09/2012 (6:40 am)
Sorry Vlad, I misunderstood your original problem. I did however find something that might help out. Check out this forums post: www.garagegames.com/community/forums/viewthread/49887

Specifically this bit:
Quote:
BTW: ".safeDelete()" is only available for TGB objects e.g. ones with the "t2d" prefix. ".delete()" can be used by all objects including TGB ones. The advantage of ".safeDelete()" is that it can be used when an object does a script-callback as it defers the deletion until the start of the next frame.
So maybe safeDelete() isn't the right thing to be calling and you should try regular delete() instead? Worth a try at least.
#4
05/09/2012 (7:39 am)
Chris! ha-ha , you were right ! :)
It does work now , all I had to do with my current script is to replace %this.safedelete(); with just %this.delete();

Thanks for the useful info!
#5
05/09/2012 (7:49 am)
Glad I could help.

:)