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

[Trigger] Game Time

Status
Not open for further replies.
Level 9
Joined
Jun 7, 2008
Messages
440
I was searching for anything to a related ingame timer. I couldnt find anything. What i want to be done is this:
  • Events
    • Player - player x (color) types -time as an exact match
  • Conditions
  • Actions
    • Game - Display to triggering player the message Elapsed game time is: + {this is where im stuck}
Do i need to put in a variable or is there another way to measure elapsed game time? <i don't need a countdown timer, quite the opposite>
 
Level 1
Joined
Dec 18, 2006
Messages
4
As it stands this requires JassHelper; which comes with JNGP.

JASS:
library GameTime initializer Init

    globals
        private timer Timer = CreateTimer()
        private integer Hrs = 0
        private integer Min = 0
        private integer Sec = 0
    endglobals
    
    private function Callback takes nothing returns nothing
        set Sec = Sec+1
        if Sec == 60 then
            set Sec = 0
            set Min = Min+1
        endif
        if Min == 60 then
            set Min = 0
            set Hrs = Hrs+1
        endif
    endfunction

    private function Init takes nothing returns nothing
        call TimerStart(Timer, 1., true, function Callback)
    endfunction
    
    public function Get takes nothing returns string
        local string s
        if Hrs < 10 then
            set s = "0"+I2S(Hrs)+":"
        else
            set s = I2S(Hrs)+":"
        endif
        if Min < 10 then
            set s = s+"0"+I2S(Min)+":"
        else
            set s = s+I2S(Min)+":"
        endif
        if Sec < 10 then
            set s = s+"0"+I2S(Sec)
        else
            set s = s+I2S(Sec)
        endif
        return s
    endfunction

endlibrary

  • Melee Initialization
    • Events
      • Player - Player 1 (Red) types a chat message containing -time as An exact match
    • Conditions
    • Actions
      • Custom script: call DisplayTextToPlayer(GetTriggerPlayer(), 0., 0., "Elapsed game time is: "+GameTime_Get())
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
As it stands this requires JassHelper; which comes with JNGP.

Hmm... the thread is about GUI. You did it in Jass and that is vJass ;)

Attached to the post is a GUI solution.
Though it can be done even simpler, this way it will work as long as needed, is very customizable and is even more efficient than the jass script above(because in the code above the timer runs once a second calling a function every second putting some stress on the CPU, rather insignificant, but more than if the timer ran for long times and then you checked how much time has passed) .

P.s.
The function
JASS:
    private function Callback takes nothing returns nothing
        set Sec = Sec+1
        if Sec == 60 then
            set Sec = 0
            set Min = Min+1
        endif
        if Min == 60 then
            set Min = 0
            set Hrs = Hrs+1
        endif
    endfunction

can be improved a bit by doing this:
JASS:
    private function Callback takes nothing returns nothing
        set Sec = Sec+1
        if Sec == 60 then
            set Sec = 0
            set Min = Min+1
            if Min == 60 then
                set Min = 0
                set Hrs = Hrs+1
            endif
        endif
    endfunction
Which will decrease the number of comparisons by 59 per minute reducing CPU stress slightly.
 

Attachments

  • Time.w3x
    12.8 KB · Views: 64
Last edited:
Level 9
Joined
Jun 7, 2008
Messages
440
Since im a beginner in JASS, i thank you very much for helping me in that aspect, as well as doing it in GUI. However, i do have a question : what does the very top statement mean
Code:
library GameTime initializer Init
Is that the title of the trigger? If so, why library?
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
There are plenty of tutorials for vJass. There are some in the tutorials section(most are about structs).
There is the JassHelper Manuel. It goes along with the Jass New Gen Pack
Jass New Gen Pack (JNGP or New Gen) is a must for anyone who wants to "trigger" with vJass and not only for them.
 
Status
Not open for further replies.
Top