• 🏆 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] Need help on Tree Spawn System

Status
Not open for further replies.
Level 9
Joined
Dec 12, 2007
Messages
489
I'm making a trigger on vJASS for my map, which set up trees on map initialization.
When I'm trying to test it, it crash when loading is already half complete.
but after changing a bit the trigger, now the map can be loaded.
But, the trees that should be spawned on init isn't there.

Here is the trigger:
JASS:
scope TreeSetup initializer init

    globals
        private constant real X_DIS = 400
        private constant real Y_DIS = 400
        private constant real MIN_T = 0.60
        private constant real MIN_S = 0.8
        private constant real MAX_S = 1.2
        private constant real MIN_D = 10
        private constant real MAX_D = 60
        private constant integer T_ID  = 'ITtw'
        private constant integer T_VAR = 10
        private constant string SFX = "Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl"
        private constant boolean USE_SFX = false
    endglobals

    struct ReviveTree
        destructable d
    endstruct

    private function Res_Tree takes nothing returns nothing
        local timer t = GetExpiredTimer()
        local ReviveTree data = GetInt(t,0)
        call DestructableRestoreLife( data.d, GetDestructableMaxLife(data.d), true )
        if USE_SFX then
            call DestroyEffect(AddSpecialEffect(SFX,GetDestructableX(data.d),GetDestructableY(data.d)))
        endif
        call data.destroy()
        call Flush(t)
        call ReleaseTimer(t)
        set t = null
    endfunction

    private function Revive_Tree takes nothing returns nothing
        local timer t        = NewTimer()
        local destructable d = GetDyingDestructable()
        local ReviveTree data = ReviveTree.create()
        set data.d = d
        call SetInt(t,0,data)
        call TimerStart(t,GetRandomReal(MIN_D,MAX_D),false,function Res_Tree)
        set t = null
        set d = null
    endfunction

    private function setup takes nothing returns nothing
        local trigger trig   = CreateTrigger()
        local destructable d
// this Game_MinX,MaxX, MinY,and MaxY are globals that declared in library on init.
        local real minx = Game_MinX + X_DIS
        local real maxx = Game_MaxX - X_DIS
        local real miny = Game_MinY + Y_DIS
        local real maxy = Game_MaxY - Y_DIS
        local real curx = minx
        local real cury = miny
        local integer check = 0
        local integer cur_t = 0
        local integer min_t = R2I((maxy-miny)*MIN_T/Y_DIS)
        local integer i     = 1
        local boolean array is_tree

        call TriggerAddAction(trig, function Revive_Tree)
        loop
            exitwhen curx >= maxx
            loop
                exitwhen cury >= maxy
                set check = GetRandomInt(1,2)
                if check == 2 and is_tree[i] == false then
                    set d = CreateDestructable(T_ID,curx,cury,GetRandomReal(0,359),GetRandomReal(MIN_S,MAX_S),GetRandomInt(1,T_VAR))
                    call TriggerRegisterDeathEvent(trig, d)
                    set cur_t = cur_t +1
                    set is_tree[i] = true
                endif
                set i = i +1
                set cury = cury + Y_DIS
                if cur_t < min_t then
                    set i = 1
                    set cury = miny
                endif
            endloop
            set i = 1
            loop
                exitwhen i > R2I(min_t/MIN_T)
                set is_tree[i] = false
                set i = i+1
            endloop
            set cury = miny
            set cur_t = 0
            set i = 1
            set curx = curx + X_DIS
        endloop

        set d = null
        set trig = null
    endfunction

    private function init takes nothing returns nothing
        call ExecuteFunc("TreeSetup___setup")
    endfunction
endscope
after some time debugging, I found out that its the executefunc in the init that cause the whole mess.
but I can't find anything wrong with it, please help.

EDIT : I forgot to tell what the trigger do: it supposed to place tree in random order, so it will always be different from game to game, it has minimum amount of tree requirement per line, if the minimum hasn't reached, it will loop again till it reached the minimum req. Upon placement the tree is also registered into tree respawn trigger.
 
Last edited:
Agreed. ExecuteFunc most is most likely the cause of the error.

Simply do this, scope TreeSetup initializer setup.

If that does not work then you can change your init trigger to;

JASS:
call TimerStart(CreateTimer(), 0.00, false, function setup)

Good luck.

EDIT: I didn't even look at your setup function, hitting the OP limit is definitely a possibility like DSG said.
 
Last edited:
Level 4
Joined
Nov 7, 2009
Messages
83
Why don't you try doing things this way
JASS:
scope TreeSetup initializer Init
    private function Conditions takes nothing returns boolean
        return GetSpellAbilityId() == SPELL_ID
    endfunction

    private function Actions takes nothing returns nothing

    endfunction

    private function Init takes nothing returns nothing
        local trigger TreeSetupTrg = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(TreeSetupTrg, EVENT_PLAYER_UNIT_SPELL_EFFECT )
        call TriggerAddCondition(TreeSetupTrg, Condition( function Conditions ) )
        call TriggerAddAction(TreeSetupTrg, function Actions )
    endfunction
endscope
I think you'll have to change the event though.

As regarding to
JASS:
call ExecuteFunc("TreeSetup___setup")
I think it's better if you do
JASS:
call setup()
like Saia_Djinn said
 
Level 9
Joined
Dec 12, 2007
Messages
489
Thx for the help, the crash part is solved. Yay:smile:
and I've search about this opt limit, but none explain about it.
can someone explain it for me?
or is this opt limit the same as thread limit crash thingy?
oh btw, when I test the trigger, it only create 1 tree at bottom-left corner and nothing more,
can someone take a look in the script and tell me what's wrong with it?
or a better way to accomplish it too would be better...:grin:
 
Level 13
Joined
Mar 16, 2008
Messages
941
A thread (some sort of "one trigger" definition, can't explain it exactly) can only do a special amount of actions. This was invented to prevent endless loops and will stop the trigger immediatly. Waits, TriggerExecute, TriggerSyncReady and someother function start new threads, causing the limit to start by 0 again.
 
Level 9
Joined
Dec 12, 2007
Messages
489
FFS. The ExecuteFunc thing is exactly what you should do, but "TreeSetup___setup" is not always the private name for the function. The number of underscores changes every time to save it. You need to do ExecuteFunc(SCOPE_PRIVATE + "setup").

Ah I see... thx!!
btw, I prefer to use executefunc for this because like you all said, it may cause thread crash.
Thanks alot for helping!

@Flamesoul: ehm.... this isn't spell man.... hehee:smile:
 
Status
Not open for further replies.
Top