Home   Help Search Login Register  

Author Topic: Global variable problem in local script.  (Read 1092 times)

0 Members and 3 Guests are viewing this topic.

Offline Kurayami

  • Members
  • *
Global variable problem in local script.
« on: 18 Dec 2002, 08:00:14 »
I'm working on a mission now where one group is to hold at a move waypoint until another group joins it or until the other group is dead.

I figured that the best way to do this was to make a trigger and have it execute a script to check both things. Since I'm going to be using multiple triggers like this, it'd be nice if I could use the same script at all of them.

Code: [Select]
_Group = _this select 0

#Main Loop
? (GroupDead == 1) : goto "Done"
? (West countSide units _Group == 0) : GroupDead = 1
? (Go == 1) : goto "Done1"
~1
goto "Main Loop"
#Done
hint "All units dead"
exit;
#Done1
hint "Variable true"
exit;

This works, but the variable is hard coded...
What I want to know why this doesn't work:

Code: [Select]
_Group = _this select 0
_Variable = _this select 1

#Main Loop
? (GroupDead == 1) : goto "Done"
? (West countSide units _Group == 0) : GroupDead = 1
? (_Variable == 1) : goto "Done1"
~1
goto "Main Loop"
#Done
hint "All units dead"
exit;
#Done1
hint "Variable true"
exit;

Making _Variable "Go" in the trigger's condition field doesn't do anything at all. The variable can be true, but the script doesn't pick it up. Why?

Thanks.

Gameer_77

  • Guest
Re:Global variable problem in local script.
« Reply #1 on: 18 Dec 2002, 11:56:41 »
Try doing this:

? _variable: goto "done1"

If that don't work, try changing the var's name. :)

Gameer

Offline Kurayami

  • Members
  • *
Re:Global variable problem in local script.
« Reply #2 on: 18 Dec 2002, 17:03:18 »
OK, I tried several variations of that. Still doesn't work.

Another thing I'm finding in messing around with it this morning is that it isn't counting the whole group. It's only counting the leader. If the leader dies, the script goes to #done and considers the entire group dead. If I put the same thing in a trigger (West CountSide units x == 0), it works just fine.

This is simple and it has me stumped  ::)

Offline Dinger

  • Contributing Member
  • **
  • where's the ultra-theoretical mega-scripting forum
Re:Global variable problem in local script.
« Reply #3 on: 18 Dec 2002, 18:16:36 »
any variable prefixed by _ is a local, not a global variable.'
Try calling it MyVariable
set activation to MyVariable = true
Dinger/Cfit

Offline Kurayami

  • Members
  • *
Re:Global variable problem in local script.
« Reply #4 on: 18 Dec 2002, 19:43:04 »
any variable prefixed by _ is a local, not a global variable.'
Try calling it MyVariable
set activation to MyVariable = true

Heh. I thought I'd need it to be all local in this case...
But looking at it again I can see that you're right. However, I still couldn't get it to work using several variations of this.

Code: [Select]
_Group = _this select 0
Check = _this select 1

#Main Loop
? (West CountSide units _Group == 0) : goto "Done"
? Check == 1 : goto "Done1"
~1
goto "Main Loop"
#Done
hint "All units dead"
exit;
#Done1
hint "Variable true"
I also tried simply using triggers and no external scripts at all.
Code: [Select]
West CountSide units x == 0 || Variable == 1Putting that in the condition field made it so the variable would work properly, but the trigger wouldn't execute when all of the units were dead.

I was a little confused about the way that OFP counts units, so I wrote this.
Code: [Select]
_Group = _this select 0

#Main Loop
_Alive = West CountSide units _Group
TitleText [format ["%1", _Alive], "plain"]
? (_Alive < 1) : goto "End1"
~1
goto "Main Loop"
#End1
hint "All units dead"
exit;
Since the result of the CountSide is printed on the screen, I can see what's happening. Something that I don't understand happens. Say that _Group has 9 men. 9 will be displayed. Shoot one and the count drops to 8. However, somewhere along the line it messes up. The count has dropped from 3 to 0 while there were still three guys alive and within the range of the trigger. It has done this on multiple occasions, always on a count of 1, 2 or 3. What gives?

And this is the init field of the group in question's leader if anybody wants to see.
Code: [Select]
this SetBehaviour "Careless"; group this SetGroupId ["Alpha", "GroupColor2"];Unit named Alpha2.

Offline Kurayami

  • Members
  • *
Re:Global variable problem in local script.
« Reply #5 on: 19 Dec 2002, 17:32:50 »
OK, I've messed around with it some more and can be a bit more specific about the counting thing.

It stops counting properly about 3 seconds after the leader of the group dies. If there are 6 guys and you shoot the leader, the count reads "5" for about 3 seconds before changing to 0 and exiting the script in spite of the fact that 5 guys are still alive. The time that the script fails appears to coinside with the time that the next in command becomes leader of the group.

If somebody could tell me why it does this I could fix it...

Offline Kurayami

  • Members
  • *
Re:Global variable problem in local script.
« Reply #6 on: 19 Dec 2002, 18:36:59 »
Hmm... Well, I seemed to have fixed it.

I changed the group leader's init field to
Code: [Select]
this Setbehaviour "careless"; Hotel1 = group this; group this SetGroupId ["Hotel", "GroupColor7"];Using "Hotel1" for _Group ensures that the units are counted properly.
But... um... why was there a problem with the other way? It's not as if the units weren't grouped as they were being counted. I'm kind of confused as to why this works and the other way doesn't.
« Last Edit: 19 Dec 2002, 18:37:37 by Kurayami »