Home   Help Search Login Register  

Author Topic: Need to correct a script  (Read 1300 times)

0 Members and 1 Guest are viewing this topic.

Serial Killer

  • Guest
Need to correct a script
« on: 29 Nov 2005, 19:01:35 »
Can anyone correct this script I made, for me, please?

Quote
Hint "Enemy neutralized!";
flg7 setFlagTexture "rus_vlajka.pac";
"enemy7" setMarkerColor "ColorGreen"
?(alive reinf7): goto "reinf"
?!(alive reinf7): goto "done"
#reinf
~2
Hint "The enemy is launching a counter-attack"
r7 doMove getPos flg7; r7 setBehaviour "aware";

Exit

#Done

Exit

Thanks

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Need to correct a script
« Reply #1 on: 29 Nov 2005, 19:07:49 »
What problems do you have with it?  I can see some redundancy, but providing everything is correctly defined it doesn't strike me as being significantly in error.

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:Need to correct a script
« Reply #2 on: 29 Nov 2005, 19:10:46 »
just in case it's this simple,

Code: [Select]
r7 doMove getPos flg7; r7 setBehaviour "aware";
should the r7 not be reinf7?

just a thought...

Serial Killer

  • Guest
Re:Need to correct a script
« Reply #3 on: 29 Nov 2005, 19:13:40 »
What problems do you have with it?  I can see some redundancy, but providing everything is correctly defined it doesn't strike me as being significantly in error.

Here's the error I get...


That script is supposed to check if a group named "reinf7" is alive, and if yes, it should move to an object named "flg7" and there's supposed to be a hint (see the script). If no, nothing happens.

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Need to correct a script
« Reply #4 on: 29 Nov 2005, 19:15:50 »
You can't check to see if a group is alive using the alive command, only an individual unit can be checked that way.  For a whole group you should use something like:

if ({alive _x} count units grpname < 1) then {they are all dead} else {no they arn't}
« Last Edit: 29 Nov 2005, 19:32:26 by THobson »

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:Need to correct a script
« Reply #5 on: 29 Nov 2005, 19:16:48 »
only units can be checked for life. for a group, you need to check all the units within that group.

Code: [Select]
?({alive _x} count units group reinf7) >0:goto "reinf"
exit

that should work.

LoTekK

  • Guest
Re:Need to correct a script
« Reply #6 on: 29 Nov 2005, 19:20:18 »
From the comref:
Quote
alive obj

Operand types:
    obj: Object
So it won't work if you just apply it to a group. Maybe add everyone in the group to an array, then you could check each member, and if dead, remove from the array? Then you can check if the array is empty.

edit:
Bedges, that doesn't look like it would work. For one, the syntax looks like you meant to use forEach. For another, according to the comref, count doesn't take any parameters. It only counts how many members are in an array, period. I could be reading your code wrong, though.

edit2:
On a hunch, I did a quick test in the mission editor. Dead guys get removed from the group (according to the comref they return as grpNull). So you simply need:

Code: [Select]
if (count reinf7 > 0) then {goto "reinf"} else {goto "done"}
« Last Edit: 29 Nov 2005, 19:34:34 by LoTekK »

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Need to correct a script
« Reply #7 on: 29 Nov 2005, 19:35:41 »
bedges' code should work once the word group is removed.  reinf7 is already a group.  If reinf7 was a unit then it would be fine as it is.

The way count works is:

{condition} count arrayname

It returns the number of elements in arrayname for which the condition is true.


Edit:
Dead guys do indeed get removed from a group - but it can take a long time.  Several minutes sometimes.  How many times have you as a group leader had dead guys in your team and not known it until you did a report status?  This works in the same way.  Kill a whole group and it can be quite sometime before count catches up with the fact.

{alive _x} count units groupname

is the way to go on this.
« Last Edit: 29 Nov 2005, 19:41:04 by THobson »

LoTekK

  • Guest
Re:Need to correct a script
« Reply #8 on: 29 Nov 2005, 19:44:52 »
Ah, so count can take an extra parameter. Good to know. :)

Also good info on the group needing to know about the dead guy before it gets removed from the group.

But come to think of it, if the entire group was dead, wouldn't they all get assigned to grpNull immediately?

edit:
Answering my own question after a quick test in the mission editor. Evidently they don't get removed immediately. Even if a friendly unit is in the area to witness the slaughter. Even if a friendly walks over their dead bodies. They seem to get removed randomly at very long intervals.
« Last Edit: 29 Nov 2005, 19:52:59 by LoTekK »

Serial Killer

  • Guest
Re:Need to correct a script
« Reply #9 on: 29 Nov 2005, 19:48:31 »
None of your advices didn't work :(

LoTekK

  • Guest
Re:Need to correct a script
« Reply #10 on: 29 Nov 2005, 19:59:32 »
Serial Killer:
Maybe you have a typo somewhere? I tried THobson's example and it worked like a charm:
Code: [Select]
if ({alive _x} count units reinf7 > 0) then {goto "reinf"} else {goto "done"}

Serial Killer

  • Guest
Re:Need to correct a script
« Reply #11 on: 29 Nov 2005, 20:09:24 »
I'll try again then...

Ok, it's working. Thanks.
« Last Edit: 29 Nov 2005, 20:14:32 by Serial Killer »