Page 1 of 1

My For loop

Posted: Thu Jan 22, 2004 1:35 pm
by digitac

Code: Select all

for ( local.n = 1;local.n =< $player.size;local.n++ )
{
$player[local.n] physics_off
wait 15
self say dfr_M1L1_101j
$player[local.n] physics_on
}
Can someone tell me what i'm doing wrong ?
this crashes my script

Greetz DigitaC

Re: My For loop

Posted: Thu Jan 22, 2004 1:42 pm
by Bjarne BZR
Arrays start at the index 0... and because of this you also need to change the comparison from '<=' to '<'... try this:

Code: Select all

for ( local.n = 0 ; local.n < $player.size ; local.n++ )
{
    $player[local.n] physics_off
    wait 15
    self say dfr_M1L1_101j
    $player[local.n] physics_on
}
BTW... what is it supposed to do?

Posted: Thu Jan 22, 2004 1:57 pm
by bdbodger
Well actually targetname arrays start indexing at 1 not 0 .

try useing <= instead of =<

also is this in a thread . It must be in a thread for self to mean anything and an entity must call the thread for self to have value

$ai1 thread mythread

mythread:

iprintln self.targetname

end

ai1 will print on screen

Posted: Thu Jan 22, 2004 7:25 pm
by Bjarne BZR
:oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops:
Sorry... C++ programmer made a boo boo, yes starts at 1, not 0... sorry :)

http://www.planetmedalofhonor.com/rjuka ... 0Files.txt

Posted: Mon Jan 26, 2004 1:04 am
by nuggets
a script will run line by line, and on a for loop it'll run the for loop for the 1st person, then the 2nd person, etc...

so... your script is running
$player[1] physics_off
wait 15
self say dfr_M1L1_101j
$player[1] physics_on
$player[2] physics_off
wait 15
self say dfr_M1L1_101j
$player[2] physics_on
but i'm guessing you want to do this all at once...

also your using self... surely from this i can guess that your using another for loop to accommodate all the other players,

you should use
$player[local.n] say dfr_M1L1_101j