Game Development Community

Confused script no error

by Anthony Ratcliffe · in Torque Game Builder · 08/09/2008 (1:23 am) · 17 replies

function en::onLevelLoaded(%this)
{

$node= 1;

%this.setPositionTarget(35,-24, true, true);
%this.setLinearVelocityX(15);
echo ("called");
} 

function en::onPositionTarget(%this)
{

if ($node==1)
{
echo ("reached call 1"); 
%this.setPositionTarget(35,24, true, true);
%this.setLinearVelocityX(20);
$node++;
}

else if ($node==2)
{
echo ("reached 2"); 
%this.setPositionTarget(35,-24, true, true);
%this.setLinearVelocityX(-20);
$node--; //goes back to call 1 ?
}
}

i can get this to work eg it runs to the first point, but insted of stopping it just carrys on running? i had this problem before and i cant remeber hw it was fixed can anyone gimmie a hand? also i cant remeber if thats the right way to minus from a count?

#1
08/09/2008 (1:34 am)
Try using moveTo instead of setPositionTarget.
#2
08/09/2008 (1:48 am)
I wouldnt think it would matter if it worked before on a previous script, however i will try
#3
08/09/2008 (1:54 am)
No go syntax errors line 5, not very sure on how to use move to and the refrence isnt the best help either

function en::onLevelLoaded(%this)
{

$node= 0;
%this.moveTo("35 -24", 10, true, true, true, 0.01))"
//%this.setPositionTarget(35,-24, true, true);
//%this.setLinearVelocityX(15);
echo ("called");
$node++;
} 

function en::onPositionTarget(%this)
{

if ($node==1)
{
echo ("reached call 1"); 
%this.moveTo("35 24", 10, true, true, true, 0.00))"
//%this.setPositionTarget(35,24, true, true);
//%this.setLinearVelocityX(20);
//%this.setLinearVelocityY(0);
$node++;
}

else if ($node==2)
{
echo ("reached 2"); 
%this.setPositionTarget(35,-24, true, true);
%this.setLinearVelocityX(-20);
%this.setLinearVelocityY(0);
$node--; //goes back to call 1 ?
}
}
#4
08/09/2008 (2:07 am)
It was moving before but not stopping before t0 the next node
then i put moveto in and got the syntax

function en1::onlevelloaded(%this)
{
%this.setLinearVelocityX(20);
}
function en1::onWorldLimit(%this, %mode, %limit)
{

   switch$ (%limit)
   {

      case "right":
echo("oi");
         %this.setLinearVelocityX(-20);
         %this.setFlipX(false);

      case "left":
         %this.setLinearVelocityX(20);
         %this.setFlipX(true);
   }


}


i also tried this way to bounce them indefinetly just world limits also not working
#5
08/09/2008 (2:14 am)
You really don't see anything wrong with line 5? There's a close parenthesis and double-quote there for no reason, also one on your other moveTo call below. Not to mention no semicolon at the end of your line.
#6
08/09/2008 (2:16 am)
I was jsut copying the refrence book

"%obj.moveTo("30 20", 10, true, true, true, 0.01))"

how ever your suggestion also doesnt work
#7
08/09/2008 (2:22 am)
It also looks like you didn't switch the last call from setPositionTarget to moveTo. And what does "it isn't working" mean?
#8
08/09/2008 (2:23 am)
I was jsut copying the refrence book

"%obj.moveTo("30 20", 10, true, true, true, 0.01))"

how ever your suggestion also doesnt work
#9
08/09/2008 (2:39 am)
It isnt working means that its running along and not going to the next point
#10
08/09/2008 (2:55 am)
function en::onLevelLoaded(%this)
{
%call=1;
%this.moveTo("33 -24", 10, true, true, true, 0.00);
} 

function en::onPositionTarget(%this)
{
if (%call==1)
	{
	echo ("reached call 1"); 
	%this.moveTo("33 10, -10, true, true, true, 0.00");
	%call++;
	}

else if (%call==2)
{
echo ("reached 2"); 
%call--; //goes back to call 1 ?
%this.moveTo("33 -24", 10, true, true, true, 0.00);
}
}

cleaned up the code, however a strange thing now happens the object flys diagonally across the screen
?
#11
08/09/2008 (3:03 am)
function en::onLevelLoaded(%this)
{
%call=1;
%this.moveTo("33 -24", 10, true, true, true, 0.00);
} 

function en::onPositionTarget(%this)
{
if (%call==1)
	{
	echo ("reached call 1"); 
	%this.moveTo("33 10, -10, true, true, true, 0.00");
	%call++;
	}

else if (%call==2)
{
echo ("reached 2"); 
%call--; //goes back to call 1 ?
%this.moveTo("33 -24", 10, true, true, true, 0.00);
}
}

cleaned up the code, however a strange thing now happens the object flys diagonally across the screen
?
#12
08/09/2008 (3:04 am)
Don't pass a negative speed into moveTo under your (%call==1) block. It should always be positive.

You also still have typos.... one of your moveTo calls you have all the arguments inside quotes, so... there are all one big string? I really can't help you if you don't understand the basic syntax of TorqueScript.

I don't want to be mean, and maybe it isn't that you don't understand it, but in any case I can't be correcting your syntax errors on a line by line basis.
#13
08/09/2008 (3:13 am)
Changed to a positive number and out of ", codeweaver didnt pick up on it and i find the refrence unhelpful
if it is written in the file as "%obj.moveTo("30 20", 10, true, true, true, 0.01))" thats the example i took and changed it to accomedate my situation, however i have done as you have suggested changed both the number to + and removed the speech marks where there not needed and it still moves diagonally
#14
08/09/2008 (3:24 am)
function en::onLevelLoaded(%this)
{
   %call=1;
   %this.moveTo("33 -24", 10, true, true, true, 0.01);
} 

function en::onPositionTarget(%this)
{
   if (%call==1)
   {
      echo("reached call 1"); 
      %this.moveTo( "33 10", 10, true, true, true, 0.01 );
      %call++;
   }
   else if (%call==2)
   {
      echo("reached 2"); 
      %call--;
      %this.moveTo( "33 -24", 10, true, true, true, 0.01 );
   }
}
#15
08/09/2008 (3:06 pm)
I manged to get the first part working but its not moving onto call == 2

function en::onLevelLoaded(%this)
{

%call= 1;


 if (%call==1)
   {
	echo ("call1");
      %this.moveTo( "24 33", 10, true, true, true, 0.00 );
	echo ("done adding call");
      %call++;
	echo ("call executed");
   }
 else if (%call==2)
   {
	echo ("call2");
       
      %this.moveTo( "-24 33", 10, true, true, true, 0.00 );
	  %call--;
   }

}
#16
08/09/2008 (6:27 pm)
How would that ever reach call == 2? You have it all inside onLevelLoaded, which only happens once, when the level is loaded. Why would you take out the onPositionTarget callback? And how would you expect it to work without it?
#17
08/09/2008 (6:29 pm)
Ah i see i thought it would run step by step through the code