• 🏆 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!

[JASS] New trigger files not working for unknown reason

Status
Not open for further replies.
Level 1
Joined
Dec 12, 2019
Messages
3
My object is to display a text for testing, but when I create new trigger files and add some codes, the text won't display in the game

Code:
function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
    call BJDebugMsg("Hii")
    call BJDebugMsg("Hii") // I want to display the text for testing.
endfunction
//===========================================================================
function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_001 = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Untitled_Trigger_001, function Trig_Untitled_Trigger_001_Actions )
endfunction
// This entire code won't run even the editor doesn't throw the errors.

But if I add a new function in Melee Initialization, it runs.

Code:
function Trig_Melee_Initialization_Actions takes nothing returns nothing
    call MeleeStartingVisibility(  )
    call MeleeStartingHeroLimit(  )
    call MeleeGrantHeroItems(  )
    call MeleeStartingResources(  )
    call MeleeClearExcessUnits(  )
    call MeleeStartingUnits(  )
    call MeleeStartingAI(  )
    call MeleeInitVictoryDefeat(  )
    call BJDebugMsg("Hii") // added new function in Meele Initialization
endfunction

//===========================================================================
function InitTrig_Melee_Initialization takes nothing returns nothing
    set gg_trg_Melee_Initialization = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Melee_Initialization, function Trig_Melee_Initialization_Actions )
endfunction

I can't debug about this by myself because in my editor does not throw the errors when the game's running.

Any tips for fixing this problem? (I'm not using plugins.)
 
Last edited:
Level 1
Joined
Dec 12, 2019
Messages
3
It will do nothing because no event was registered for the trigger, meaning that your trigger is listening to no events in the game.
How do I figure out if triggers have no event register? The 2 examples on my post look almost exactly same, yet they are giving different results.

I've just tested creating 2 trigger files that one has Map initialize and another hasn't. And it gives exactly same code snippets like this:

<img src="Imgur" alt="">

Code:
function Trig_Conv_with_init_Actions takes nothing returns nothing
endfunction

//===========================================================================
function InitTrig_Conv_with_init takes nothing returns nothing
    set gg_trg_Conv_with_init = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Conv_with_init, function Trig_Conv_with_init_Actions )
endfunction

<img src="Imgur" alt="">

Code:
function Trig_Conv_no_init_Actions takes nothing returns nothing
endfunction

//===========================================================================
function InitTrig_Conv_no_init takes nothing returns nothing
    set gg_trg_Conv_no_init = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Conv_no_init, function Trig_Conv_no_init_Actions )
endfunction
 
Last edited:

Wrda

Spell Reviewer
Level 26
Joined
Nov 18, 2012
Messages
1,889
There's an option at the top of the custom text that has "run on map initialization", that's what makes the trigger run before the game starts. It's not an event, it only shows as that in GUI.
How do I figure out if triggers have no event register?
Maybe if you don't add, you don't have, no...? Maybe add it in GUI and then convert to custom text and see it for yourself.
 
Level 9
Joined
Jul 30, 2018
Messages
445
If you make a normal trigger and then convert it to Custom Text, you can tick the "Run on Map Initialization" above the Trigger Comment box and then the InitTrig_... will be ran on on map initialization.

If you make a custom script straight away, you can use a library to run it on map init:

JASS:
library MyLibrary initializer Init
    function Init takes nothing returns nothing
        call BJDebugMsg("Hello world!") //This will now be ran on map init
    endfunction
endlibrary

Don't try to do too much like how GUI -> Custom Text does, because that does a lot of stuff a bit stupidly, and for example never uses local variables. You can check individual functions (actions in GUI) to see how they are made in JASS, but otherwise you should look up how code in general is written (by looking at other people's code for example).

One thing GUI does super stupidly are conditions and ifs. It will create new function for pretty much all even short if-statements and that is a habit you shouldn't teach yourself.

Let's take a little example. A simple trigger like this:

  • Untitled Trigger 001
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Triggering unit)) Equal to Footman
        • Then - Actions
          • Player - Add 1000 to (Owner of (Killing unit)) Current gold
        • Else - Actions
Now, if we just convert this to custom text, we see how GUI makes code, and it's ugly. Compare this:

JASS:
function Trig_Untitled_Trigger_001_Copy_Func001C takes nothing returns boolean
    if ( not ( GetUnitTypeId(GetTriggerUnit()) == 'hfoo' ) ) then
        return false
    endif
    return true
endfunction
function Trig_Untitled_Trigger_001_Copy_Actions takes nothing returns nothing
    if ( Trig_Untitled_Trigger_001_Copy_Func001C() ) then
        call AdjustPlayerStateBJ( 1000, GetOwningPlayer(GetKillingUnitBJ()), PLAYER_STATE_RESOURCE_GOLD )
    else
    endif
endfunction
//===========================================================================
function InitTrig_Untitled_Trigger_001_Copy takes nothing returns nothing
    set gg_trg_Untitled_Trigger_001_Copy = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Untitled_Trigger_001_Copy, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddAction( gg_trg_Untitled_Trigger_001_Copy, function Trig_Untitled_Trigger_001_Copy_Actions )
endfunction

To this, which is what I would do, if I had to do a trigger like that in JASS:

JASS:
library FootmanDies initializer FootmanDies_Init
    function FootmanDies_GiveGold takes nothing returns boolean
        if (GetUnitTypeId(GetTriggerUnit()) == 'hfoo') then
            call AdjustPlayerStateBJ(1000, GetOwningPlayer(GetKillingUnitBJ()), PLAYER_STATE_RESOURCE_GOLD)
        endif
    endfunction

    //===========================================================================
    function FootmanDies_Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DEATH)
        call TriggerAddAction(t, function FootmanDies_GiveGold)
    endfunction
endlibrary

Now, I'm not a master at JASS yet either, so others can point out if even I do something stupidly now :p But just so you see a little bit how JASS (or any coding language, for that matter) works.

You can also always use Custom Script: call FootmanDies_Init() in your init trigger, so you don't need the initializer in the library.
 
Last edited:
Status
Not open for further replies.
Top