[General] Map initialization does not work (vJASS)

Level 2
Joined
Feb 23, 2025
Messages
8
I'm trying to print a custom text on the Player(0)'s in-game screen in Vanilla Jass style for a practice, but World Editor never print it even though the code does not throw any syntax error while it's being saved.

JASS:
// Custom Script Name: foo

function fooAction takes nothing returns nothing
    // variable initialization
    local integer red
    local string message
    
    // variable assignment
    set red = 0
    set message = "hello world!"
    
    // invoke a built-in function
    // used a different native function from common.j instead of DisplayTimedTextToPlayer() wherer it's used in BJDebugMsg
    call DisplayTextToPlayer(Player(red), 0, 0, message)   
endfunction


function InitTrig_foo takes nothing returns nothing
    // variable declaration
    local trigger t = CreateTrigger()
    
    // invoke a built-in function called TriggerAddAction
    call TriggerAddAction(t, function fooAction)
    
    // kill memory leak
    set t = null
endfunction

I founded an alternative way (yet it's advanced) from one of the Tutorial page on this site, using the initializer keyword with Library like this;

JASS:
library Bar initializer init 
// Throws a syntax error;

    private function barAction takes nothing returns nothing
        local integer red = 0
        local string message = "hello world bar!"

        call DisplayTextToPlayer(Player(red), 0, 0, message)
    endfunction

    private function init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerAddAction(t, function barAction)
        set t = null
    endfunction

endlibrary

But this version throws a massive error list called Unknown compile error from the first line where the library starts.

According to this article, a function that is pointed by the keyword initializer is equivalent to InitTrig_* outside of the library block though, none of them works on my map right now.

Any solutions?
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
Looking at your first code, your InitTrig_foo function might not be getting called. But even if you did call it you still wouldn't see the text message since fooAction is never being called. All you've created in that code is an Event-less trigger:
  • t
    • Events
    • Conditions
    • Actions
      • Player - Display text message to (Player(1)): "hello world"
I don't know why the library doesn't work in your second code, you should try renaming things and looking into the errors. Maybe you're on an old version that doesn't support libraries?
 
Level 2
Joined
Feb 23, 2025
Messages
8
Looking at your first code, your InitTrig_foo function might not be getting called. But even if you did call it you still wouldn't see the text message since fooAction is never being called. All you've created in that code is an Event-less trigger:
  • t
    • Events
    • Conditions
    • Actions
      • Player - Display text message to (Player(1)): "hello world"
I don't know why the library doesn't work in your second code, you should try renaming things and looking into the errors. Maybe you're on an old version that doesn't support libraries?

you still wouldn't see the text message since fooAction is never being called.
Doesn't the built-in function TriggerAddAction(t, function fooAction) register the fooFunction to the initializer InitTrig_foo? If it's not, which function do the job?

All you've created in that code is an Event-less trigger:
I tried to add TriggerRegisterPlayerEvent(t, **EVENT_CONSTANT**) on the first code but couldn't find any appropriate event variables from common.j. If it registers the event, which event constant variable should I use?

Maybe you're on an old version that doesn't support libraries?
I'm using the Vanilla World Editor from the latest version of W3R.
 
Last edited:
Level 45
Joined
Feb 27, 2007
Messages
5,578
There is no syntax error with that example Bar library, so as Uncle said the only explanation is that you didn't enable JASSHelper/vJASS in the map (trigger editor > JASSHelper > enable... does have to be done once for every map manually) or you are on an older patch before JASSHelper was officially adopted into the modern WE.

Even if it did compile, though, it still wouldn't print hello world for the same reason as you other code doesn't: the trigger is created but has no events and is never run. The init function runs as expected, so you would really just want to put your print message in that function. There's not really a reason to involve a trigger just because you want to execute a function; triggers are really only necessary when you to interface with an Event of some kind.
 
Level 2
Joined
Feb 23, 2025
Messages
8
There is no syntax error with that example Bar library, so as Uncle said the only explanation is that you didn't enable JASSHelper/vJASS in the map (trigger editor > JASSHelper > enable... does have to be done once for every map manually) or you are on an older patch before JASSHelper was officially adopted into the modern WE.

Even if it did compile, though, it still wouldn't print hello world for the same reason as you other code doesn't: the trigger is created but has no events and is never run. The init function runs as expected, so you would really just want to put your print message in that function. There's not really a reason to involve a trigger just because you want to execute a function; triggers are really only necessary when you to interface with an Event of some kind.

you didn't enable JASSHelper/vJASS in the map (trigger editor > JASSHelper > enable..
Thank you for the critical information, but the map still doesn't print out the message from the both codes.

Screenshot 2025-02-24 163208.png
 
Level 45
Joined
Feb 27, 2007
Messages
5,578
the map still doesn't print out the message from the both codes
it still wouldn't print hello world for the same reason as you other code doesn't: the trigger is created but has no events and is never run. The init function runs as expected, so you would really just want to put your print message in that function. There's not really a reason to involve a trigger just because you want to execute a function; triggers are really only necessary when you to interface with an Event of some kind.
I tried to add TriggerRegisterPlayerEvent(t, **EVENT_CONSTANT**) on the first code but couldn't find any appropriate event variables from common.j. If it registers the event, which event constant variable should I use?
Such variables could be found in either Blizzard.j or common.j; in this case it's common:
JASS:
    //===================================================
    // For use with TriggerRegisterPlayerEvent
    //===================================================


/**
@patch 1.07
*/
    constant playerevent        EVENT_PLAYER_ARROW_LEFT_DOWN            = ConvertPlayerEvent(261)
/**
@patch 1.07
*/
    constant playerevent        EVENT_PLAYER_ARROW_LEFT_UP              = ConvertPlayerEvent(262)
/**
@patch 1.07
*/
    constant playerevent        EVENT_PLAYER_ARROW_RIGHT_DOWN           = ConvertPlayerEvent(263)
/**
@patch 1.07
*/
    constant playerevent        EVENT_PLAYER_ARROW_RIGHT_UP             = ConvertPlayerEvent(264)
/**
@patch 1.07
*/
    constant playerevent        EVENT_PLAYER_ARROW_DOWN_DOWN            = ConvertPlayerEvent(265)
/**
@patch 1.07
*/
    constant playerevent        EVENT_PLAYER_ARROW_DOWN_UP              = ConvertPlayerEvent(266)
/**
@patch 1.07
*/
    constant playerevent        EVENT_PLAYER_ARROW_UP_DOWN              = ConvertPlayerEvent(267)
/**
@patch 1.07
*/
    constant playerevent        EVENT_PLAYER_ARROW_UP_UP                = ConvertPlayerEvent(268)
/**
@patch 1.29.0.8803
*/
    constant playerevent        EVENT_PLAYER_MOUSE_DOWN                 = ConvertPlayerEvent(305)
/**
@patch 1.29.0.8803
*/
    constant playerevent        EVENT_PLAYER_MOUSE_UP                   = ConvertPlayerEvent(306)
/**
@patch 1.29.0.8803
*/
    constant playerevent        EVENT_PLAYER_MOUSE_MOVE                 = ConvertPlayerEvent(307)
/**
@patch 1.31.0.11889
*/
    constant playerevent        EVENT_PLAYER_SYNC_DATA                  = ConvertPlayerEvent(309)
/**
@patch 1.31.0.11889
*/
    constant playerevent        EVENT_PLAYER_KEY                        = ConvertPlayerEvent(311)
/**
@patch 1.31.0.11889
*/
    constant playerevent        EVENT_PLAYER_KEY_DOWN                   = ConvertPlayerEvent(312)
/**
@patch 1.31.0.11889
*/
    constant playerevent        EVENT_PLAYER_KEY_UP                     = ConvertPlayerEvent(313)
Instead of combing through either of those to find what you're looking for (though it may show up with a relatively general search), you can often shortcut by making a GUI trigger with the event/condition/action/function you want to investigate and then converting it to JASS to see how that looks. You would see something like EVENT_PLAYER_UNIT_SPELL_EFFECT and could either use that directly or follow the chain of other functions that call functions and see how it all fits together.
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
Doesn't the built-in function TriggerAddAction(t, function fooAction) register the fooFunction to the initializer InitTrig_foo?
Not exactly. InitTrig_foo is setup to run at map initialization and any code inside of it will be happen at that time as well. Because of this you've successfully created a Trigger and registered an Action to it. The problem is that you're expecting fooAction to run immediately but you never did anything that would call it immediately.

You registered fooAction as an Action, which is different than calling it -> call fooAction().

You're meant to combine these registered Actions with registered Events and Conditions, effectively creating a Trigger:
  • My Trigger
    • Events
      • Registered events...
    • Conditions
      • Registered conditions...
    • Actions
      • Registered actions... These only happen after an Event occurs and only if all Conditions are true.

If it's not, which function do the job?
If you want fooAction to happen during map initialization then a Trigger isn't even necessary, just call the function directly:
JASS:
function InitTrig_foo takes nothing returns nothing
    call fooAction()
endfunction
 
Last edited:
Top