• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Spell] vJass beginning

Status
Not open for further replies.
Level 5
Joined
Sep 16, 2008
Messages
47
JASS:
scope Spell initializer Init
//===========================================================================
    private function Act takes nothing returns nothing
    call DisplayTimedTextToForce( GetPlayersAll(), 0.01, "Test" )
    endfunction
//===========================================================================
    private function Cond takes nothing returns boolean
        return GetSpellAbilityId() == 'A000'
    endfunction
//===========================================================================
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddCondition(t, Condition(function Cond))
        call TriggerAddAction(t, function Act)
    endfunction
endscope

The only thing i am interested in is how to fix it?
Because i would like to use globals i need scope, once i am trying to create any trigger with scope map is not loading.

What is wrong in this simple code?
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
Never use TriggerAddAction. Run everything from TriggerAddCondition. Take a look at my tutorial How to convert gui to efficient jass for more info on why.

When testing you can use call BJDebugMsg("Test").
Your trigger does compile fine.

What JNGP do you have ? Also JNGP allows for globals on any trigger. You just need the globals keyword to declare them. You do not need Scope or Library. You need JNGP.
 
I can instantly name two cases of why you should not always combine condtion and action in only the conditon function.

1. TriggerSleepAction might be used for simplification/cinematics, or also for this explicit desire to operate in a new virtual thread, but in the same function.

2.
In some cases (in one of my maps I use it), the user wants to split conditions from actions. Let my explain:
If a trigger fires, the condtion is checked (event responses are used in here), and if it's evaluated as true the action function will be fired.
But in my case, I don't only want to execute the actions by my trigger event, but also by call TriggerExecute function.
When ever I want run my trigger without firing the trigger event, I don't want check any condition, but directly run the actions. (because event responses won't work)
The logical solution for me is now to seperate conditions and actions, so I can skip my conditions if needed.

There might be more example of how it can be useful to use trigger actions.
So I just want to say, that it's no good to generalize it for each user and his map and ban TriggerAction. It still might be useful.

Sorry for going offtopic here, but I already tried to help in my post before. :D
 
Status
Not open for further replies.
Top