Home   Help Search Login Register  

Author Topic: Can't do for/while loops - can you help?  (Read 2295 times)

0 Members and 1 Guest are viewing this topic.

Corben Dallas

  • Guest
Can't do for/while loops - can you help?
« on: 13 Jun 2005, 11:04:13 »
Hi again. After the great help I got in getting a couple of nasties to hunt me down (works fine now), I'm stuck on something related.

The script I'm now using for the hunt is this:

  _huntSquad = group _this select 0
  #loop
  [_huntSquad,0] setwppos getpos player
  [_huntSquad,1] setwppos getpos player
  [_huntSquad,2] setwppos getpos player
  [_huntSquad,3] setwppos getpos player
  [_huntSquad,4] setwppos getpos player
  [_huntSquad,5] setwppos getpos player
  [_huntSquad,6] setwppos getpos player
  [_huntSquad,7] setwppos getpos player
  ~20
  ?(alive player):goto "loop"
  exit

Basically, I have waypoints 0 to 7 preset for the group, I kill one, and the other two then come after me.

What I want to do is use the script for any group, and set any number of waypoints they may have to point to me and update regularly as above. I think I need a While loop to set all their waypoints, no matter how many they have? Perhaps something like:

  _huntSquad = group _this select 0
  #loop

  _n = 0
  while [_huntSquad,n] not null {
  [_huntSquad,n] setwppos getpos player;
  n=n+1;
  }

  ~20
  ?(alive player):goto "loop"
  exit

I can't get it to work - help greatly appreciated.

Edit:

bedges gave me code something like this, which works with the final waypoints in a Cycle:

  #loop
  [natashas_group, 8] setwppos getpos player
  [natashas_group, 9] setwppos getpos player
  ~10
  ?(Alive player):goto "loop"
  exit

Should I perhaps use the final wo waypoints idea, and then somehow find their number in the group list? If so, how would I find the number of the last waypoint for any group?

Boggled brain, again  :-\

'nother edit:

Should I test if the group is dead at the start of the script? I tried the following, but it gives an error:

if (_squada == GrpNull){ exit };
« Last Edit: 13 Jun 2005, 11:46:06 by Corben Dallas »

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:Can't do for/while loops - can you help?
« Reply #1 on: 13 Jun 2005, 11:46:17 »
the while/do loop may not be working because you have the commands split over a couple of lines, which i believe can only be done in functions. if you write it like this -

Code: [Select]
while "[_huntSquad,n] not null " do { [_huntSquad,n] setwppos getpos player;n=n+1;}

you also forgot the 'do' part ;) and the inverted commas... in fact, always check the comref before trying out your syntax.

that may work. not quite sure - it may do if 'null' is what flashpoint returns when there's no waypoint at that reference.

another way to do it would be to have a standard number of waypoints for all groups, and make the last three a 'cycle', 'seek and destroy' and 'cycle'. that way you'll always know which waypoint reference points to the last two.

alternatively, you could pass the waypoint numbers to the script, by using

Code: [Select]
[group_name, waypoint_ref1, waypoint_ref2] exec "hunters.sqs"
and then in the script use

Code: [Select]
_group = _this select 0
_first_wp = _this select 1
_second_wp = _this select 2

not sure why you want to move all the waypoints to the player's position. simply moving the seek and destroy waypoint there, along with its cycle should work, and so long as you have the switch trigger sync'd to the previous patrol cycle so that the loons break out of their patrol loop, they'll always come a'hunting.

EDIT - not sure which programming language you're used to, but again, check the comref for syntax...

Quote
if (_squada == GrpNull){ exit };

where's the 'then'?
« Last Edit: 13 Jun 2005, 11:48:18 by bedges »

Corben Dallas

  • Guest
Re:Can't do for/while loops - can you help?
« Reply #2 on: 13 Jun 2005, 11:52:44 »
No then? I looked at the ComRef at http://www.ofpec.com/editors/comref.php?letter=I and it doesn't have then after the if. ???

Thanks for the ideas - I'll try them now. I'm not sure which waypoint to link (group?) the trigger to - should it be the last one before the seek-and-destroy, or the first of those? Trying all sorts but they just carry on following the previous waypoints but in combat mode.

Edit:

  ? isNull _squada: exit;

doesn't error, but will that exit ok if the group is null? (ComRef pages open all over the place and reading like crazy)
« Last Edit: 13 Jun 2005, 11:59:54 by Corben Dallas »

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:Can't do for/while loops - can you help?
« Reply #3 on: 13 Jun 2005, 11:57:16 »
if condition

Operand types:
condition: Boolean
Type of returned value:
If Type
Description:
First part of if command.

Example:
if (a>b) then {a=b} ;)

the trigger should be of type 'switch', the condition should be 'not (alive general)' and the trigger should be synchronised (not grouped) to the waypoint before the 'seek and destroy' waypoint. this means that if, for example, you have your loons on a patrol route, with move waypoints and a cycle waypoint to keep them at it, when the trigger activates, they will 'switch' to the next waypoint, which will be the 'seek and destroy'.

edit - take another look at the missionette i sent - it's all in there.
« Last Edit: 13 Jun 2005, 11:58:12 by bedges »

Corben Dallas

  • Guest
Re:Can't do for/while loops - can you help?
« Reply #4 on: 13 Jun 2005, 12:01:07 »
Cheers - will try all of that. It's a bit of a slog learning all this stuff, but fun too :)

Got this code now:

  _group = _this select 0
  _wp1 = _this select 1
  _wp2 = _this select 2

  ? isNull _group: exit;

  #loop
  [_group,_wp1] setwppos getpos player
  [_group,_wp2] setwppos getpos player
  ~20
  ?(alive player):goto "loop"
  exit

and am calling it from the trigger with:

  [TheMajor, 8, 9] exec "huntme.sqs"

but it's not working now. They run to the other waypoints in combat mode. I have synchronised the trigger with the first seek-and-destroy waypoint, which has another cycle waypoint after it (and they're both further away from the last initial wp and its cycle).  >:(
« Last Edit: 13 Jun 2005, 12:24:55 by Corben Dallas »

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:Can't do for/while loops - can you help?
« Reply #5 on: 13 Jun 2005, 12:36:44 »
Quote
the trigger should be synchronised (not grouped) to the waypoint before the 'seek and destroy' waypoint...

 ::)

Corben Dallas

  • Guest
Re:Can't do for/while loops - can you help?
« Reply #6 on: 13 Jun 2005, 12:49:50 »
Yep, done that (it's the last cycle wp in the initial wp set). Everything else in the trigger is as it was, but it doesn't seem to work. I'll try putting hints in and seeing if it's actually executing the script.

Edit: Yep, script's executing, but they're off to other waypoints! I'll check the syntax and make sure it's setting the right stuff.

Many thanks again.
« Last Edit: 13 Jun 2005, 12:53:24 by Corben Dallas »

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:Can't do for/while loops - can you help?
« Reply #7 on: 13 Jun 2005, 13:02:31 »
the only other thing it might be is the waypoint references. i think i may have made a bubu in a previous post saying that the first group waypoint is reference 0. it may be 1, i can't recall - i shall investigate...

edit - yep, sorry, first waypoint is 1, second 2 and so on...  :-\
« Last Edit: 13 Jun 2005, 13:05:34 by bedges »

Corben Dallas

  • Guest
Re:Can't do for/while loops - can you help?
« Reply #8 on: 13 Jun 2005, 13:14:55 »
The first wp shows as 0: in the wp list, and my last cycle wp in the initial set ends at 7:
The seek-and-destroy is therefor 8:, and the cycle for that is 9:

Do you mean that I should now pass 9 & 10 to the script, instead of 8 & 9 as shown in the wp list?

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:Can't do for/while loops - can you help?
« Reply #9 on: 13 Jun 2005, 13:18:58 »
yep - the waypoint list in the editor is 'wrong', at least as far as getting the waypoints by script is concerned ;)

Corben Dallas

  • Guest
Re:Can't do for/while loops - can you help?
« Reply #10 on: 13 Jun 2005, 13:31:17 »
Ah - thanks for that bedges.

It's still not working, so I must have something set wrong. I'll plod on trying to debug it, as I want to be able to tell any units to hunt me and pass their last two wps to the script. Seems daft having to give every unit the same number of wps just to set fixed numbers in the script!

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:Can't do for/while loops - can you help?
« Reply #11 on: 13 Jun 2005, 13:36:17 »
by all means keep at it - best way of learning in my opinion - but if you want a hand, zip the mission folder and attach it to the next post, and i'll take a look.

it is always best to try and keep your scripts flexible like this, as you never know when you'll need a similar script in another mission - you're learning fast ;)

Corben Dallas

  • Guest
Re:Can't do for/while loops - can you help?
« Reply #12 on: 13 Jun 2005, 14:55:22 »
Thanks bedges.

Here's the mission and a few small addons.  It's not very polished yet and has no intro, etc., but for a bug find it won't matter.  You might like to have a little play anyway, and imagine it with good atmospheric music, nice intro and cutscenes, etc.  ;)

Edit:

The end triggers are just lumped to the right of the player at the moment, but will be added to and moved to an escape vehicle, etc., when it's ready for beta.
« Last Edit: 13 Jun 2005, 15:04:59 by Corben Dallas »

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:Can't do for/while loops - can you help?
« Reply #13 on: 13 Jun 2005, 15:29:44 »
what isn't working about it? i shoot any of the three 'guards' and the script fires correctly...

Corben Dallas

  • Guest
Re:Can't do for/while loops - can you help?
« Reply #14 on: 13 Jun 2005, 15:41:19 »
When you shoot either the Major, Natasha or Sofia, the other two should immediately hunt you down.  They did in the first script which set all the waypoints to the player's position. As soon as you shot one, the others went combat and sneaked around to your position, following you as you moved.

In this version, they run off up the road and seem to be following the original waypoints, but in combat mode. Not very realistic as they're supposed to be crack troops and immediately guess where your shots came from...
« Last Edit: 13 Jun 2005, 15:45:04 by Corben Dallas »