• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Timers in functions

Status
Not open for further replies.
Level 3
Joined
Dec 27, 2008
Messages
56
JASS:
function SE takes string SpecialEffect, location Loc, real Duration returns nothing
local effect Effect = AddSpecialEffectLoc(SpecialEffect,Loc)

call PolledWait(Duration)
//I need something instead of PolledWait, because it uses TriggerSleepAction
call RemoveLocation(Loc)
  
set Effect=null
endfunction
I need something instead of PolledWait, because it uses TriggerSleepAction and the trigger shouldn't sleep.
 
Level 3
Joined
Dec 27, 2008
Messages
56
Now it works, i need that vJass function² but I can't write vJass.
So i also can't understand it.
Isn't there and timer which works instead of PolledWait or TriggerSleppAction?
 
Level 3
Joined
Dec 27, 2008
Messages
56
JASS:
function Wait takes nothing returns nothing
 call DisplayTextToForce(GetPlayersAll(),"A")
 // Wait for 5 seconds
 call DisplayTextToForce(GetPlayersAll(),"B")
endfunction

function Trigger takes nothing returns nothing
 local trigger t=CreateTrigger() //that rigger shouldn't sleep
 call TriggerRegisterPlayerChatEvent(t,Player(0),"-go",true)
 call TriggerAddAction(t,function Wait)
endfunction

Something like this:
Player(0) chats -go
A gets displayed
5 seconds later
B gets displayed
trigger t musn't slepp!!
 
Level 14
Joined
Nov 18, 2007
Messages
816
JASS:
library Trigger initializer Init uses TimerUtils

    // You could also replace DisplayTextToForce(GetPlayersAll() with DisplayTextToPlayer(GetLocalPlayer(), 0,0

    private function Wait2 takes nothing returns nothing
        call DisplayTextToForce(GetPlayersAll(),"B")
        call ReleaseTimer(GetExpiredTimer())
    endfunction
    
    private function Wait1 takes nothing returns nothing
        call DisplayTextToForce(GetPlayersAll(),"A")
        call TimerStart(NewTimer(), 5, false, function Wait2)
    endfunction

    private function Init takes nothing returns nothing
    local trigger t=CreateTrigger() //that rigger shouldn't sleep
        call TriggerRegisterPlayerChatEvent(t,Player(0),"-go",true)
        call TriggerAddAction(t,function Wait1)
    endfunction
    
endlibrary
 
Level 4
Joined
Jun 8, 2007
Messages
89
Exactly what Deaod has posted. Simply have a second function, called by a timer event that started in your first function. You also might want to consider making the timer variable global so that you can destroy it after displaying the second set of text.
 
Level 4
Joined
Jun 8, 2007
Messages
89
But my function has abot 10 locals and i want to keep them.
Can't i keep my locals?

Sadly, you will need to move over to a second function in order to have this wait work. As Deaod said, you can save your variables into locals (private locals probably, and just treat them as if they were the locals you wanted to save).
 
Level 3
Joined
Dec 27, 2008
Messages
56
Can I use function or do I have to use methods in structs?
And when i have to use methods, how to activate them(call ....)
 
Level 4
Joined
Jun 8, 2007
Messages
89
Can I use function or do I have to use methods in structs?
And when i have to use methods, how to activate them(call ....)

I don't know whether or not you can use timers to call methods at all, but using a function should work just fine, here is an example:

JASS:
scope SomeScope initializer Init

globals
    timer MessageTimer

    // place the locals you want to carry over to the second function here as globals
endglobals

function Message2 takes nothing returns nothing
    call DisplayTextToPlayer(Player, Message2)
    
    call DestroyTimer(MessageTimer)
endfunction

function OriginalActions takes nothing returns nothing
    // do whatever this is supposed to do
    call DisplayTextToPlayer(Player, Message1)
    // now here is where you set your timer for the second message function
    call TimerStart(MessageTimer, <Timer Duration>, false, function Message2)
endfunction

// ------------------------------

private function Init takes nothing returns nothing
    // setup your trigger events, etc.
endfunction

endscope

EDIT: I hope this helps, if you need any clarifying, just ask.
 
Level 4
Joined
Jun 8, 2007
Messages
89
Hm, but i can simply call everywhere my scope function, can't I?

As long as you don't make the function private, you should be able to call it from anywhere; however, if you do make it private, then you can only call it from within the scope.

What brings a scope?

I'm not really sure what you are trying to ask here. A scope is simply a way of separating out code and making access restrictions. For example, setting something as private inside of a scope makes it so that only that scope can call said function. It works the same way with variables, and things like that.
 

Cokemonkey11

Spell Reviewer
Level 29
Joined
May 9, 2006
Messages
3,531
Another vjass type, it functions as a variable allowing you to pass multiple variables through a function with one line

So let's say I make a struct that contains 5 properties of a unit, and every time I call a function for that unit I need to pass those 5 variables.

Instead, I can simply pass the struct.

It's of course a little more complicated than that.
 
Status
Not open for further replies.
Top