• 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] Ok. I need help with this.

Status
Not open for further replies.
JASS:
function InitTrig_Red_Spawn takes nothing returns nothing
    set gg_trg_Red_Spawn = CreateTrigger(  )
    call TriggerRegisterTimerExpireEventBJ( gg_trg_Red_Spawn, udg_Next_Level )
    local integer x
    set x = 1
    call CreateNUnitsAtLoc( udg_Monster_Amount, udg_Monster_Type, Player(11), GetRectCenter(gg_rct_Red_Spawn), bj_UNIT_FACING )
    call DisplayTextToForce( bj_FORCE_PLAYER[0], ( GetUnitName(GetLastCreatedUnit()) + "s" ) )
    loop
        exitwhen (udg_Level_Number == 10 )
        exitwhen (udg_Level_Number == 20 )
        exitwhen (udg_Level_Number == 30 )
        call CreateNUnitsAtLoc( udg_Monster_Amount, udg_Monster_Type, Player(11), GetRectCenter(gg_rct_Red_Spawn), bj_UNIT_FACING )
        call TriggerSleepAction( 1.00 )
        exitwhen x > 20
        set x = x + 1
    endloop
    set gg_trg_Red_Spawn = null
endfunction

The problem is with declaring the integer. I keep getting error messeges with it. Help someone?
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
You need to declare all locals at the start of the function (before any non-local defining lines)

Also, you can initialize locals with values, so

local integer x
set x = 1

is the same as

local integer x = 1

The first 4 lines of the function should look like:

JASS:
function InitTrig_Red_Spawn takes nothing returns nothing
    local integer x = 1
    set gg_trg_Red_Spawn = CreateTrigger()
    call TriggerRegisterTimerExpireEventBJ( gg_trg_Red_Spawn, udg_Next_Level )

By the way, all of those exitwhens can be merged, for example

JASS:
exitwhen udg_Level_Number == 10 or udg_Level_Number == 20 or udg_Level_Number == 30 or x > 20

Next, clean up your location leaks, or more preferrably, just create the units using X/Y (CreateUnit)

Finally, I'm not sure you understand how triggers work. The actions( like the loop and stuff) should go in an Actions function, and you use

JASS:
call TriggerAddAction( gg_trg_Red_Spawn, function SomeActionFunction )
to point a trigger to an action

What you have right now would just run it once on map init, and do nothing whenever the timer expired.
 
KK, ty ill mess around and see if i can make it work. IF i set the initialy enabled field to false will it not run at start? Because i can do the event in a GuI trigger and call it with custom script >< and where are all the leaks? No leaks is good, but at the moment, its only a four player map (30 levels), so it doesnt lag much, but i do want it leak free ^.^

Ok now it wont let me call it through a custom script. i keep getting the error message: Expecting fuction name, but when i call it i have: call Inittrigg_Red_Spawn ()
and thats what the name of the function is, what am i doing incorrectly?
 
Last edited:
Level 40
Joined
Dec 14, 2005
Messages
10,532
GetRectCenter( someRect )

returns a location


anyways --

Disabling the trigger won't help, it'll just make the trigger not be able to fire, causing the actions not to run, but you don't have any actions.

The structure should be like such:

JASS:
function SomethingConds takes nothing returns boolean
    return someBoolean//someBoolean is a boolean, eg. true, false, GetSpellAbilityId() == 'A005', etc
endfunction

function Something takes nothing returns nothing
    //go crazy here
endfunction

function InitTrig_Something takes nothing returns nothing
    set gg_trg_Something = CreateTrigger()
    call TriggerRegister(finish this function with the correct 'event' function)( gg_trg_Something, (finish your event function parameters here))
    call TriggerRegisterCondition( gg_trg_Something, Condition( function SomethingConds ) )//conditions are optional, you can choose not to have one if you so desire
    call TriggerAddAction( gg_trg_Something, function Something )
endfunction
 
Status
Not open for further replies.
Top