Home   Help Search Login Register  

Author Topic: loops  (Read 673 times)

0 Members and 1 Guest are viewing this topic.

Offline Hauk

  • Members
  • *
  • I sail under the Jolly Roger!! Pirates are kings!!
loops
« on: 17 Apr 2004, 21:27:06 »
I have a problem with loops, and if it doesn't work my mission might as well be thrown in the bin.
The problem is this. He goes to the first two markers fine but when it reads the loop it gets all laggy and he doesn't execute the loop. I posted the entire script so you could see what I'm rambling on about but also to get the entire picture:

_chopper = _this select 0
_paradropalpha = _this select 1
_marker2 = _this select 2
_player = _this select 3

@(units player in chopper)

chopper move getmarkerpos paradropalpha;

chopper move getmarkerpos marker2;

_marker3 = _this select 4
_marker4 = _this select 5

#loop

chopper move getmarkerpos marker3;

chopper move getmarkerpos marker4;

chopper move getmarkerpos paradropalpha;

chopper move getmarkerpos marker2;

goto "loop"

exit

Please help me cos I don't wanna have to scrap my mission.

Thnx

Hauk



Offline Hauk

  • Members
  • *
  • I sail under the Jolly Roger!! Pirates are kings!!
Re:loops
« Reply #1 on: 17 Apr 2004, 21:30:19 »
Sorry I posted the old script.
here's the one I meant to post:

 _chopper = _this select 0
_paradropalpha = 1
_marker2 = 2
_player = 3
_marker3 = 4
_marker4 = 5


@(player in chopper)

chopper move getmarkerpos "paradropalpha";

chopper move getmarkerpos "marker2";


#loop

chopper move getmarkerpos "marker3";

chopper move getmarkerpos "marker4";

chopper move getmarkerpos "paradropalpha";

chopper move getmarkerpos "marker2";

goto "loop"

exit

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:loops
« Reply #2 on: 17 Apr 2004, 21:35:58 »
Use delays in the loop, between all the move orders...
Now your loop runs as fas as your CPU possibly can run it....

Use

~seconds

Or

@unitReady choppername

between the move orders...
« Last Edit: 17 Apr 2004, 21:41:06 by HateR_Kint »
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

csde-PiLLe

  • Guest
Re:loops
« Reply #3 on: 17 Apr 2004, 21:45:36 »
First:

Why do you have variables named after the Waypoints?

OK, you want to be able to do is for every chopper, so you get the vehicle from the array given by ofp to your script.

The variables you create below (the ones with the underscore, "_") are simply integers, which means they contain a single number.

Then you have a "conditional wait", meaning the script will pause until a certain condition is met, in this case, the player being in the chopper.

Now you want to order the chopper to fly to two positions (set by a marker) and then do something?

At this point, note that "move" creates an actual waypoint, meaning the waypoint is added to the groups list of waypoints and made the active waypoint.

Now what your script does is, it creates waypoints and activates them. First the two waypoints outside the loop, then an infinite number of waypoints inside the loop.

BUT you are not waiting for the chopper to reach a waypoint. How could your script know it should wait until the chopper has reached a waypoint? There is an infinite numer of waypoints being created, as fast as your computer can do it.

What you should do is insert an additional "conditional wait" below each "chopper move markerpos ..." part, telling the script to wait until the unit has completed its previous assignment (e.g. reached the waypoint).

For that, you need to add "unitready", which returns the status of the unit (true for "unit is ready" and false for "unit is not ready"). As its a conditional wait, you have to place the "@" character in front of it.

@unitready chopper
which reads: "As soon as unitready is true for the unit _chopper"...

Cheers
PiLLe

Offline Hauk

  • Members
  • *
  • I sail under the Jolly Roger!! Pirates are kings!!
Re:loops
« Reply #4 on: 17 Apr 2004, 23:34:28 »
hey, csde-PILLe

I managed to get it to work.
You've saved my mission. (points to the sky in super-hero fashion)

All I had to do was put that "unitready" condition after the getmarkerpos command and it worked!
Now my chopper will be on sentry duty until he runs out of fuel.

Thnx,

Hauk

Offline Raptorsaurus

  • Editors Depot Staff
  • *****
Re:loops
« Reply #5 on: 18 Apr 2004, 03:10:30 »
I see another problem.  Your loop is endless.  You need to have somthing that will make the loop exit or else the script will not end.  Then if you have many units using the script you will have a bunch of unending scripts bogging down your CPU.  Put a line like this:

?(!alive _chopper) : exit

this will at least make it end when the chopper dies.  You should also make it end when all the loons are out of the chopper.

Offline Hauk

  • Members
  • *
  • I sail under the Jolly Roger!! Pirates are kings!!
Re:loops
« Reply #6 on: 18 Apr 2004, 14:02:14 »
In the mission I'm working on, the chopper just goes into sentry and I haven't configured the mission so that the chopper would die, he just circles the area of battle until I radio him for an airlift.
Any tips for breaking the script when I radio him for the airlift?
I'll try that ?(!alive_chopper) : exit in my test mission.

Thnx for the tip,

Hauk

csde-PiLLe

  • Guest
Re:loops
« Reply #7 on: 18 Apr 2004, 17:24:22 »
Sure. Have, after each move command (before the conditional checks) a line

?playerhasrequestedairlift:exit
(exits the scripts)
or
?playerhasrequestedairlift:goto "anotherpartofthescript"


Then, in your radio trigger, in the on activation field, put

playerhasrequestedairlift=true;

One weak point in my solution, though: the conditional waits pause the script, as I mentioned before. So the chopper will always continue to that waypoint he is currently moving to and break away afterwards.

as unitready is a boolean, you might "work around" it by not using @unitready.

something like:

#wp1
?playerairlift:exit;
?unitready chopper:goto wp2
~5
goto wp1

#wp2
?playerairlift:exit;
?unitready chopper:goto wp3
~5
goto wp2

---

and so on. Using this approach, the delay before the script is exited (respectively, if you replace exit with another goto, before the "get player out" part of the script is run) there will be a maximum delay of 5 seconds.

One hint: In scripts, do NEVER place a ; behind any wait command (like the  ~5 above).

Cheers
PiLLe

csde-PiLLe

  • Guest
Re:loops
« Reply #8 on: 18 Apr 2004, 17:26:32 »
forgot the easiest approach:

simply use

@(unitready chopper || playerhasrequestedairlift)

instead of

@unitready chopper

This will end the conditional wait as soon as either the unit is ready OR the player requests the airlift.

Stupid me :)

Offline Hauk

  • Members
  • *
  • I sail under the Jolly Roger!! Pirates are kings!!
Re:loops
« Reply #9 on: 18 Apr 2004, 18:47:39 »
Hey csde-Pille

I'll try that out. Having trouble getting my head around conditions :'(
I'm startin' to sort  it out

Thnx,

Hauk

Offline Hauk

  • Members
  • *
  • I sail under the Jolly Roger!! Pirates are kings!!
Re:loops
« Reply #10 on: 18 Apr 2004, 22:55:59 »
I managed to get the airlift script to co-operate with the sentry/paradrop script, but with one problem.

The chopper goes to the first marker:paradropalpha and stays there until you call in the airlift.
I've put @(unitready chopper || playerhasrequestedairlift) after every move command and have put in the trigger for the radio:
"playerhasrequestedairlift=true;" but with that problem.
Everything else works but for that tiny minor detail.

Thnx

Hauk

csde-PiLLe

  • Guest
Re:loops
« Reply #11 on: 19 Apr 2004, 00:54:20 »
well then, use the first option I mentioned ;)

I just read what I told you and its pretty stupid. You will need some "exit" in the script, as Raptosaurus mentioned.

What I did was simply adding a second condition to the conditional wait, which would - if you did exactly what I told you - cause the same problem you originally described ;)

Sorry :)

PiLLe

Offline Hauk

  • Members
  • *
  • I sail under the Jolly Roger!! Pirates are kings!!
Re:loops
« Reply #12 on: 19 Apr 2004, 22:06:08 »
Yeah I had that problem. I'm trying the first option at the moment.
Everthing should work out fine. I'll IM you if I have any more problems.

Thnx,

Hauk