[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.
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top