• 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] Making a units periodicaly at an location

Status
Not open for further replies.
Level 2
Joined
Jul 23, 2007
Messages
15
JASS:
function Create_Units_NightElf takes nothing returns nothing
    call CreateUnitAtLoc(Player(0), 4, GetRectCenter(Top_Right_Spawn), "earc")//"earc" is the raw object data for Archer in WC3
endfunction

function Create_Units_Top_Left takes nothing returns nothing
    call TriggerRegisterTimerEventPeriodic(Create_Units_Top_Left, 30.00)
    call TriggerAddAction(trigger(Create_Units_Top_Left), function Create_Units_NightElf)
endfunction

I keep getting errors on undeclared variables and cannot convert string to real.
Please help.
 
Last edited:
Level 14
Joined
Nov 18, 2007
Messages
816
JASS:
function Create_Units_NightElf takes nothing returns nothing
    call CreateUnitAtLoc(Player(0), 4, GetRectCenter(Top_Right_Spawn), "earc")//"earc" is the raw object data for Archer in WC3
endfunction

function Create_Units_Top_Left takes nothing returns nothing
    local trigger t=CreateTrigger()
    call TriggerRegisterTimerEventPeriodic(t, 30.00)
    call TriggerAddAction(t, function Create_Units_NightElf)
endfunction
 
JASS:
function Create_Units_NightElf takes nothing returns nothing
    local integer i = 0
    local real x = GetRectCenterX(Top_Right_Spawn)
    local real y = GetRectCenterY(Top_Right_Spawn)
    loop
        call CreateUnit(Player(0), 'earc', x, y, 270) //'earc' is the raw object data for Archer in WC3
        set i = i + 1
        exitwhen i == 4
    endloop
endfunction

function Create_Units_Top_Left takes nothing returns nothing
    local trigger t=CreateTrigger()
    call TriggerRegisterTimerEventPeriodic(t, 30.00)
    call TriggerAddAction(t, function Create_Units_NightElf)
endfunction
 
Level 11
Joined
Apr 6, 2008
Messages
760
use vJass instead of jass :D

JASS:
scope Name initializer init

globals
    private real x
    private real y
    private timer Time = CreateTimer()
endglobals


private function Create takes nothing returns nothing
    local integer i = 0

    loop
        exitwhen i >= 4
        call CreateUnit(Player(0), 'earc', x, y, 270)
        set i = i + 1
    endloop

endfunction

private function init takes nothing returns nothing
    set x = GetRectCenterX(Top_Right_Spawn)
    set y = GetRectCenterY(Top_Right_Spawn)

    call TimerStart(Time,30,true,function Create)
endfunction

endscope
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
two notes:
- if Top_Right_spawn is a global variable generated with the variable editor, it requires the "udg_" prefix.
- you don't necessarily need the timer variable. Assuming the periodic spawn can't be interrupted, you don't need it, and assuming you can stop the periodic spawn somehow, you could still retrieve the timer in the callback.
 
Status
Not open for further replies.
Top