Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
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.
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
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).
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
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.