• 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.

[Solved] spawning trigger efficiency question

Status
Not open for further replies.
hello this is my first attempt to doing jass im using jngp so i just put vjass as the prefix thing. i did this in gui (i only converted things i couldnt find out how to do online) b4 i started to learn jass but i figured since im learning jass i might as well change over my map to 100% jass made i just want to know if there is anything tht i can change to make this more efficient ? thanks for anyone tht helps also i hope i copied it right lol

note: i plan on changing some of the other variables later since i now know about locals and how to use them but since there r a few tht i dont want to change in this or in other triggers

JASS:
\function Trig_Unit_Spawn_Red_all_Lvls_Actions takes nothing returns boolean
    local integer LoopA = 1
    local real rx
    local real ry
    call DisableTrigger( gg_trg_Unit_Spawn_Red_all_Lvls )
    set udg_Damage_Boss_Round_Count_Player[1] = udg_Damage_Boss_Round_Count_Player[1] + 1
    set udg_EnemiesAlive_Counter_Player[1] = udg_Number_Of_Unit_Spawns_Player[1]//#of unit spawns is a selected number of spawns in the game
    set udg_Boss_Bonus_Counter[1] = udg_Boss_Bonus_Counter[1] + 1//used for giving players mana to summon a boss
    set udg_Round_Player[1] = ( udg_Round_Player[1] + 1 )
    call MultiboardSetItemValueBJ( udg_MultiBoard_Game_Scores, 2, 2, I2S(udg_Round_Player[1]) )
    if  ( udg_Round_Player[1] <= 31 ) then
        set udg_Unit_Runner_Red_Spawn = udg_Unit_Runner_Spawn[udg_Round_Player[1]]//unit runner spawn is the array of units to spawn
        //used for setting the next unit to be spawned
    endif
    if  ( udg_Boss_Bonus_Counter[1] == 5 ) then
        set udg_Boss_Add_Mana_Boolean_Player[1] = true
        set udg_Boss_Bonus_Counter[1] = 0
    endif
    
    loop //loops for spawning units into map for player 1 ( i do not use 0 for players gets annoying ) 
        exitwhen LoopA > udg_Number_Of_Unit_Spawns_Player[1] // variable tht allows player to pick # of enemy units per round 
        set rx = GetRectCenterX(gg_rct_red_start)
        set ry = GetRectCenterY(gg_rct_red_start)
        set udg_Unit_Spawns_Red[LoopA] = CreateUnit(Player(11), udg_Unit_Runner_Red_Spawn, rx, ry, 0)
        call SetHeroLevel( udg_Unit_Spawns_Red[LoopA], ( udg_Round_Player[1] - 30 ), false )
        set udg_EnemiesAlive_Player[1] = ( udg_EnemiesAlive_Player[1] + 1 ) //multiboard variable enemies alive
        call MultiboardSetItemValueBJ( udg_MultiBoard_Game_Scores, 2, 6, I2S(udg_EnemiesAlive_Player[1]) )
        call PolledWait( udg_Spawn_Speed_Player[1] )//set the speed between enemy spawns
        set LoopA = LoopA + 1
    endloop
    return false
endfunction

//===========================================================================
function InitTrig_Unit_Spawn_Red_all_Lvls takes nothing returns nothing
    set gg_trg_Unit_Spawn_Red_all_Lvls = CreateTrigger()
    call TriggerRegisterPlayerEvent(gg_trg_Unit_Spawn_Red_all_Lvls, Player(0), EVENT_PLAYER_END_CINEMATIC)
    call TriggerRegisterPlayerChatEvent( gg_trg_Unit_Spawn_Red_all_Lvls, Player(0), ( "-go" ), true )
    call TriggerAddAction( gg_trg_Unit_Spawn_Red_all_Lvls, function Trig_Unit_Spawn_Red_all_Lvls_Actions )
endfunction
 
Last edited:
It is not vJASS

[jass=]function Trig_Unit_Spawn_Red_all_Lvls_Func007C takes nothing returns boolean
if ( not ( udg_Round_Player[1] <= 31 ) ) then
return false
endif
return true
endfunction

function Trig_Unit_Spawn_Red_all_Lvls_Func009C takes nothing returns boolean
if ( not ( udg_Boss_Bonus_Counter[1] == 5 ) ) then
return false
endif
return true
endfunction[/code]
This always return true

Also,this is just converted.

About locals,locals only work for one function but not other functions.
Example
[jass=]
function Func1 takes nothing returns nothing
local real r = 1
endfunction

function Func2 takes nothing returns nothing
call BJDebugMsg(R2S(r))
endfunction
[/code]
This wont work,and will cause syntax error.

If you are going to use locals such as units,groups,destructables,sfx or anything that arent reals,strings,integers,make sure to null them in the end of the code.
 
it wasnt all converted like i said earlier i just started learning jass lol and ok i understand about the locals tht part i didnt know i thought a local could only be changed in the function tht it is made in but ok now i know tht the conditions i converted because i couldnt find out how to do them thanks for pointing tht out i found out how to do tht

note : just started to learn jass 4 hrs ago so i dont know the best way any help to inprove is appreciated
 
Last edited:
Level 23
Joined
Apr 16, 2012
Messages
4,041
its quite hard to rewrite it because of the names and all :D but it seems its not that bad considering that you will want to enable that trigger again after certain time
but it looks like all those array variables only use one index, if that is true and you are not using other indexes in other triggers make them normal variable, it should be a very little bit faster
I thought of chaing this into TriggerCondition, but you are using PolledWait which cant be done in TriggerConditions and also you are using the TriggerSleepAction in the loop which may cause a problems

You also have a point(location) leak in there, just nulling the variable is not enough
as you are doing things in Jass or learning to do, you should stop using locations and start using coordinates(reals)
The way you would do it is:
JASS:
set udg_Temp_Spawn_Red_Reg[1] = GetRectCenter(gg_rct_red_start)
call CreateNUnitsAtLoc( 1, udg_Unit_Runner_Red_Spawn, Player(11), udg_Temp_Spawn_Red_Reg[1], 0 )
set udg_Temp_Spawn_Red_Reg[1] = null // i think this will work ?
set udg_Unit_Spawns_Red[LoopA] = GetLastCreatedUnit()

into

JASS:
local real rx = GetRectCenterX(gg_rct_red_start)
local real ry = GetRectCenterY(gg_rct_red_start)
....
loop
    ....
    set udg_Unit_Spawns_Red[LoopA] = CreateUnit(Player(11), tospawn, rx, ry, 0)

the rx and ry are local variables but you can change that to anyting as long as you have declared it, the rx and ry should be declared and initialized outside of the loop because it is another useless call to function in loop when it returns all the time the same value
Also, instead of using scalar region, you can just get the coordiantes and use them because this takes a lot longer to proceed then just having to set a value
Also using bJass(Jass2, Blizzard Jass) is not very efficient but as Im too lazy for me the MultiboardSetItemValueBJ is fine, the TriggerRegisterPlayerEventEndCinematic and CreateNUnitsAtLoc should be rewrote.
This is how far I got before realising its hard to rewrite because of the Polled Wait
JASS:
function Trig_Unit_Spawn_Red_all_Lvls_Actions takes nothing returns boolean
    local integer loopA = 1
    local integer numOf = udg_Number_Of_Unit_Spawns_Player[1]
    local integer tospawn = 0
    local real spawnnext = udg_Spawn_Speed_Player[1]
    set udg_Round_Player[1] = ( udg_Round_Player[1] + 1 )
    set udg_Damage_Boss_Round_Count_Player[1] = udg_Damage_Boss_Round_Count_Player[1] + 1
    set udg_Boss_Bonus_Counter[1] = udg_Boss_Bonus_Counter[1] + 1
    call DisableTrigger( GetTriggeringTrigger() )
    call MultiboardSetItemValueBJ( udg_MultiBoard_Game_Scores, 2, 2, I2S(roundPl) )
    if  ( roundPl <= 31 ) then
        set tospawn = udg_Unit_Runner_Spawn[udg_Round_Player[1]]
        //used for setting the next unit to be spawned
    endif
    //used for giving players mana to summon a boss
    if  ( udg_Boss_Bonus_Counter[1] == 5 ) then
        set udg_Boss_Add_Mana_Boolean_Player[1] = true
        set udg_Boss_Bonus_Counter[1] = 0
    endif
    
    loop //loops for spawning units into map for player 1 ( i do not use 0 for players gets annoying ) 
        exitwhen loopA > numOf // variable tht allows player to pick # of enemy units per round 
        set rx = GetRectCenterX(gg_rct_red_start)
        set ry = GetRectCenterY(gg_rct_red_start)
        set udg_Unit_Spawns_Red[LoopA] = CreateUnit(Player(11), tospawn, rx, ry, 0)
        call SetHeroLevel( udg_Unit_Spawns_Red[LoopA], ( udg_Round_Player[1] - 30 ), false )
        set udg_EnemiesAlive_Player[1] = ( udg_EnemiesAlive_Player[1] + 1 ) //multiboard variable enemies alive
        call MultiboardSetItemValueBJ( udg_MultiBoard_Game_Scores, 2, 6, I2S(udg_EnemiesAlive_Player[1]) )
        set LoopA = LoopA + 1
    endloop
    return false
endfunction

//===========================================================================
function InitTrig_Unit_Spawn_Red_all_Lvls takes nothing returns nothing
    set gg_trg_Unit_Spawn_Red_all_Lvls = CreateTrigger()
    call TriggerRegisterPlayerEvent(gg_trg_Unit_Spawn_Red_all_Lvls, Player(0), EVENT_PLAYER_END_CINEMATIC)
    call TriggerRegisterPlayerChatEvent( gg_trg_Unit_Spawn_Red_all_Lvls, Player(0), ( "-go" ), true )
    call TriggerAddAction( gg_trg_Unit_Spawn_Red_all_Lvls, function Trig_Unit_Spawn_Red_all_Lvls_Actions )
endfunction
(notice the polled wait is no longer there)
Also, the
JASS:
        set udg_Unit_Runner_Red_Spawn = udg_Unit_Runner_Spawn[udg_Round_Player[1]]//unit runner spawn is the array of units to spawn
        //used for setting the next unit to be spawned
will even work? afaik its trying to convert unit into integer(udg_Unit_Runner_Red_Spawn is later used as unitId which is integer)
 
ok i see what u did some of the variables i need the arrays but i can change them back i used the arrays for the different players to keep the info easy for me to remember and read thx a lot tho im pretty sure i understand everything in it only thing i dont know is what happened to the wait ? what will act as the wait tht i had there ? and what does the spawn next refer to ?

JASS:
set udg_Unit_Runner_Red_Spawn = udg_Unit_Runner_Spawn[udg_Round_Player[1]]//unit runner spawn is the array of units to spawn
        //used for setting the next unit to be spawned

unit runner red spawn is a unit tht is not an array/ unit runner spawn is an array tht has preset units from array 1 to 31 and the round player one sets which array is selected so the units change from lvl to lvl
 
Status
Not open for further replies.
Top