Potential problem with picked units

BiGyElLoWhAt

New Member
Reaction score
1
If I have a triggered patrol for a group of units, and I use something like this

pick all units in unit group and do multiple actions
Loop
Order picked unit to attack-move to center of region 1
wait 5 s
Order picked unit to attack-move to center of region 2
wait 5 s

Will this cause/encounter problems if I use the picked unit variable in another trigger?
I want the marines to patrol through 5 regions indefinitely (until triggered off later).
Actual code
Patrol Zones
Events
Conditions
Actions
Unit Group - Pick every unit in Marine_Patrol and do (Actions)
Loop - Actions
Unit - Order (Picked unit) to Attack-Move To (Center of Marine Patrol 1 <gen>)
Wait 4.00 seconds
Unit - Order (Picked unit) to Attack-Move To (Center of Marine Patrol 2 <gen>)
Wait 4.00 seconds
Unit - Order (Picked unit) to Attack-Move To (Center of Marine Patrol 3 <gen>)
Wait 4.00 seconds
Unit - Order (Picked unit) to Attack-Move To (Center of Marine Patrol 4 <gen>)
Wait 4.00 seconds
Unit - Order (Picked unit) to Attack-Move To (Center of Marine Patrol 5 <gen>)
Wait 4.00 seconds

This trigger is enabled once the unit group marine_patrol has 3 units in it, and disabled when it has 0. I generate marines when the overall marine group Marines is less than 5 and add them to fill up marine_patrol to 3... blah blah blah...
 

BiGyElLoWhAt

New Member
Reaction score
1
hmmm... so I was actually just curious about this in terms of later on, but it's not working how I expected... the marines get generated appropriately at first, they hit max, they get added to marine patrol (there has to be a better way to do it than how I did it). They start the patrol, get to zone 2, then stop and sit there. Also killing them doesn't turn the trigger back on. (Apparently you can't have a trigger with no event, figured that out from ^)

Anyways, I was hoping someone would look at my triggers and see what I'm doing wrong.

##

Generate Marines (initially off, gets turned on by completing a quest; this worked for the first time)
Events
Time - Every 10.00 seconds of game time
Conditions
(Number of units in Marines) Less than 5
Actions
Unit - Create 1 Marine for Player 12 (Brown) at (Random point in Region 004 <gen>) facing 180.00 degrees
Unit Group - Add (Last created unit) to Marines
Wait 10.00 seconds
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Number of units in Marine_Patrol) Equal to 3
Then - Actions
Trigger - Turn off Patrol Add <gen>
Trigger - Turn on Patrol Zone <gen>
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Number of units in Marine_Patrol) Equal to 0
Then - Actions
Trigger - Turn off Patrol Zone <gen>
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Number of units in Marine_Patrol) Less than 3
Then - Actions
Trigger - Turn on Patrol Add <gen>
Else - Actions
Do nothing

##
##This trigger basically is supposed to check the number of marines total. If it's less than 5, create a marine and add it to marines. It also toggles some other ##triggers (see below)
##

Stop Generate (haven't tested, should work though. initially on)
Events
Unit - A unit Dies
Conditions
(Unit-type of (Triggering unit)) Equal to Tent
(Number of units in Marine_tent) Equal to 0
Actions
Trigger - Turn off Generate Marines <gen>

##
##If all the tents get killed, marines stop generating. Pretty self explanatory.
##

Patrol Add (Initally on)
Events
Time - Every 1.00 seconds of game time
Conditions
(Number of units in Marines) Greater than 0
(Number of units in Marine_Patrol) Less than 3
Actions
Unit Group - Add (Random unit from Marines) to Marine_Patrol
##
##This is supposed to add a unit from Marines to Marine Patrol, I couldn't find a better way to add units other than a random, so it just loops over and over making ##sure marine patrol is 3, and adding marines if it's not
##

Patrol Zone (worked up until zone 2, then stopped; I'm not sure why. Initially off)
Events
Time - Every 4.00 seconds of game time
Conditions
Actions
Unit Group - Pick every unit in Marine_Patrol and do (Actions)
Loop - Actions
Unit - Order (Picked unit) to Attack-Move To (Center of Marine Patrol 1 <gen>)
Wait 4.00 seconds
Unit - Order (Picked unit) to Attack-Move To (Center of Marine Patrol 2 <gen>)
Wait 4.00 seconds
Unit - Order (Picked unit) to Attack-Move To (Center of Marine Patrol 3 <gen>)
Wait 4.00 seconds
Unit - Order (Picked unit) to Attack-Move To (Center of Marine Patrol 4 <gen>)
Wait 4.00 seconds
Unit - Order (Picked unit) to Attack-Move To (Center of Marine Patrol 5 <gen>)
Wait 4.00 seconds
Unit - Order (Picked unit) to Attack-Move To (Center of Marine Patrol 1 <gen>)

##
##This is the actual patrol, it should be pretty self explanatory. Move, wait, Move, wait, encounter something? Kill it
##

Ideally these would work as such. Once marines start getting generated, 3 get added to a patrol group. That patrol group patrols. If one dies, one generates and joins it. If they all die, it waits until it gets 3 to send them out. If I had to guess, I would say my error is in Generate_Marines, but I'm not sure where or how to fix it. Still pretty new to this whole thing.

Thanks.
 

jonas

You can change this now in User CP.
Reaction score
64
It will not work at all (e.g., it won't even reach the second unit)

What you want is this:

Code:
Every 8 seconds of game time:
  Order patrol group to move
  Wait 4 seconds
  Order patrol group to move
 

afisakov

You can change this now in User CP.
Reaction score
37
To start with, using waits in the middle of unit group- do actions for picked units is kind of risky.
I would remake that trigger as
variable marine_int is an integer
Trigger:
  • Events
    • Time - Every 4.00 seconds of game time
    • Conditions
    • Actions
    • if marine_int&lt;6 then
      • set marine_int=marine_int+1
    • else
      • set marine_int=1
    • endif
    • Unit Group - Pick every unit in Marine_Patrol and do (Actions)
    • Loop - Actions
    • if marine_int=1 then
    • Unit - Order (Picked unit) to Attack-Move To (Center of Marine Patrol 1 &lt;gen&gt;)
    • else
    • if marine_int=2 then
    • Unit - Order (Picked unit) to Attack-Move To (Center of Marine Patrol 2 &lt;gen&gt;)
    • else
    • if marine_int=3 then
    • Unit - Order (Picked unit) to Attack-Move To (Center of Marine Patrol 3 &lt;gen&gt;)
    • ... you get the picture

also, ordering units to move to center of region leaks a point. I recommend reading about memory leaks once you get the basic trigger to work... it will add up during a prolonged game.
I have not looked at the rest of the code yet, but fixing this would be a start.
 

BiGyElLoWhAt

New Member
Reaction score
1
It will not work at all (e.g., it won't even reach the second unit)

What you want is this:

Code:
Every 8 seconds of game time:
  Order patrol group to move
  Wait 4 seconds
  Order patrol group to move
I'm not sure what you're doing differently. I changed my time to 24s and same thing. go to the second zone then nothing.
To start with, using waits in the middle of unit group- do actions for picked units is kind of risky.
I would remake that trigger as
variable marine_int is an integer
Trigger:
  • Events
    • Time - Every 4.00 seconds of game time
    • Conditions
    • Actions
    • if marine_int&lt;6 then
      • set marine_int=marine_int+1
    • else
      • set marine_int=1
    • endif
    • Unit Group - Pick every unit in Marine_Patrol and do (Actions)
    • Loop - Actions
    • if marine_int=1 then
    • Unit - Order (Picked unit) to Attack-Move To (Center of Marine Patrol 1 &lt;gen&gt;)
    • else
    • if marine_int=2 then
    • Unit - Order (Picked unit) to Attack-Move To (Center of Marine Patrol 2 &lt;gen&gt;)
    • else
    • if marine_int=3 then
    • Unit - Order (Picked unit) to Attack-Move To (Center of Marine Patrol 3 &lt;gen&gt;)
    • ... you get the picture

also, ordering units to move to center of region leaks a point. I recommend reading about memory leaks once you get the basic trigger to work... it will add up during a prolonged game.
I have not looked at the rest of the code yet, but fixing this would be a start.
Why does adding the integer check matter? I definitely see what you're doing, but why does that work and not mine? I guess I don't see the flaw in my logic.
 

jonas

You can change this now in User CP.
Reaction score
64
I'm not sure what you're doing differently. I changed my time to 24s and same thing. go to the second zone then nothing.

Instead of doing one loop with waits in the body,

do multiple loops, each separated by a wait.

Second, I suggest using the "group order" action instead of ordering the units individualy (group order makes them move in formation, respecting unit speeds, etc).




And what afisakov wants is to create a global location array. This is called the table-driven approach.

Then the code becomes:


Code:
send all units to MarineLoc[next_loc]
if next_loc <= #locations:
  next_loc = next_loc + 1
else:
  next_loc = 0
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top