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?
 
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>
 
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?
 
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
 
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?
 
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.
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    News portal has been retired. Main page of site goes to Headline News forum now
  • The Helper The Helper:
    I am working on getting access to the old news portal under a different URL for those that would rather use that for news before we get a different news view.
  • Ghan Ghan:
    Easily done
    +1
  • The Helper The Helper:
    https://www.thehelper.net/pages/news/ is a link to the old news portal - i will integrate it into the interface somewhere when i figure it out
  • Ghan Ghan:
    Need to try something
  • Ghan Ghan:
    Hopefully this won't cause problems.
  • Ghan Ghan:
    Hmm
  • Ghan Ghan:
    I have converted the Headline News forum to an Article type forum. It will now show the top 20 threads with more detail of each thread.
  • Ghan Ghan:
    See how we like that.
  • The Helper The Helper:
    I do not see a way to go past the 1st page of posts on the forum though
  • The Helper The Helper:
    It is OK though for the main page to open up on the forum in the view it was before. As long as the portal has its own URL so it can be viewed that way I do want to try it as a regular forum view for a while
  • Ghan Ghan:
    Yeah I'm not sure what the deal is with the pagination.
  • Ghan Ghan:
    It SHOULD be there so I think it might just be an artifact of having an older style.
  • Ghan Ghan:
    I switched it to a "Standard" article forum. This will show the thread list like normal, but the threads themselves will have the first post set up above the rest of the "comments"
  • The Helper The Helper:
    I don't really get that article forum but I think it is because I have never really seen it used on a multi post thread
  • Ghan Ghan:
    RpNation makes more use of it right now as an example: https://www.rpnation.com/news/
  • The Helper The Helper:
  • The Helper The Helper:
    What do you think Tom?
  • tom_mai78101 tom_mai78101:
    I will have to get used to this.
  • tom_mai78101 tom_mai78101:
    The latest news feed looks good

      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