SendActivationEvent

From Game Editor

Jump to: navigation, search
int SendActivationEvent(char *actorName);

This function acts as a trigger to initiate the Activation Event for different actors. Activation Events are extremely useful and versatile and allow you to overcome some of the functional limitations gameEditor currently has. Like the Create Actor event, the event it triggers is run immediately when the function is called. So, it will stop the current script, to run the cloneName's activation event.


SendActivationEvent Input

actorName

  • "Parent Actor": Event Actor's parent, if actor has a parent.
  • "Creator Actor": Event Actor's creator, if Event Actor has been created in some "Create Actor" action.
  • "Collide Actor": Actor that collided with the event Actor.
  • Any Actor name or clonename in the game.
  • NOTE: You cannot use "Event Actor" like in all other functions requiring actorName. If you want to call the event actor's activation event you have to use clonename, or a string constant equivalent of it.


Example:

Using spawn point actors and activation events, you can easily create resettable levels without having to use LoadGame. Simply lay the spawn actors throughout the level, and when you want to load the level, send an activation event to all of the spawn actors in that level.

Global Code

void
activateSpawn (int start, int finish)
{
    int i;
    char buffer[50];
    for(i=start;i<finish;i++)
    {
        sprintf(buffer, "%s.%d", "spawn", i);
        SendActivationEvent(buffer);
    }
}


This function really activates the spawn actors you designate, so you can tell it more precisely which enemies should be created. For more in depth examples of creating separate levels, click here.


Tips

By using variables, you can have multiple events triggered per activation event. Since the SendActivationEvent can only trigger one event, you have to use variables to more precisely control what the actor will do in the single event. Though there are several ways to do this, the one with the most control is to create an actor variable, in this example named activateType. When sending the activation event to an actor, you first set its activateType variable. This way you can have multiple events trigger depending on the current state of the game (in this example difficulty).

Global Code

void
activateSpawn (int start, int finish, int difficulty)
{
    int i;
    char buffer[50];
    for(i=start;i<finish;i++)
    {
        sprintf(buffer, "%s.%d", "spawn", i);
        getclone(buffer)->activateType=difficulty;
        SendActivationEvent(buffer);
    }
}


So setting it to 0 would trigger the default enemy activation event, while setting it to 1 might make the spawn actor spawn harder difficulty enemies. Then in the activation event, you would do something like this.

spawn -> Activation Event (any actor) -> Script Editor

switch(activateType)
{
    case 0:
    CreateActor("enemEasy", "enemEasyAnim", "(none)", "(none)", 0, 0, false);
    break;

    case 1:
    CreateActor("enemHard", "enemHardAnim", "(none)", "(none)", 0, 0, false);
    break;
}

In this example it is simple enough that you don't need to use the activateType variable, as in the activation event, you could switch it for a global variable difficulty, but when creating more complex systems it will be come extremely handy.