[vJass] "Run on Map Init" doesn't seem to run

mattyspatty

New Member
Reaction score
0
JASS:

scope MapInit initializer Init
    private function Actions takes nothing returns nothing
        local integer n = 0
        local group g = null
        local unit u = null
        
        //local rect vis1 = Rect(-14976, 14912, -9920, 10976)
        //local rect vis2 = Rect(-14976, 11040, -12512, 9344)
        //local rect gate = Rect(-10560, 11552, -10208, 11264)
        
        
        // Define schools
        set SCHOOL_NAMES[SCHOOL_EARTH] = "|c00006600Earth|r"
        set SCHOOL_NAMES[SCHOOL_AIR] = "|c0033ccffAir|r"
        set SCHOOL_NAMES[SCHOOL_FIRE] = "|c00ff0000Fire|r"
        set SCHOOL_NAMES[SCHOOL_WATER] = "|c000033ffWater|r"
        call SetTimeOfDay(8.00)
        
        call SetPlayerState(Player(0), PLAYER_STATE_RESOURCE_GOLD, 50)  // Test if anything works

        //call CreateFogModifierRect(Player(11), FOG_OF_WAR_VISIBLE, vis1, true, true) 
        //call CreateFogModifierRect(Player(11), FOG_OF_WAR_VISIBLE, vis2, true, true)
        //call ModifyGateBJ(bj_GATEOPERATION_OPEN, RandomDestructableInRectSimpleBJ(gate))


        set n = 0
        loop
            exitwhen n == 8
            if(GetPlayerSlotState(Player(n)) == PLAYER_SLOT_STATE_PLAYING) then
                call SetPlayerAllianceStateBJ(Player(n), Player(11), bj_ALLIANCE_ALLIED_VISION)
                call SetPlayerAllianceStateBJ(Player(11), Player(n), bj_ALLIANCE_ALLIED_VISION)
                call SetPlayerState(Player(n), PLAYER_STATE_RESOURCE_GOLD, 750)
                call CreateUnit(Player(n), 'H000', -12380, 11486, 0)
                call CreateUnitAtLoc(Player(n), 'H000', GetRectCenter(bj_mapInitialPlayableArea), 0)
            endif
            set n = n + 1
        endloop 
        
        // Add Spell Books to MagicSchool
        // ==============================
        // ==========  EARTH  ==========
        set n = GetRandomInt(1, 3)
        if(n == 1) then
            call AddItemToStock(gg_unit_h006_0001, 'I000', 0, 1)
        elseif(n == 2) then
            call AddItemToStock(gg_unit_h006_0001, 'I00S', 0, 1)
        else
            call AddItemToStock(gg_unit_h006_0001, 'I01Q', 0, 1)
        endif
        
        // ===========  AIR  ===========
        set n = GetRandomInt(1, 2)
        if(n == 1) then
            call AddItemToStock(gg_unit_h006_0001, 'I00M', 0, 1)
        else
            call AddItemToStock(gg_unit_h006_0001, 'I00H', 0, 1)
        endif
        
        // ===========  FIRE  ==========
        set n = GetRandomInt(1, 2)
        if(n == 1) then
            call AddItemToStock(gg_unit_h006_0001, 'I01H', 0, 1)
        else
            call AddItemToStock(gg_unit_h006_0001, 'I01B', 0, 1)
        endif
        
        // ==========  WATER  ==========
        set n = GetRandomInt(1, 3)
        if(n == 1) then
            call AddItemToStock(gg_unit_h006_0001, 'I00B', 0, 1)
        elseif(n == 2) then
            call AddItemToStock(gg_unit_h006_0001, 'I00R', 0, 1)
        else
            call AddItemToStock(gg_unit_h006_0001, 'I01L', 0, 1)
        endif
    endfunction

    //===========================================================================
    private function Init takes nothing returns nothing
        local trigger MapInit = CreateTrigger()
        call TriggerAddAction(MapInit, function Actions)
    endfunction
endscope


essentially, im trying to create the heroes, add a visibility mod and add some items into a building stock

but for now, it wont seem to work at all :( I just converted all my code from jass to vJass, the map saves without any errors but i cannot figure out why this trigger wont run.
When i play the map there are no units created and i have no gold. Would anyone be able to shed some light on this issue?

Also any tips on how my code is would be appreciated, i'm sure ive done some parts the hard way :p
 

quraji

zap
Reaction score
144
It doesn't do anything because you don't actually call the actions functions on init, you just make a trigger with no event. Just either put all that stuff in the Init function, or call the Actions function in the Init function.
 

ZugZugZealot

New Member
Reaction score
33
Like he said, it needs to be change. Going into deeper explanation, here's your options...

Option #1:
Change
JASS:
private function Actions takes nothing returns nothing

To
JASS:
private function Init takes nothing returns nothing

And remove...
JASS:
    //===========================================================================
    private function Init takes nothing returns nothing
        local trigger MapInit = CreateTrigger()
        call TriggerAddAction(MapInit, function Actions)
    endfunction


Option #2:
JASS:
    private function Init takes nothing returns nothing
        local trigger MapInit = CreateTrigger()
        call TriggerAddAction(MapInit, function Actions)
        call TriggerExecute(MapInit) //This will tell it to 'do' "Actions"
    endfunction


Explanation:
In the background of things, there's a main function which is where everything starts... In your case your main function should look similar to this...
JASS:
function main takes nothing returns nothing
    call SetCameraBounds( -3328.0 + GetCameraMargin(CAMERA_MARGIN_LEFT), -3584.0 + GetCameraMargin(CAMERA_MARGIN_BOTTOM), 3328.0 - GetCameraMargin(CAMERA_MARGIN_RIGHT), 3072.0 - GetCameraMargin(CAMERA_MARGIN_TOP), -3328.0 + GetCameraMargin(CAMERA_MARGIN_LEFT), 3072.0 - GetCameraMargin(CAMERA_MARGIN_TOP), 3328.0 - GetCameraMargin(CAMERA_MARGIN_RIGHT), -3584.0 + GetCameraMargin(CAMERA_MARGIN_BOTTOM) )
    call SetDayNightModels( "Environment\\DNC\\DNCLordaeron\\DNCLordaeronTerrain\\DNCLordaeronTerrain.mdl", "Environment\\DNC\\DNCLordaeron\\DNCLordaeronUnit\\DNCLordaeronUnit.mdl" )
    call NewSoundEnvironment( "Default" )
    call SetAmbientDaySound( "LordaeronSummerDay" )
    call SetAmbientNightSound( "LordaeronSummerNight" )
    call SetMapMusic( "Music", true, 0 )
    call CreateRegions(  )
    call CreateAllUnits(  )
    call InitBlizzard(  )

//! initstructs
call ExecuteFunc("MapInit___Init")

//! initdatastructs
    call InitGlobals(  )
    call InitCustomTriggers(  )
    call RunInitializationTriggers(  )

endfunction


When you add a Map Initialize event to a trigger in GUI, World edit will add a call to it in the RunInitializationTriggers function, which let's say...

Make a trigger name "PreplaceUnits" you add "Map Initialization" as an event... The RunInitializationTriggers function will look like this...
JASS:
function RunInitializationTriggers takes nothing returns nothing
    call ConditionalTriggerExecute( gg_trg_PrePlaceUnits )
endfunction

Which calls the actions of that trigger.

Basically scope/library initializers just skip that part and goes right to the function, sparing you from having to deal with trigger creation and executing as well as sparing you additional thread instance(s) in loading.
 

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
oh good explanation indeed! gj
 

mattyspatty

New Member
Reaction score
0
Thanks very much, Works perfectly now!
not only do I know what needs to be done, I think I understand WHY it needs to be done which is vital for good coding.

In the name of consitency I used
JASS:
call TriggerExecute(MapInit)
 

ZugZugZealot

New Member
Reaction score
33
I throw a syntax error into the code and save to bring up pjass.exe so that I can see what vJass and Blizzard/World Edit are doing in the background.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top