Home   Help Search Login Register  

Author Topic: Can't do for/while loops - can you help?  (Read 2296 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 »

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:Can't do for/while loops - can you help?
« Reply #15 on: 13 Jun 2005, 15:50:34 »
they still do hunt the player down... i agree sometimes one of them seems to disappear off in another direction, but whoever it is soon comes running... ;)

on a side-note, the jeep with the general in it doesn't need so many waypoints to get where it's going. you'd be surprised how few the ai needs to get it to its destination...

Corben Dallas

  • Guest
Re:Can't do for/while loops - can you help?
« Reply #16 on: 13 Jun 2005, 16:20:19 »
Hmmm....

The original 'set all waypoints' script set them after me at once, which was far more realistic.  Why is this different..?

As to the General's jeep - if I set less waypoints the idiot AI driver crashes into trees, etc., and then the meeting messes up as they don't arrive on time.  I've spent many hours messing with this - if there's an easier way to set up a meeting please tell me!

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:Can't do for/while loops - can you help?
« Reply #17 on: 13 Jun 2005, 16:38:59 »
to make sure two parties meet at a certain time, synchronise the two waypoints. that will make whoever gets there first wait for the stragglers before moving on.

Corben Dallas

  • Guest
Re:Can't do for/while loops - can you help?
« Reply #18 on: 13 Jun 2005, 17:35:42 »
Ah!  That easy?  Geez... ;)

Corben Dallas

  • Guest
Re:Can't do for/while loops - can you help?
« Reply #19 on: 14 Jun 2005, 10:05:52 »
I'm still having awful trouble with this hunt-me-down stuff. Well, trouble if I try to use the -seek-and-destroy/cycle final wp method.

I've tried every combination of seek/cycle, synchonisation, etc., and all I get is them running in the wrong direction when I kill one of the three in the group. In other words, they still follow the original wp sequence for a short time. They then don't even hunt me down very well.

However, if I set all their wps to 'getpos player' in the script loop, as soon as one is shot they come after me like a pack of terriers on amphetamines.

Confused. I can make it work the shabby way, but would rather have a flexible 'pass the group name and last wp number' to get hunted by any unit I choose.

Perhaps it's because I'm on 1.46 and something doesn't work the same as 1.9x ???
« Last Edit: 14 Jun 2005, 10:06:07 by Corben Dallas »

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:Can't do for/while loops - can you help?
« Reply #20 on: 14 Jun 2005, 11:36:35 »
it may well be a version discrepancy, but i doubt it. attached is a version which seems to work - they come straight for the player.

Corben Dallas

  • Guest
Re:Can't do for/while loops - can you help?
« Reply #21 on: 14 Jun 2005, 12:10:14 »
Not for me they don't!  I set seek and cycle wps away from the last main cycle, then sync'd the trigger to the one before the seek (ie., the last in the main wp set).  I then pass [this, 9, 10] to the script, and kill one of the group.  The others run away from me combat mode, ie., to the next wp in the main set.

I tried passing [this, 8, 9] - no change.
Tried setting the wp in the script loop 'manually' - no change.
Tried sync'ing the trigger to the seek wp - no change.

The script runs when the trigger fires - I put a hint in to test it.

So the only way I've got it to work correctly so far, and get them to hunt me immediately, is to set every flaming wp to getpos player.

This is doing my head in.  ???  Perhaps I'll just leave it setting all wps to get me, but I'd rather have a flexible script to use with other units.

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:Can't do for/while loops - can you help?
« Reply #22 on: 14 Jun 2005, 12:15:52 »
what does 'this' refer to? the way the script is set up, you need to pass it the name of the group leader. that way it knows whose waypoints you mean. if it's in a trigger, i'm not sure what 'this' will refer to, most likely the trigger itself... which won't have any waypoints.

Corben Dallas

  • Guest
Re:Can't do for/while loops - can you help?
« Reply #23 on: 14 Jun 2005, 12:31:23 »
Aha!  Thank you yet again.  Changed it from 'this' to 'TheMajor' and it it now works.  They still don't come for me immediately though, as they do if you set all wps to getpos player.  No noob idea at all why, but it looked better that way - as though when you shot him in the back they saw where the bullets had come from.

This'll do fine though!  :)  Perhaps I should consider this solved - you folks must be yawning a lot...

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:Can't do for/while loops - can you help?
« Reply #24 on: 14 Jun 2005, 12:34:26 »
it does seem a weird one, and like i say - the zip i sent seems to work fine for me - they come straight at the player. to be honest i'm a bit curious myself as to what may be going on with your version that they go off to another waypoint first. logically, if the switch trigger points to the 'seek & destroy' waypoint, that's where they should go, immediately....  :-\

Corben Dallas

  • Guest
Re:Can't do for/while loops - can you help?
« Reply #25 on: 14 Jun 2005, 13:37:34 »
Well, wouldn't you know it - it's my fault.  When I looked at the one you sent (cheers for that) I thought I'd set my latest added-to version up the same way.  However, I didn't have the trigger set as a Switch.  Now it's all fine :)

I'll put this thread to sleep now, and many thanks.  I'm starting to get the hang of triggers and scripts at least, and now have the group in the car go combat if they turn up and find someone dead.  Shame OFP's AI doesn't do that sort of thing already - I can't see any reason why any armed forces would casually stand about when there are bodies all over the place!