• 🏆 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] Timer doesn't expire as determined

Status
Not open for further replies.
Level 13
Joined
Mar 29, 2012
Messages
530
I start a timer but it doesn't expire as i determined... It's supposed to expire every 0.03125 seconds. The debug message inside the periodic function shows every 2 seconds (perhaps)

JASS:
//***************************************************************************
//*    Critical Combo
//*
//*  Created by: Ofel
//*  Version: 1.0
//*
//* =========================================================================
//*  
//*   Credits :
//*  - 
//*
//* =========================================================================
//*
//*   Changelog :
//*  - v1.0: Initial version.
//*
//***************************************************************************

//***************************************************************************
//*
//*  Configuration
//*
//***************************************************************************

constant function CC_AbilityID takes nothing returns integer
    return 'A000'
endfunction

constant function CC_OrderID takes nothing returns string
    return "banish"
endfunction

constant function CC_DummyID takes nothing returns integer
    return 'u000'
endfunction

constant function CC_Interval takes nothing returns real
    return 0.03125
endfunction

constant function CC_SplatBlood takes nothing returns boolean
    return true
endfunction

constant function CC_BloodModel takes nothing returns string
    return ""
endfunction

constant function CC_BloodPerSlash takes nothing returns integer
    return 2
endfunction

constant function CC_BloodSplatMaxDistance takes nothing returns real
    return 400.00
endfunction

constant function CC_BloodSplatMinDistance takes nothing returns real
    return 100.00
endfunction

constant function CC_BloodSplatMaxSpeed takes nothing returns real
    return 40.00
endfunction

constant function CC_BloodSplatMinSpeed takes nothing returns real
    return 20.00
endfunction

constant function CC_SlashAnimation takes nothing returns string
    return "attack"
endfunction

constant function CC_SlashAnimationSpeed takes nothing returns real
    return 300.00
endfunction

constant function CC_SlashInterval takes nothing returns real
    return 0.20
endfunction

constant function CC_SlashDistance takes nothing returns real
    return 100.00
endfunction

constant function CC_SlashTargetEffect takes nothing returns string
    return ""
endfunction

constant function CC_RunAnimationIndex takes nothing returns integer
    return 6
endfunction

constant function CC_RunGroundEffect takes nothing returns string
    return ""
endfunction

function CC_SlashNumber takes integer level returns integer
    return level * 5 + 15
endfunction

//***************************************************************************
//*
//*  End of Configuration
//*
//***************************************************************************

constant function CC_NewSlashDistance takes nothing returns real
    return CC_SlashDistance() * CC_SlashDistance()
endfunction

function CC_IsUnitAlive takes unit u returns boolean
    return not( GetUnitTypeId(u) == null and IsUnitType(u, UNIT_TYPE_DEAD) and u == null )
endfunction

//***************************************************************************
//*
//*  Periodic Function
//*
//***************************************************************************

function CC_Periodic takes nothing returns nothing
    local integer index = udg_CC_Next[0]
    local real x
    local real y
    local real x2
    local real y2
    local real x3
    local real y3
    local real dist
    local real angle
    loop
        exitwhen index == 0
        call DebugInt("index", index)
        if (udg_CC_Stage[index] == 1) then
            
        elseif (udg_CC_Stage[index] == 2) then
            if (CC_IsUnitAlive(udg_CC_Caster[index]) and CC_IsUnitAlive(udg_CC_Target[index]) and GetUnitCurrentOrder(udg_CC_Caster[index]) == udg_CC_OrderID and udg_CC_Slashed[index] > 0) then
                set x = GetUnitX(udg_CC_Caster[index])
                set y = GetUnitY(udg_CC_Caster[index])
                set x2 = GetUnitX(udg_CC_Target[index])
                set y2 = GetUnitY(udg_CC_Target[index])
                set x3 = x2 - x
                set y3 = y2 - y
                set dist = (x3) * (x3) + (y3) * (y3)
                if (dist > CC_NewSlashDistance()) then
                    
                else
                    
                endif
            else
                
            endif
        elseif (udg_CC_Stage[index] == 3) then
            set udg_CC_Recycle[index] = udg_CC_Recycle[0]
            set udg_CC_Recycle[0] = index
            set udg_CC_Prev[udg_CC_Next[index]] = udg_CC_Prev[index]
            set udg_CC_Next[udg_CC_Prev[index]] = udg_CC_Next[index]
            set udg_CC_ActiveInstance = udg_CC_ActiveInstance - 1
            if (udg_CC_ActiveInstance == 0) then
                call PauseTimer(udg_CC_Timer)
            endif
        endif
        set index = udg_CC_Next[index]
    endloop
endfunction

//***************************************************************************
//*
//*  Starter Function
//*
//***************************************************************************

function CC_Cast takes nothing returns boolean
    local integer index
    local real x
    local real y
    if (GetSpellAbilityId() == CC_AbilityID()) then
        set index = udg_CC_Recycle[0]
        if (index == 0) then
            set udg_CC_InstanceCount = udg_CC_InstanceCount + 1
            set index = udg_CC_InstanceCount
        else
            set udg_CC_Recycle[0] = udg_CC_Recycle[index]
        endif
        set udg_CC_Next[index] = 0
        set udg_CC_Prev[index] = udg_CC_Prev[0]
        set udg_CC_Next[udg_CC_Prev[0]] = index
        set udg_CC_Prev[0] = index
        set udg_CC_Caster[index] = GetTriggerUnit()
        set udg_CC_Owner[index] = GetTriggerPlayer()
        set udg_CC_Target[index] = GetSpellTargetUnit()
        set udg_CC_Level[index] = GetUnitAbilityLevel(udg_CC_Caster[index], CC_AbilityID())
        set udg_CC_Slashed[index] = CC_SlashNumber(udg_CC_Level[index])
        set udg_CC_Stage[index] = 2
        set udg_CC_ActiveInstance = udg_CC_ActiveInstance + 1
        if (udg_CC_ActiveInstance == 1) then
            call TimerStart(udg_CC_Timer, CC_Interval, true, function CC_Periodic)
        endif
    endif
    return false
endfunction

//***************************************************************************
//*
//*  Initializer Function
//*
//***************************************************************************

function InitTrig_Critical_Combo takes nothing returns nothing
    if (udg_CC_Timer == null) then
        set udg_CC_Timer = CreateTimer()
    endif
    set udg_CC_OrderID = OrderId(CC_OrderID())
    set gg_trg_Critical_Combo = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Critical_Combo, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(gg_trg_Critical_Combo, Filter(function CC_Cast))
endfunction

JASS:
function DebugInt takes string msg, integer i returns nothing
    call DisplayTimedTextToPlayer(Player(0), 0, 0, 1000000, msg + " = " + I2S(i))
endfunction

+Rep for help...:ogre_icwydt:
Feel free to give suggestion too...
 
Level 16
Joined
Dec 15, 2011
Messages
1,423
call TriggerAddCondition(gg_trg_Critical_Combo, Filter(function CC_Cast))

This line seems really iffy. Why is it not Condition() but Filter()?

Filter(code c) returns a filterfunc, which I believe is different from a conditionfunc returned from Condition(code c). I reckon that this is your problem.
 
Implementing linked lists through vanilla JASS globals is an abomination unto the eyes. :(

Put a DebugInt right above the "loop" function. If it appears every 0.03125 seconds, then that means that the timer is fine, but the loop is exiting prematurely because next[0] is equaling 0 (which may indicate a problem with your linking).

@Doomlord: Both filterfunc and conditionfunc extend boolexpr, and they are allowed to be used interchangeably. :) (they don't do type checks on them) So it should work just fine.
 
Level 16
Joined
Dec 15, 2011
Messages
1,423
Implementing linked lists through vanilla JASS globals is an abomination unto the eyes. :(

Put a DebugInt right above the "loop" function. If it appears every 0.03125 seconds, then that means that the timer is fine, but the loop is exiting prematurely because next[0] is equaling 0 (which may indicate a problem with your linking).

@Doomlord: Both filterfunc and conditionfunc extend boolexpr, and they are allowed to be used interchangeably. :) (they don't do type checks on them) So it should work just fine.

Ah right. Thank you very much for the clarification :)
 
Level 13
Joined
Mar 29, 2012
Messages
530
Implementing linked lists through vanilla JASS globals is an abomination unto the eyes. :(

Put a DebugInt right above the "loop" function. If it appears every 0.03125 seconds, then that means that the timer is fine, but the loop is exiting prematurely because next[0] is equaling 0 (which may indicate a problem with your linking).

It still doesn't appears every 0.03125 :(
and it appears index = 1 not 0 :vw_death: confused...:vw_unimpressed:

Should i use indexed array instead?
 
Level 18
Joined
Sep 14, 2012
Messages
3,413
Suggestion :
JASS:
function InitTrig_Critical_Combo takes nothing returns nothing
    if (udg_CC_Timer == null) then
        set udg_CC_Timer = CreateTimer()
    endif
    set udg_CC_OrderID = OrderId(CC_OrderID())
    set gg_trg_Critical_Combo = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Critical_Combo, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(gg_trg_Critical_Combo, Filter(function CC_Cast))
endfunction
-->
JASS:
function InitTrig_Critical_Combo takes nothing returns nothing
    if (udg_CC_Timer == null) then
        set udg_CC_Timer = CreateTimer()
    endif
    set udg_CC_OrderID = OrderId(CC_OrderID())
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t, Filter(function CC_Cast))
    set t = null
endfunction

Except if you want this trigger to be turn on/off
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
JASS:
function InitTrig_Critical_Combo takes nothing returns nothing
    if (udg_CC_Timer == null) then
        set udg_CC_Timer = CreateTimer()
    endif
    set udg_CC_OrderID = OrderId(CC_OrderID())
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t, Filter(function CC_Cast))
    set t = null
endfunction
Syntax error. Local variables must be declared before anything else.
JASS:
function InitTrig_Critical_Combo takes nothing returns nothing
    local trigger t = CreateTrigger()
    if (udg_CC_Timer == null) then
        set udg_CC_Timer = CreateTimer()
    endif
    set udg_CC_OrderID = OrderId(CC_OrderID())
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t, Filter(function CC_Cast))
    set t = null
endfunction
 
Status
Not open for further replies.
Top