My For loop

Post your scripting questions / solutions here

Moderator: Moderators

Post Reply
digitac
Sergeant
Posts: 58
Joined: Mon Jul 28, 2003 3:30 pm

My For loop

Post 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
Bjarne BZR
Site Admin
Posts: 3298
Joined: Wed Feb 05, 2003 2:04 pm
Location: Sweden
Contact:

Re: My For loop

Post 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?
Admin .MAP Forums
Image
Head above heels.
User avatar
bdbodger
Moderator
Posts: 2596
Joined: Tue Feb 25, 2003 7:34 am
Location: canada
Contact:

Post 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
Bjarne BZR
Site Admin
Posts: 3298
Joined: Wed Feb 05, 2003 2:04 pm
Location: Sweden
Contact:

Post 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
Admin .MAP Forums
Image
Head above heels.
nuggets
General
Posts: 1006
Joined: Fri Feb 28, 2003 2:57 am
Location: U-england-K (england in the UK) :P
Contact:

Post 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
hope this helps, prob not cos it's all foreign 2 me :-/
Post Reply