• 🏆 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!

[vJASS] Could use some frequent coaching. Especially in dealing with timers.

Status
Not open for further replies.
Level 19
Joined
Oct 12, 2007
Messages
1,821
Hey there.

I'm working on my own strategic board game (check my youtube link in signature). It's turning out to become pretty interesting, but I'm stuck with a few basic systems.
I know how to work leakless and avoid BJ's and all, but there are a few things I'm just not efficient at in vJASS.
One of those things is using timers.

This is what I'm trying to create, but I don't know where to start or how to build it up from the start:

- Whenever my unit uses an ability the effect triggers. (that's simple)
- The effect puts a group of 'attacking units' in a group I created with GroupUtils. And it also puts a group of 'defending units' in an other group.
- Now every unit will get to attack, but the order in which they defend depends on a few factors; Units in attack group with ability 'First Strike' go first. Units in defend group with 'First Strike' go second. Units in attack group without that ability go third, and last will be the defending units without First Strike. Let's say 4 units in attack group have First Strike, then the order in which they are being put will be random.
- So now I should have some kind of a list (i used a unit variable for this called AttackingUnit with if 'i' is 1 that will be the first unit attacking, and with i = 17 that unit being #17 to attack)
- Now this was the calculating and now the timer should come into play (i guess) because every unit attacking will be paused and play its attack animation (while I also calculate damage etc via an other trigger I already have). It's just that I want every unit to attack in order and not at the same time, so there should be some kind of a 'wait' after every attacking unit to let the 2nd unit start attacking whenever the 1st one is done.

Especially this last part seems to be tricky for me, and I don't really know how I should build something up like this.


Also in general I might be needing help more often with realising this map of mine. I've got a good amount of stuff ready. There are just some things lacking at the moment where I might need help with.
 
Level 19
Joined
Mar 18, 2012
Messages
1,716
For your last problem, you could use something like this.
It's just a template, not written for cnp.

JASS:
    integer current = 0
    integer counter = 0
    Table stack
    
    private function Callback takes nothing returns nothing
        if UnitAlive(stack.unit[current] then       
            call SetUnitAnimation(stack.unit[current], "attack")
        endif
        set current = current + 1
        
        if current == counter then
            //call ReleaseTimer(GetExpiredTimer())
            call stack.flush()
            call PauseTimer(GetExpiredTimer())
        endif
    endfunction

    private function AddToStack takes nothing returns nothing
        set counter = 0
        set current = 0
        loop
            set unit = FirstOfGroup(group)
            exitwhen unit == null
            call GroupRemoveUnit(group, unit)
            set stack.unit[counter] = unit
            set counter = counter + 1
        endloop
        
        call TimerStart(timer, timeout, true, Callback)
    endfunction
 
Level 19
Joined
Oct 12, 2007
Messages
1,821
Alright thanks both.
I'll send you a message soon Xonok.
And BPower, I'll check that out and start experimenting a bit with it. I've never understood Tables and the powers of it. I've C&Pasted some of them and edited it a bit, but never succeeded in creating a correct one from scratch.
 
Status
Not open for further replies.
Top