How to Grab and Count Enemy Units?

Started by Kernel64, March 08, 2010, 01:00:10 PM

Previous topic - Next topic

vjeux

Quote from: Kernel64 on March 09, 2010, 05:37:47 AM
while(A) {
   do(x)...
}
while(!B) {
   do(y)...
}
We can do things in paralell within the game. In order to create a thread you have to start a trigger and inside do a while (1) { /* Something */; Wait(1); }


Here is a working example:


// Define the trigger function
bool TriggerTiming (bool checkConds, bool doActions) {
  while (1) {
    // Do something every 5 seconds
    Wait(5, 0);
  }
}


void InitMap() {
  // Create a new trigger based off the function
  trigger t = TriggerCreate("TriggerTiming");


  // Run it at map initialization
  TriggerAddEventMapInit (t);
}

Kernel64

That's very interesting! Can you explain more on creating triggers, what triggers are?

hd

Quote from: Kernel64 on March 12, 2010, 04:36:52 PM
That's very interesting! Can you explain more on creating triggers, what triggers are?

a trigger is exactly how it sounds. they are "triggered" once specific conditions are met. they're like if statements but usually just lie in way for conditions to be met and then they ... "trigger"

Astazha

I love it.  I'm also astonished that we have it.


What I'm really curious to know is what other events besides map init can call a trigger.

vjeux

#19
Yeah triggers are functions that are call upon several events. At the moment, only MapInit and ChatMessage handlers are implemented.
If you want to know more I've documented all the trigger functions there:

       
  • TriggerCreate(string func) - Create a new trigger from a function
  • TriggerDebugOutput(int triggerDebug, text message, bool UI) - Display a debug message
  • TriggerAddEventMapInit(trigger t) - Register a trigger that will be executed on map initialization
  • Wait(fixed seconds, int timezone) - Pause the current trigger without blocking
  • TriggerAddEventChatMessage(trigger t, int player, string message, bool strict) - Register a trigger that will be executed on Chat Messages
  • EventChatMessage(bool strict) - Message content available on TriggerAddEventChatMessage callback
The trigger function is returning a boolean and takes two booleans as argument. I'm not sure yet what they are used for.

Kernel64

In the editor, this might look like "Events"?