- Joined
- Jan 10, 2023
- Messages
- 247
I recently began learning JASS via converting GUI and reading tutorials and I have a question about local triggers
I think it's easiest if I post my example:
SG_Init makes a local trigger and after the other actions it queues SG_InitPlayer
SG_InitPlayer loops to make a 5184 images per player for later use in making various grids for the players
- these triggers were separated because the world editor didn't seem to want to do 5184*12 loops in one trigger
I'm guessing there are many things I can improve, and that's what I'm currently trying to do, but my real question is can I make the SG_InitPlayer a local trigger? It seems like between the two of them, it would be better to have SG_InitPlayer be local because it is much larger
The reason I elected to add the trigger to the queue and didn't just run the trigger is because it seemed to perform better this way, and to my mind it was safer, rather than having the trigger call itself within itself many times, testing which worked better, run or add to queue, they seemed to perform the same, but I think its better to have breaks in the trigger.
(correct me if I'm wrong, but it also seemed to help on another project that makes a much larger loop)
When I change SG_InitPlayer to use 'local trigger t = CreateTrigger()' (and the rest of the InitTrig_SG_InitPlayer function to match), I lose my handle on the trigger it seems and I can't add it to the queue, or maybe it can't be added because it isn't a global trigger... I can't figure it out.
If I were to simply merge the two triggers, the trigger fails because it is too large..
It runs fine if I just don't make it a local trigger, but I thought at the very least this would be a good opportunity for me to learn something about local triggers
(I can't seem to find this specific question anywhere)
To formalize the question:
Can I write this so that SG_InitPlayer is a local trigger that can still be accessed by SG_Init?
I have a feeling that I can't do that (sounds like the word local would imply I can't) so my follow up question would be:
Is there a way I can make SG_InitPlayer a local function of SG_Init without making the trigger too large to work?
I think it's easiest if I post my example:
SG_Init makes a local trigger and after the other actions it queues SG_InitPlayer
SG_InitPlayer loops to make a 5184 images per player for later use in making various grids for the players
- these triggers were separated because the world editor didn't seem to want to do 5184*12 loops in one trigger
I'm guessing there are many things I can improve, and that's what I'm currently trying to do, but my real question is can I make the SG_InitPlayer a local trigger? It seems like between the two of them, it would be better to have SG_InitPlayer be local because it is much larger
The reason I elected to add the trigger to the queue and didn't just run the trigger is because it seemed to perform better this way, and to my mind it was safer, rather than having the trigger call itself within itself many times, testing which worked better, run or add to queue, they seemed to perform the same, but I think its better to have breaks in the trigger.
(correct me if I'm wrong, but it also seemed to help on another project that makes a much larger loop)
When I change SG_InitPlayer to use 'local trigger t = CreateTrigger()' (and the rest of the InitTrig_SG_InitPlayer function to match), I lose my handle on the trigger it seems and I can't add it to the queue, or maybe it can't be added because it isn't a global trigger... I can't figure it out.
If I were to simply merge the two triggers, the trigger fails because it is too large..
It runs fine if I just don't make it a local trigger, but I thought at the very least this would be a good opportunity for me to learn something about local triggers
(I can't seem to find this specific question anywhere)
To formalize the question:
Can I write this so that SG_InitPlayer is a local trigger that can still be accessed by SG_Init?
I have a feeling that I can't do that (sounds like the word local would imply I can't) so my follow up question would be:
Is there a way I can make SG_InitPlayer a local function of SG_Init without making the trigger too large to work?
JASS:
function Trig_SG_Init_Actions takes nothing returns nothing
local integer i = 1
set udg_SG_MaxPlayer = 12
set udg_SG_MaxSize = 72
set udg_SG_MaxRect = ( udg_SG_MaxSize * udg_SG_MaxSize )
call InitHashtableBJ( )
set udg_SG_CycleHash = GetLastCreatedHashtableBJ()
call InitHashtableBJ( )
set udg_SG_ImagesHash = GetLastCreatedHashtableBJ()
set udg_SG_Pos = Location(0, 0)
loop
exitwhen i > udg_SG_MaxPlayer
set udg_SG_PathingRadius[i] = ( udg_SG_MaxSize * 32 )
set i = i + 1
endloop
call TriggerExecute( gg_trg_SG_ColorValues )
call TriggerExecute( gg_trg_SG_ColorNames )
set udg_SG_PlayerIndex = 1
call QueuedTriggerAddBJ( gg_trg_SG_InitPlayer, false )
endfunction
//===========================================================================
function InitTrig_SG_Init takes nothing returns nothing
local trigger t = CreateTrigger( )
call TriggerRegisterTimerEventSingle( t, 0.05 )
call TriggerAddAction( t, function Trig_SG_Init_Actions )
set t = null
endfunction
JASS:
function Trig_SG_InitPlayer_Actions takes nothing returns nothing
local integer i = 0
local integer j = udg_SG_MaxSize
local integer k = udg_SG_MaxRect
local integer l = udg_SG_PlayerIndex
local integer x
local integer y
loop
exitwhen i > k
set x = ( ModuloInteger(i, j) - ( j / 2 ) )
set y = ( ( ( i - ModuloInteger(i, j) ) / j ) - ( j / 2 ) )
call CreateImageBJ( "war3mapImported\\Grid64.blp", 64.00, udg_SG_Pos, 0, 3 )
call SaveImageHandleBJ( GetLastCreatedImage(), i, l, udg_SG_ImagesHash )
call SetImageRenderAlways( LoadImageHandleBJ(i, l, udg_SG_ImagesHash), true )
call ShowImageBJ( false, LoadImageHandleBJ(i, l, udg_SG_ImagesHash) )
set i = i + 1
endloop
set udg_SG_isCycleOn[l] = true
set udg_SG_PlayerIndex = ( udg_SG_PlayerIndex + 1 )
if ( udg_SG_PlayerIndex > udg_SG_MaxPlayer ) then
call RemoveLocation(udg_SG_Pos)
call QueuedTriggerRemoveBJ( GetTriggeringTrigger() )
call StartTimerBJ( udg_SG_PostInializationTimer, false, 0.10 )
else
call QueuedTriggerAddBJ( GetTriggeringTrigger(), false )
call QueuedTriggerRemoveBJ( GetTriggeringTrigger() )
endif
endfunction
//===========================================================================
function InitTrig_SG_InitPlayer takes nothing returns nothing
set gg_trg_SG_InitPlayer = CreateTrigger( )
call TriggerAddAction( gg_trg_SG_InitPlayer, function Trig_SG_InitPlayer_Actions )
endfunction