Squirrel

The programming language
Welcome to Squirrel Sign in | Join | Help
in Search

"triggers" from Rise of Nations, how to get such stuff in Squirrel?

Last post 08-12-2009, 3:29 AM by Elijah Frost. 2 replies.
Sort Posts: Previous Next
  •  06-15-2009, 10:09 PM 3309

    "triggers" from Rise of Nations, how to get such stuff in Squirrel?

    In Rise of Nations Scripts, there is a language feature called "trigger"

    trigger(/* conditions under which trigger wil fire*/)
    {
        //Trigger body, just like function body
    }

    Each trigger is executed at least once (ofc if it isn't disabled by
    default). After trigger has fired, it becomes disabled and will not
    fire again, unless enable_trigger(MyTriggerName) function is used in the
    body of the trigger.

    In Squirrel, where do I get similar functionality? If there is none, then
    what is solution for this situation?
     
  •  07-28-2009, 7:59 PM 3397 in reply to 3309

    Re: "triggers" from Rise of Nations, how to get such stuff in Squirrel?

    Can you explain how they work a bit more? What triggers them to begin with?
  •  08-12-2009, 3:29 AM 3428 in reply to 3397

    Re: "triggers" from Rise of Nations, how to get such stuff in Squirrel?

    Okay, here is how they look like and what they do.

    Syntax
    Trigger's syntax is very similar to that of funtion.
    trigger trigger_name([conditions_under_wich_trigger_will_fire)
    {
         //List of actions to perform every time trigger fires, just like any function's body

        /*Optional: trigger control statement, either enable_trigger() or disable_trigger(), becasue triggers  only fire once. If we want trigger to fire again, we should place enable_trigger() in the end */

    }


    Let us create a trigger wich will check victory/defeat conditions.
    trigger VictoryCheck(GetPlayerUnitsCount <= 0)   /*under this condition trigger will fire*/
    {
        Defeat();
    }


    Here is another trigger which we want to fire every game tick.
    trigger EternalTrigger() /*since we want trigger to fire every tick, no condition required*/
    {
        print("Eternal Trigger ticked");
        enable_trigger(); //It enables trigger to fire once again
    }


    Now, we can disable EternalTrigger from any place in our script. It can be done from both funtions and another triggers:
    function LetUsDisableOurTrigger()
    {
        disable_trigger("EternalTrigger"); /*Eternal trigger will not tick anymore, unless we enable_trigger() it*/
    }

    or we can disable it from another trigger
    trigger TriggerDisablingAnotherTrigger()
    {
        disable_trigger("EternalTrigger");
        /*Since triggers only fire once, this trigger won't fire again,           unless we  allow it to by using enable_trigger() */
    }


    You have got the idea, haven't you?




View as RSS news feed in XML
Powered by Community Server, by Telligent Systems