Home   Help Search Login Register  

Author Topic: Loop doesn't work?  (Read 1258 times)

0 Members and 1 Guest are viewing this topic.

Offline OFPfreak

  • Members
  • *
  • Who is da operation flashpoint freak now, freak?!
    • OFP NFS mod
Loop doesn't work?
« on: 26 Jun 2005, 01:57:19 »
Once again this stupid nitro script again ;D!
I tried using loops, but they don't work! I want my nitro to end after 3 seconds! Here's what I got:

Code: [Select]
#accel
_inc = 1
_amountleft = 0
car1 setvelocity [(velocity car1 select 0) + _inc*sin getdir car1, (velocity car1 select 1) + _inc*cos getdir car1, velocity car1 select 2]
~0.25
_amountleft=_amountleft+1
? _amountleft > 20 : goto "exit"
? speed car1 < 300 && alive car1 : goto "accel"

car1 removeaction "nitrox1"

#exit

exit

Since that didn't work, I used the hard way:

Code: [Select]
_inc = 1
_amountleft = 0
car1 setvelocity [(velocity car1 select 0) + _inc*sin getdir car1, (velocity car1 select 1) + _inc*cos getdir car1, velocity car1 select 2]
~0.25
_inc = 1
_amountleft = 0
car1 setvelocity [(velocity car1 select 0) + _inc*sin getdir car1, (velocity car1 select 1) + _inc*cos getdir car1, velocity car1 select 2]
~0.25
_inc = 1
_amountleft = 0
car1 setvelocity [(velocity car1 select 0) + _inc*sin getdir car1, (velocity car1 select 1) + _inc*cos getdir car1, velocity car1 select 2]
~0.25
_inc = 1
_amountleft = 0
car1 setvelocity [(velocity car1 select 0) + _inc*sin getdir car1, (velocity car1 select 1) + _inc*cos getdir car1, velocity car1 select 2]
~0.25
_inc = 1
_amountleft = 0
car1 setvelocity [(velocity car1 select 0) + _inc*sin getdir car1, (velocity car1 select 1) + _inc*cos getdir car1, velocity car1 select 2]
~0.25
_inc = 1
_amountleft = 0
car1 setvelocity [(velocity car1 select 0) + _inc*sin getdir car1, (velocity car1 select 1) + _inc*cos getdir car1, velocity car1 select 2]
~0.25
_inc = 1
_amountleft = 0
car1 setvelocity [(velocity car1 select 0) + _inc*sin getdir car1, (velocity car1 select 1) + _inc*cos getdir car1, velocity car1 select 2]
~0.25
_inc = 1
_amountleft = 0
car1 setvelocity [(velocity car1 select 0) + _inc*sin getdir car1, (velocity car1 select 1) + _inc*cos getdir car1, velocity car1 select 2]
~0.25
_inc = 1
_amountleft = 0
car1 setvelocity [(velocity car1 select 0) + _inc*sin getdir car1, (velocity car1 select 1) + _inc*cos getdir car1, velocity car1 select 2]
~0.25
_inc = 1
_amountleft = 0
car1 setvelocity [(velocity car1 select 0) + _inc*sin getdir car1, (velocity car1 select 1) + _inc*cos getdir car1, velocity car1 select 2]
~0.25
_inc = 1
_amountleft = 0
car1 setvelocity [(velocity car1 select 0) + _inc*sin getdir car1, (velocity car1 select 1) + _inc*cos getdir car1, velocity car1 select 2]
~0.25
_inc = 1
_amountleft = 0
car1 setvelocity [(velocity car1 select 0) + _inc*sin getdir car1, (velocity car1 select 1) + _inc*cos getdir car1, velocity car1 select 2]
~0.25

car1 removeaction nitrox2
nitrox1=car1 addaction ["use nitro","1xnitro.sqs"]

exit
ofp nfs REBORN! All new nitro, neon, customized cars, off-road, on-road, rally, bikes, racer models and more!
ofp nfs's homepage

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:Loop doesn't work?
« Reply #1 on: 26 Jun 2005, 08:04:58 »
you set the initial values of the variables within the loop. each time it repeats, the values reset themselves.  ::)

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:Loop doesn't work?
« Reply #2 on: 26 Jun 2005, 08:06:03 »
Well, you set the variable _amountleft to 0 inside the loop, which means it will never go higher than 1...
The loop first sets the _amountleft to 0, then later adds 1 in it and again when the loop restarts it sets the _amountleft to 0, and so on and so on...
This might not be the whole problem but sticks out first...

I would od the script like this:
Code: [Select]
_inc = 1
#accel
car1 setvelocity [(velocity car1 select 0) + _inc*sin getdir car1, (velocity car1 select 1) + _inc*cos getdir car1, velocity car1 select 2]
~0.25
? _time < 3 && alive car1 : goto "accel"

car1 removeaction "nitrox1"

_time is reserved OFP variable that returns the time since the script has started running, in seconds...
So with that it's easy to check if the scripts has run 3 secs...
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline OFPfreak

  • Members
  • *
  • Who is da operation flashpoint freak now, freak?!
    • OFP NFS mod
Re:Loop doesn't work?
« Reply #3 on: 26 Jun 2005, 08:49:28 »
lol stupid mistake of me.
ok thanks i'll use that stuff!
ofp nfs REBORN! All new nitro, neon, customized cars, off-road, on-road, rally, bikes, racer models and more!
ofp nfs's homepage