• 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!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Noob JASS concern -- how does the subroutine get called?

Status
Not open for further replies.
Level 1
Joined
Aug 10, 2013
Messages
1
So I saw this on wikipedia:
Code:
function Trig_JASS_test_Actions takes nothing returns nothing
 call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "Hello, world!")
endfunction

However, how does the function/subroutine/method Trig_JASS_test_Actions get called?

How do I call Trig_JASS_test_Actions when the map just gets loaded?
 
Level 14
Joined
Jun 27, 2008
Messages
1,325
There are different ways to run a function on map initialization.

In standard jass each Trigger (in terms of the GUI-triggers in the left column of the triggereditor) automatically has a init function assigned that gets called when the map loads.
Example:
When you create an empty GUI Trigger called "MyTrigger" and convert it to Jass, you get:

JASS:
function Trig_MyTrigger_Actions takes nothing returns nothing
endfunction

//===========================================================================
function InitTrig_MyTrigger takes nothing returns nothing
    set gg_trg_MyTrigger = CreateTrigger(  )
    call TriggerAddAction( gg_trg_MyTrigger, function Trig_MyTrigger_Actions )
endfunction

The function InitTrig_MyTrigger is executed when the map loads, so thats where you do stuff like creating jass-triggerobjects and assign events and actions to them. But you can also just use it to call your own functions:

JASS:
function doSomething takes nothing returns nothing
    call BJDebugMsg("blabla hello world...")
endfunction

//===========================================================================
function InitTrig_MyTrigger takes nothing returns nothing
    call doSomething()
endfunction

If you use vJass then you dont need to use these premade initfunctions. Instead you can use vjass-Libraries and define your own initfunctions:

JASS:
library MyFirstLibrary initializer initFunc
    function doSomething takes nothing returns nothing
        call BJDebugMsg("blabla hello world...")
    endfunction

    private function initFunc takes nothing returns nothing
        call doSomething()
    endfunction
endlibrary
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
All JASS has 2 types of entry point.
1. The game itself when initializing the map, this runs all map initialization functions. I think one might even run when you join a session to build the lobby.
2. When an event or timer fires. This causes a trigger to run a function (or many functions).

Type 1 is not controllable, the game will always call certain function names it expects. If they are not present it may crash. You can get some of the functions to call custom functions which have logic you define.

Type 2 is what you really control. You can specify what events run a trigger and what timers run what functions. Most of your code will be running from this type, only using Type 1 for initializing state.
 
Status
Not open for further replies.
Top