Struct Help +rep.

Reaction score
341
Ok , im trying to make a MUI spell using structs because im tired of using arrays. Here's my start of my spell.

JASS:
scope FlamePort initializer InitTrig

globals
    // ------------------------------------------------------------------------------------
    private string Dummy = "Abilities\\Spells\\Other\\Incinerate\\FireLordDeathExplode.mdl"
    // ------------------------------------------------------------------------------------
    private constant real PeriodicTimer = 0.10
    private constant integer ID = 'A000'
    private constant real Speed = 500
    // ------------------------------------------------------------------------------------
endglobals

struct Data
    unit Unit
    real Dest
    //---------------------------------------------------
    public static method create takes unit u returns Data
        local Data this = Data.allocate()
        set .Unit = u
        return this
    endmethod
    //---------------------------------------------------
endstruct

private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == ID
endfunction

private function MoveUnit takes nothing returns nothing
    //local Data.d = create() --- how would i get the struct declared earlier?
endfunction

private function BeginSpell takes nothing returns nothing
    local Data d = Data.create(GetTriggerUnit())
endfunction

//===========================================================================
function InitTrig takes nothing returns nothing
    local trigger t = CreateTrigger()
    local timer time = CreateTimer()
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddAction( t, function BeginSpell )
    call TimerStart(time, PeriodicTimer, true, function MoveUnit)
endfunction

endscope



What i'm wondering is how would i get the struct information previously stored?
 

Builder Bob

Live free or don't
Reaction score
249
Well, it depends on a lot of things.
You could for example use PUI if you don't want two or more spell casts to stack on the unit.
However, the way you've set up one timer to control everyone affected by the spell, it would be more sensible to use an array of the type Data together with an integer to count how many spell effects are active.

Something like this. The same unit can now be affected by the same spell multiple times.
JASS:
struct Data
    static Data array List
    static integer Count = 0
    unit Unit
    real Dest
    integer pos
    //---------------------------------------------------
    public static method create takes unit u returns Data
        local Data d = Data.allocate()
        set d.Unit = u
        set d.pos = .Count
        set .List[.Count] = d
        set .Count = .Count + 1
        return d
    endmethod
    //---------------------------------------------------
    private method onDestroy takes nothing returns nothing
        set .Count = .Count - 1
        set .List[.Count].pos = .pos
        set .List[.pos] = .List[.Count]
    endmethod
endstruct

private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == ID
endfunction

private function MoveUnit takes nothing returns nothing
    local integer i = 0
    local Data d
    loop
        exitwhen(i >= Data.Count)
        set d = Data.List<i>
        //actions for d
        set i = i + 1
    endloop
endfunction

private function BeginSpell takes nothing returns nothing
    local Data d = Data.create(GetTriggerUnit())
endfunction

//===========================================================================
function InitTrig takes nothing returns nothing
    local trigger t = CreateTrigger()
    local timer time = CreateTimer()
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddAction( t, function BeginSpell )
    call TimerStart(time, PeriodicTimer, true, function MoveUnit)
endfunction

endscope</i>
 
Reaction score
341
so

JASS:
private function MoveUnit takes nothing returns nothing
    local integer i = 0
    local Data d
    loop
        exitwhen(i &gt;= .Count)
        set d = .List<i>
        //actions for d
        set i = i + 1
    endloop
endfunction</i>


Would work for all the units of the struct?
 

Builder Bob

Live free or don't
Reaction score
249
Yes, as long as I haven't done any mistakes. I think I've removed them all now with my many edits :)

See last update by the way. I meant to put Data.Count and Data.List in that function
 
Reaction score
341
Also , I'm confused on a few things you did.

First , what is all this static stuff , i have seen them before just never really learned about them.

Second , where would i call the onDestroy method , doesn't it destroy all instances?
 

Builder Bob

Live free or don't
Reaction score
249
a static variable in a struct is one global variable. It isn't one variable for every struct instance like the normal struct members. I could have just declared them in a global block, but I tend to put everything regarding a struct within the struct. Change it if you like.

the onDestroy method is called when you destroy a struct instance with d.destroy(). So remember that you have to manually destroy the struct when you want to stop the spell's effect.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top