Making a trigger run on initialization

LearningCode

New Member
Reaction score
24
I want to make a trigger run once on map initialization, then destroy and null that trigger.

Problem is, when I make a scope that initializes the function that runs the trigger, nothing happens.
I have to use [lJASS]call TriggerRegisterTimerEvent(t, 0.01, false)[/lJASS]
It kinda' annoys me.

Would anyone know the JASS equivalent of "Map Initialization"?
Here's the trigger I have now "In case you guys catch a leak which most likely exists.)

JASS:

scope GameInit initializer GameStart

   private function Visibility takes nothing returns nothing
      local integer i = 0
      local integer d = 0
      local trigger t = GetTriggeringTrigger()
      call SetFloatGameState(GAME_STATE_TIME_OF_DAY, 12.00)
      call SetTimeOfDayScale(0.00 * 0.01)
      call FogEnable(false)
      call FogMaskEnable(false)
      call SetGameSpeed( MAP_SPEED_FASTEST )
      call SetMapFlag(MAP_LOCK_SPEED, true)
      loop
      exitwhen i == 7
         loop
         exitwhen d == 7
            call SetPlayerAlliance(Player(i), Player(d), ALLIANCE_PASSIVE, true)
            call SetPlayerAlliance(Player(i), Player(d), ALLIANCE_SHARED_XP, true)
         set d = d+1
         endloop
      set i = i+1
      endloop
      set i = 0
      loop
      exitwhen i == 7
         call SetPlayerAlliance(Player(11), Player(i), ALLIANCE_PASSIVE,  false)
         call SetPlayerAlliance(Player(i), Player(11), ALLIANCE_PASSIVE,  false)
      set i = i+1
      endloop
      call DisableTrigger(t)
      call DestroyTrigger(t)
      set t = null
   endfunction


private function GameStart takes nothing returns nothing
   local trigger t = CreateTrigger()
   call TriggerRegisterTimerEvent(t, 0.01, false)
   call TriggerAddAction(t, function Visibility)
   set t = null
endfunction

endscope
 

Komaqtion

You can change this now in User CP.
Reaction score
469
There are a couple of stuff you cannot do on Map Initialization (Though can't remember exactly which)...
So maybe that code can't be run on Map Init because of that :eek:
 

tooltiperror

Super Moderator
Reaction score
231
I thought that libraries are run at Init..?

Anyway, you can place scopes within libraries, I thought?
 

LearningCode

New Member
Reaction score
24
Eh...
What the eff.

Not everything needs to have CreateTrigger() xD

I could have just used [lJASS]scope something initializer something[/lJASS] and it would have worked out fine -___-

JASS:
library GameBegin initializer Visibility



   private function Visibility takes nothing returns nothing
      local integer i = 0
      local integer d = 0
      local trigger t = GetTriggeringTrigger()
      call SetFloatGameState(GAME_STATE_TIME_OF_DAY, 12.00)
      call SetTimeOfDayScale(0.00 * 0.01)
      call FogEnable(false)
      call FogMaskEnable(false)
      call SetGameSpeed( MAP_SPEED_FASTEST )
      call SetMapFlag(MAP_LOCK_SPEED, true)
      loop
      exitwhen i == 7
         loop
         exitwhen d == 7
            call SetPlayerAlliance(Player(i), Player(d), ALLIANCE_PASSIVE, true)
            call SetPlayerAlliance(Player(i), Player(d), ALLIANCE_SHARED_XP, true)
         set d = d+1
         endloop
      set i = i+1
      endloop
      set i = 0
      loop
      exitwhen i == 7
         call SetPlayerAlliance(Player(11), Player(i), ALLIANCE_PASSIVE,  false)
         call SetPlayerAlliance(Player(i), Player(11), ALLIANCE_PASSIVE,  false)
      set i = i+1
      endloop
      call DisableTrigger(t)
      call DestroyTrigger(t)
      set t = null
   endfunction


endlibrary


Problem fixed! xD
Thanks, guys
 

Komaqtion

You can change this now in User CP.
Reaction score
469
That is how I thought you did here ! XD :
Problem is, when I make a scope that initializes the function that runs the trigger, nothing happens.
 

LearningCode

New Member
Reaction score
24
@Executor
What did you mean by "In case Visibility contains functions"? o.0
I thought we couldn't next functions within functions xD

I've never heard of "call <FunctionName>.execute() ._.
Are there any other things similar to that that I should know of?

@GetTriggerUnit
Okay, But if I do use Game event, I'll have to destroy the expired timer, right? o.0
 

GetTriggerUnit-

DogEntrepreneur
Reaction score
129
Well Two ways for you. I'd recommend the first one.

JASS:

function A takes nothing returns nothing
   CreateMultiboard(&quot;lady gaga&quot;)
   // etc...
   // I think the timer is destroyed by itself but I wouldn&#039;t bet $100
endfunction

function B takes nothing returns nothing
    call TimerStart(CreateTimer(), 0.00, false, function A)
endfunction


JASS:

function A takes nothing returns nothing
   CreateMultiboard(&quot;lady gaga&quot;)
   // etc...
endfunction

function B takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterTimerEvent(t, 0.00, false)
    call TriggerAddAction(t, function A)
endfunction


I'm pretty sure both of these do the same thing but in different ways.
 

LearningCode

New Member
Reaction score
24
I doubt it'll be destroyed =/

Can I:
1) Use a library to initialize a function (A) that calls a method in a struct
2) Then, the method called allocates whatever thingy, and creates a timer
3) Timer expires and it calls another method (B)
4) That method (B) creates the multiboard xD
5) That same method (B) destroys the struct
6) Use the onDestroy method to Pause/Destroy/null the timer

So long winded =x
 

LearningCode

New Member
Reaction score
24
I am afraid of the leaks xD
I know that a couple of leaks won't kill a map..
But I'm just scared of them

The tutorials I read have all made me fear the leaks
The guys that post on these forums have made me fear the mighty leak
 

GetTriggerUnit-

DogEntrepreneur
Reaction score
129
There are alot of leaks in Jass but most of them are minors.

You should only try to avoid
  • Locations
  • Groups
  • Boolexpr

And, imo, you can make an awesome lagfree map with only avoiding these three types of leak.

/faceplam EDIT: And always null your agents.
 

Sickle

New Member
Reaction score
13
>>And always null your agents.

There are situations where that is unneeded and/or a bad idea.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      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