• 🏆 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] Not running function to give spell

Status
Not open for further replies.
Level 9
Joined
Apr 23, 2011
Messages
460
I've tried many different spell ID's and none have worked so far and I'm curious as to what could be wrong with my scripting that would cause this to happen. Using Debug messages I was able to determine that the trigger is working as intended, but a block in the coding for the struct isn't working. I can't find it, anyone have any ideas?

vJass code
JASS:
struct Jump extends array
    private static integer spell = 'Aroc'
    private static rect area = gg_rct_GiveSpell
    
    private static method GiveSpell takes nothing returns nothing
        local unit u = GetEnumUnit()
        local location loc = Location(GetRectCenterX(gg_rct_ResendSpell),GetRectCenterY(gg_rct_ResendSpell))
        call UnitAddAbility(u, spell)
        call SetUnitPositionLoc(u, loc)
        set loc = null
        set u = null
    endmethod
    
    private static method CheckUnit takes nothing returns nothing
        local group g = CreateGroup()
        call GroupEnumUnitsInRect(g, area, null)
        call ForGroup(g, function thistype.GiveSpell)
        call DestroyGroup(g)
        set g = null
    endmethod
    
    static method Main takes nothing returns nothing
        call .CheckUnit()
    endmethod
endstruct

Jass Trigger Creation
JASS:
function CheckUnitCond takes unit u returns boolean
    local integer typeUnit = 'hfoo'
    local region r = CreateRegion()
    call RegionAddRect(r, gg_rct_GiveSpell)
    if GetUnitTypeId(u) == typeUnit and IsUnitInRegion(r, u) == true then
        return true
    else
        return false
    endif
endfunction

function DoSpellGive takes nothing returns nothing
local unit u = GetEnumUnit()
   if CheckUnitCond(u) == true then
        call Jump.Main()
    endif
    set u = null
endfunction

function GiveSpell takes nothing returns nothing
    local group g = CreateGroup()
    call GroupEnumUnitsInRect(g, gg_rct_GiveSpell, null)
    call ForGroup(g, function DoSpellGive)
    call DestroyGroup(g)
    set g = null
endfunction
function InitTrig_Run_Jump takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterTimerEvent(t, 1., true)
    call TriggerAddAction(t, function GiveSpell)
    set t = null
endfunction
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
call TriggerRegisterTimerEvent(t, 1., true)

thus the trigger will ONLY run at 1 second game time and not when a unti enters region...
 
Level 9
Joined
Apr 23, 2011
Messages
460
That's not the issue. The jass line call TriggerRegisterTimerEvent(t, 1., true) takes three arguments. The first is trigger whichTrigger, real timeout, and boolean periodic. Therefore, my code line will apply the timer event to the local trigger t, which will time out every 1. seconds, and repeat true.

The BJ known as TriggerRegisterTimerEventPeriodic will call the following code.

JASS:
function TriggerRegisterTimerEventPeriodic takes trigger trig, real timeout returns event
    return TriggerRegisterTimerEvent(trig, timeout, true)
endfunction

Which does exactly what I did, only I used the proper native with "true" to declare periodic, just like this function.
 
Level 9
Joined
Apr 23, 2011
Messages
460
The error is occurring from the Give Spell method. Everything works up until I call ForGroup(g, function GiveSpell). It seems to be skipping this function. Should I do a loop system for every unit in group. Or should this entire system be redone to something else?
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
Test something like this (Its from a tutorial about leak checking)

JASS:
globals
    // values to carry to the DoThings function
    real AmountToHeal
endglobals
function DoThings takes nothing returns boolean
                                      /*nothing becomes boolean*/

    call SetWidgetLife(GetFilterUnit(), GetWidgetLife(GetFilterUnit()) + AmountToHeal
                     /*GetEnumUnit() becomes GetFilterUnit()*/
    
    return false
  /*return false appears here*/
endfunction

function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
    // Store values before the enum instead
    set AmountToHeal = 200.0
    // Note the next line.
    call GroupEnumUnitsInRect(GROUP, bj_mapInitialPlayableArea, Filter(function DoThings))
    // The end.
endfunction
 
Level 9
Joined
Apr 23, 2011
Messages
460
That not only doesn't address my problem, but is entirely irrelevant. Currently the problem stands at: The code call ForGroup(g, function GiveSpell) is not firing properly. I'll review some tutorials and some other scripts, but If anyone has some useful feedback as to why the ForGroup wouldn't work in this case please tell me.
 
Level 3
Joined
Jan 31, 2012
Messages
42
JASS:
//! zinc
library Jump {
    constant integer SPELL_ID = 'Aroc';
    constant integer UNIT_ID = 'hfoo';
    //! textmacro Jump__Rect
        gg_rct_GiveSpell
    //! endtextmacro
    constant group G = CreateGroup();

    function onInit() {
        TimerStart(CreateTimer(), 1., true,
            function() {
                unit u;
                GroupEnumUnitsInRect(G,
                    //! runtextmacro Jump__Rect()
                , null);
                while (true) {
                    u = FirstOfGroup(G);
                    if (u == null) { break; }
                    if (GetUnitTypeId(u) == UNIT_ID) {
                        UnitAddAbility(u, SPELL_ID);
                        SetUnitX(u, GetRectCenterX(
                            //! runtextmacro Jump__Rect()
                        );
                        SetUnitY(u, GetRectCenterY(
                            //! runtextmacro Jump__Rect()
                        );
                    }
                }
            }
        );
    }
}
//! endzinc
 
Level 9
Joined
Apr 23, 2011
Messages
460
JASS:
//! zinc
library Jump {
    constant integer SPELL_ID = 'Aroc';
    constant integer UNIT_ID = 'hfoo';
    //! textmacro Jump__Rect
        gg_rct_GiveSpell
    //! endtextmacro
    constant group G = CreateGroup();

    function onInit() {
        TimerStart(CreateTimer(), 1., true,
            function() {
                unit u;
                GroupEnumUnitsInRect(G,
                    //! runtextmacro Jump__Rect()
                , null);
                while (true) {
                    u = FirstOfGroup(G);
                    if (u == null) { break; }
                    if (GetUnitTypeId(u) == UNIT_ID) {
                        UnitAddAbility(u, SPELL_ID);
                        SetUnitX(u, GetRectCenterX(
                            //! runtextmacro Jump__Rect()
                        );
                        SetUnitY(u, GetRectCenterY(
                            //! runtextmacro Jump__Rect()
                        );
                    }
                }
            }
        );
    }
}
//! endzinc

Gives Unexpected ; error on line 24, without it it says unexpected SetUnitX. So. Idk what to do about this. I don't know zinc. Or textmacros >.<
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
I gave you a solution to bypassing forGroup.... instead of running a function for forGroup you make the function the filter in the groupenumunits
 
Status
Not open for further replies.
Top