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

[JASS] Eerrmm.. counting problem?

Status
Not open for further replies.
Level 5
Joined
Feb 22, 2013
Messages
161
JASS:
function SpawnLoop takes nothing returns nothing
    local timer spawnInterval = GetExpiredTimer()
    local integer i = GetRandomInt(1, 4)
    local real x1 = GetRandomReal(GetRectMinX(gg_rct_corruptSpawn1), GetRectMaxX(gg_rct_corruptSpawn1))
    local real y1 = GetRandomReal(GetRectMinY(gg_rct_corruptSpawn1), GetRectMaxY(gg_rct_corruptSpawn1))
    local real x2 = GetRandomReal(GetRectMinX(gg_rct_corruptSpawn2), GetRectMaxX(gg_rct_corruptSpawn2))
    local real y2 = GetRandomReal(GetRectMinY(gg_rct_corruptSpawn2), GetRectMaxY(gg_rct_corruptSpawn2))
    local real x3 = GetRandomReal(GetRectMinX(gg_rct_corruptSpawn3), GetRectMaxX(gg_rct_corruptSpawn3))
    local real y3 = GetRandomReal(GetRectMinY(gg_rct_corruptSpawn3), GetRectMaxY(gg_rct_corruptSpawn3))
    local real x4 = GetRandomReal(GetRectMinX(gg_rct_corruptSpawn4), GetRectMaxX(gg_rct_corruptSpawn4))
    local real y4 = GetRandomReal(GetRectMinY(gg_rct_corruptSpawn4), GetRectMaxY(gg_rct_corruptSpawn4))
    
    if LoadInteger(udg_spawnerHash, 1, GetHandleId(spawnInterval)) == 29 then
        call PauseTimer(spawnInterval)
        call DestroyTimer(spawnInterval)
        set spawnInterval = null
        return
    endif
    if i == 1 then
        call CreateUnit(Player(10), udg_monsterType[udg_Round], x1, y1, 270.00)
        call DisplayTimedTextToPlayer(Player(2), 0, 0, 0., "Unit created, North side. " + I2S(LoadInteger(udg_spawnerHash, 1, GetHandleId(spawnInterval))))
    endif
    
    if i == 2 then
        call CreateUnit(Player(10), udg_monsterType[udg_Round], x2, y2, 270.00)
        call DisplayTimedTextToPlayer(Player(2), 0, 0, 0., "Unit created, East side. " + I2S(LoadInteger(udg_spawnerHash, 1, GetHandleId(spawnInterval))))
    endif
    
    if i == 3 then
        call CreateUnit(Player(10), udg_monsterType[udg_Round], x3, y3, 270.00)
        call DisplayTimedTextToPlayer(Player(2), 0, 0, 0., "Unit created, South side. " + I2S(LoadInteger(udg_spawnerHash, 1, GetHandleId(spawnInterval))))
    endif
    
    if i == 4 then
        call CreateUnit(Player(10), udg_monsterType[udg_Round], x4, y4, 270.00)
        call DisplayTimedTextToPlayer(Player(2), 0, 0, 0., "Unit created, West side. " + I2S(LoadInteger(udg_spawnerHash, 1, GetHandleId(spawnInterval))))
    endif
    
    call SaveInteger(udg_spawnerHash, 1, GetHandleId(spawnInterval), LoadInteger(udg_spawnerHash, 1, GetHandleId(spawnInterval)) + 1)
    set spawnInterval = null
endfunction

function Trig_Spawn1_Actions takes nothing returns nothing
    local timer spawnInterval = CreateTimer()
    local integer index = 0
    
    call BJDebugMsg("Spawn1 running.")
    call SaveInteger(udg_spawnerHash, 1, GetHandleId(spawnInterval), index)
    call TimerStart(spawnInterval, 1.00, true, function SpawnLoop)
    set spawnInterval = null
endfunction

//===========================================================================
function InitTrig_Spawn1 takes nothing returns nothing
    set gg_trg_Spawn1 = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Spawn1, function Trig_Spawn1_Actions )
endfunction

So in this script I have here it loops every second and creates a unit and stops at 29, it counts fine up to 29 and everything, but in the DisplayTimedTextToPlayer function, it says it stops counting at 28 but I counted 29 units on the map so that's how I know it works.. So why does it display 28 as the final integer count?
 
it is because of were ur saving the integer. its at the bottom of the trigger

when u have this at the top of ur trigger it is fired when its 29 but never gets to save the integer after this
JASS:
if LoadInteger(udg_spawnerHash, 1, GetHandleId(spawnInterval)) == 29 then
        call PauseTimer(spawnInterval)
        call DestroyTimer(spawnInterval)
        set spawnInterval = null
        return
    endif
the return stops all actions from running after this.
so if u display the message that counts after this ITE it wont be displayed
 
display the message were i put the notations. notice how the first one will be displayed but not the second on the 29th time.

JASS:
function SpawnLoop takes nothing returns nothing
    local timer spawnInterval = GetExpiredTimer()
    local integer i = GetRandomInt(1, 4)
    local real x1 = GetRandomReal(GetRectMinX(gg_rct_corruptSpawn1), GetRectMaxX(gg_rct_corruptSpawn1))
    local real y1 = GetRandomReal(GetRectMinY(gg_rct_corruptSpawn1), GetRectMaxY(gg_rct_corruptSpawn1))
    local real x2 = GetRandomReal(GetRectMinX(gg_rct_corruptSpawn2), GetRectMaxX(gg_rct_corruptSpawn2))
    local real y2 = GetRandomReal(GetRectMinY(gg_rct_corruptSpawn2), GetRectMaxY(gg_rct_corruptSpawn2))
    local real x3 = GetRandomReal(GetRectMinX(gg_rct_corruptSpawn3), GetRectMaxX(gg_rct_corruptSpawn3))
    local real y3 = GetRandomReal(GetRectMinY(gg_rct_corruptSpawn3), GetRectMaxY(gg_rct_corruptSpawn3))
    local real x4 = GetRandomReal(GetRectMinX(gg_rct_corruptSpawn4), GetRectMaxX(gg_rct_corruptSpawn4))
    local real y4 = GetRandomReal(GetRectMinY(gg_rct_corruptSpawn4), GetRectMaxY(gg_rct_corruptSpawn4))
    
    //display first integer here.

    if LoadInteger(udg_spawnerHash, 1, GetHandleId(spawnInterval)) == 29 then
        call PauseTimer(spawnInterval)
        call DestroyTimer(spawnInterval)
        set spawnInterval = null
        return
    endif
    if i == 1 then
        call CreateUnit(Player(10), udg_monsterType[udg_Round], x1, y1, 270.00)
        call DisplayTimedTextToPlayer(Player(2), 0, 0, 0., "Unit created, North side. " + I2S(LoadInteger(udg_spawnerHash, 1, GetHandleId(spawnInterval))))
    endif
    
    if i == 2 then
        call CreateUnit(Player(10), udg_monsterType[udg_Round], x2, y2, 270.00)
        call DisplayTimedTextToPlayer(Player(2), 0, 0, 0., "Unit created, East side. " + I2S(LoadInteger(udg_spawnerHash, 1, GetHandleId(spawnInterval))))
    endif
    
    if i == 3 then
        call CreateUnit(Player(10), udg_monsterType[udg_Round], x3, y3, 270.00)
        call DisplayTimedTextToPlayer(Player(2), 0, 0, 0., "Unit created, South side. " + I2S(LoadInteger(udg_spawnerHash, 1, GetHandleId(spawnInterval))))
    endif
    
    if i == 4 then
        call CreateUnit(Player(10), udg_monsterType[udg_Round], x4, y4, 270.00)
        call DisplayTimedTextToPlayer(Player(2), 0, 0, 0., "Unit created, West side. " + I2S(LoadInteger(udg_spawnerHash, 1, GetHandleId(spawnInterval))))
    endif
    
    call SaveInteger(udg_spawnerHash, 1, GetHandleId(spawnInterval), LoadInteger(udg_spawnerHash, 1, GetHandleId(spawnInterval)) + 1)
    
    //display second integer here. this will not be displayed on the 29th time. the other one will

    set spawnInterval = null
endfunction

function Trig_Spawn1_Actions takes nothing returns nothing
    local timer spawnInterval = CreateTimer()
    local integer index = 0
    
    call BJDebugMsg("Spawn1 running.")
    call SaveInteger(udg_spawnerHash, 1, GetHandleId(spawnInterval), index)
    call TimerStart(spawnInterval, 1.00, true, function SpawnLoop)
    set spawnInterval = null
endfunction

//===========================================================================
function InitTrig_Spawn1 takes nothing returns nothing
    set gg_trg_Spawn1 = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Spawn1, function Trig_Spawn1_Actions )
endfunction
 
Status
Not open for further replies.
Top