• 🏆 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] Message Issue (basic)

Status
Not open for further replies.
Level 2
Joined
Jun 12, 2016
Messages
11
JASS:
function Msg takes string s returns nothing
  call DisplayTextToForce( GetPlayersAll(), s )
endfunction

function ShowMessage takes nothing returns nothing
  call Msg("This is a message!")
endfunction

function ShowSum takes integer a, integer b returns nothing
local integer r=a+b
  call Msg("r= "+I2S(r))
endfunction

function Trig_JASS_test_Actions takes nothing returns nothing
  call ShowMessage()
  call ShowSum(33,45)
endfunction

function d takes nothing returns nothing
  local trigger z = CreateTrigger()
  call TriggerRegisterTimerEventPeriodic(z, 2)
  call TriggerAddAction(z, function Trig_JASS_test_Actions)
endfunction

Right now I'm recapping some basics of Jass but this code doesn't show up anything on my screen.

How can I fix this issue?
 
Last edited:
Level 8
Joined
Jan 28, 2016
Messages
486
I'm assuming you don't have JNPG because I recreated your trigger and I ran into an error due to the init function not having the "InitTrig_" prefix in its name (I also renamed it 'Test'). Other than that, it worked flawlessly. You might have another trigger that's interfering with the code so you might have to expand your search for the source of your problem.

JASS:
function Msg takes string s returns nothing
    call DisplayTextToForce( GetPlayersAll(), s )
endfunction

function ShowMessage takes nothing returns nothing
    call Msg("This is a message!")
endfunction

function ShowSum takes integer a, integer b returns nothing
    local integer r=a+b
    call Msg("r= "+I2S(r))
endfunction

function Test_Actions takes nothing returns nothing
    call ShowMessage()
    call ShowSum(33,45)
endfunction

//===========================================================================
function InitTrig_Test takes nothing returns nothing
  local trigger t = CreateTrigger()
  call TriggerRegisterTimerEventPeriodic(t, 2)
  call TriggerAddAction(t, function Test_Actions)
endfunction

Message Issue Screenshot.jpg
 
Last edited:
Most JASS scripts will have an entry point that determines the flow of the code. It is quite similar to GUI:
  • Example
    • Events
      • Unit - A unit dies
    • Conditions
    • Actions
      • Unit - Kill (Killing unit)
In the trigger above, there is a natural flow to the trigger. First, the events must fire -> A unit dies. Then the actions are ran -> kill the attacker.

When this is converted to JASS, the events first need to be registered. You've done that in function d, but where is d called? How does the editor know that it should call d first?

If you convert a trigger from GUI to JASS, you'll notice that all the events are registered in InitTrig_<Trigger Name>. This is called an initializer. For every trigger, the editor will try to run a function following that format when the game is setting up (map initialization), and that is usually the time that triggers/events are created. So if you want to get your code working, create a new trigger (e.g. named "Test") and Edit -> Convert to Custom Text. Remove all the code. Copy and paste your code in. Rename your "d" function appropriately. For example, if the trigger is named "Test", you'll want to name it "InitTrig_Test". Save the map, and try it out!

If you are using JassNewGenPack, then things are a little easier. You can simply enclose it in a scope or library, and tell it which function is your initializer. Here is some sample code:
JASS:
scope Test initializer d

    function Msg takes string s returns nothing
        call DisplayTextToForce( GetPlayersAll(), s )
    endfunction

    function ShowMessage takes nothing returns nothing
        call Msg("This is a message!")
    endfunction

    function ShowSum takes integer a, integer b returns nothing
        local integer r=a+b
        call Msg("r= "+I2S(r))
    endfunction

    function Trig_JASS_test_Actions takes nothing returns nothing
        call ShowMessage()
        call ShowSum(33,45)
    endfunction

    function d takes nothing returns nothing
        local trigger z = CreateTrigger()
        call TriggerRegisterTimerEventPeriodic(z, 2)
        call TriggerAddAction(z, function Trig_JASS_test_Actions)
    endfunction

endscope

Notice the "initializer d" part. This tells the editor to run the function "d" on initialization. Remember, this code will only compile if you have JassNewGenPack (or JassHelper).
 
Level 2
Joined
Jun 12, 2016
Messages
11
I'm assuming you have JNPG because I recreated your trigger and I ran into an error due to the init function not having the "InitTrig_" prefix in its name (I also renamed it 'Test'). Other than that, it worked flawlessly. You might have another trigger that's interfering with the code so you might have to expand your search for the source of your problem.

JASS:
function Msg takes string s returns nothing
    call DisplayTextToForce( GetPlayersAll(), s )
endfunction

function ShowMessage takes nothing returns nothing
    call Msg("This is a message!")
endfunction

function ShowSum takes integer a, integer b returns nothing
    local integer r=a+b
    call Msg("r= "+I2S(r))
endfunction

function Test_Actions takes nothing returns nothing
    call ShowMessage()
    call ShowSum(33,45)
endfunction

//===========================================================================
function InitTrig_Test takes nothing returns nothing
  local trigger t = CreateTrigger()
  call TriggerRegisterTimerEventPeriodic(t, 2)
  call TriggerAddAction(t, function Test_Actions)
endfunction



Oh I got this. Thank you to reply!!
 
Level 8
Joined
Jan 28, 2016
Messages
486
No worries. I was meant to say that you don't have JNPG but I guess you figured that out yourself.

PnF explained it very well and in depth. Might be worth making a tutorial out of that! :D
 
Status
Not open for further replies.
Top