Game Development Community

Noob scripter help!

by jerryg7rk3w · in General Discussion · 10/30/2010 (7:15 am) · 3 replies

Ok im a noob scripter and am trying my best to wrap my head around torque script but still to no avail understand it, so here is a piece of script that im stuck on, could someone point me in the right direction please.

function enemyship::bullets(%this)
{
if ($F=true)
{
for(%i=0;%i<3;%i++)
{
schedule(1000);
{
%this.firemissile();
}
}
}else
{
$F=false;
}
}

What im trying to do is have the if $f is true then start the for loop and then have a 1 sec delay, then call the firemissile function else $f=false.
So if it would work, it should have the 1 sec delay then have the function firemissile called, then a 1 sec delay and again firemissile called, 1 sec delay firemissile, it should happen 3 times because of the loop and then set the $F to false.
well i cant wait to fully understand this scripting language and would greatly appreciate any help thanks.

#1
10/30/2010 (10:05 am)
It won't work like that, you're using schedule all wrong, and the condition needs a conditional == or !=. Also setting $F to false when it is false tells me you wanted it to be false after the shots were fired. From how you written the original code, I think you wanted the shots to have a delay between each other.

Try this (not tested):

function enemyship::bullets(%this)
{
   if ($F!=true)
      return;

   for(%i=0;%i<3;%i++)
      %this.schedule(%i*1000, "firemissile");

   $F=false;
}
#2
10/30/2010 (4:37 pm)
Thanks a lot this part of your code is exactly what i needed to make it work "%this.schedule(%i*1000, "firemissile");" i appreciate the patients and help this community gives, looking at the code above that i wrote just shows how lost i am and that's after following all the documentation tutorials and then some on the Dev network.
Thanks again :)
#3
11/02/2010 (1:16 pm)
Also, the proper code would be
if ($F == true)
using $F = true will attempt to assign the variable $F to true. Using == compares values. To make it even simpler, you can use just
if ($F)
{
   //do stuff
}