Need help with struct

Laiev

Hey Listen!!
Reaction score
188
I just start using struct right now and, hm... Don't know why something happen, probably someone can help me...

The first comment (1) i REALLY don't know for what is, i just see it in some others spells
the second comment (2) is the syntax error, i just want use the d.u to check something in the loop, but don't know how to 'restore' the struct set'ed
the thirst comment (3) Well, i don't know if all is ok in this part... some problem say and if possible explain

JASS:
scope Bats initializer Init

globals
    private constant integer AbilId = 'A034'
    private constant integer BAT = 'u00A'
    private unit U = null
endglobals

private struct bat
    unit u
    timer t
endstruct

private function Acts takes nothing returns nothing
    local data d = GetData(GetExpiredTimer()) // <~ 1
    local integer i = 0
    local integer randint = GetRandomInt (50, 300)
    
    set U = d.u // <~ 2
    loop
        exitwhen i == GetUnitAbilityLevel (U, AbilId) * 2
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ some function here.
        set i = i + 1
    endloop
endfunction

private function Actions takes nothing returns nothing
    local bat d = bat.create()                       // <~~~~~~~>
    set d.u = GetTriggerUnit()                       // <~~~~~~~>
    set d.t = NewTimer()                             // <~~~3~~~>
    call TimerStart(d.t,2.,true,function Acts)      // <~~~~~~~>
    call SetData(d.t,d)                             // <~~~~~~~>
endfunction

private function Condi takes nothing returns boolean
    if GetLearnedSkill() == AbilId and GetUnitAbilityLevel(GetTriggerUnit(),AbilId)==1 then
        call Actions()
    endif
    return false
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_HERO_SKILL )
    call TriggerAddCondition(t, Condition(function Condi))
endfunction
endscope


any help about it is appreciate, but please, don't post link of struct tutorials.


EDIT: well, nevermind... i found the problem...

[ljass] local data d = GetData(GetExpiredTimer()) // <~ 1[/ljass] must be [ljass] local bat d = GetData(GetExpiredTimer()) // <~ 1[/ljass]
 

the Immortal

I know, I know...
Reaction score
51
The order really doesn't matter.

GetData and SetData respectively set a timer's data and then get it. Ynow, it's like sticking a label to that timer. [ljass]SetData(T, D)[/ljass] sets T's data to D (T = timer). And [ljass]GetData(T)[/ljass] gets T's data. So [ljass]GetData(GetExpiredTimer())[/ljass] will get the current timer's data. Exactly what you'd need.

About this U, if you need to use the unit instantly somewhere in another function (like enum) better make your [ljass]local data d[/ljass] variable a global.

So you'll have something like
JASS:

globals
    ...
    data d
endglobals

... 
//read Acts first
function Enum takes nothing returns boolean
    call UnitDamageTarget(u.d, GetEnumUnit(), .... )    //will cause the d.u unit (the one attached to the current timer) to damage the picked unit
    return false
endfunction

function Acts takes nothing returns nothing
    local integer i = 0    //local vars declarations first
    ...
    
    set d = GetData(GetExpiredTimer())    //save the timer&#039;s data into the global, it&#039;s gonna be used instantly after that so we&#039;re perfectly MUI
    GroupEnumUnitsIn... (...., Filter( function Enum))    //for every enumed unit will do Enum function which uses the &#039;d&#039; variable i.e. the one we just set
    
    ....

endfunction
....
 

Tyman2007

Ya Rly >.
Reaction score
74
I don't know all that much about structs, but this really caught my attention.

[ljass]private struct bat[/ljass]
[ljass]local data d[/ljass]

Try
[ljass]local bat d[/ljass]
or rename your struct to [ljass]data[/ljass]
 

Laiev

Hey Listen!!
Reaction score
188
i think you don't read my post...

EDIT: well, nevermind... i found the problem...

[ljass]local data d = GetData(GetExpiredTimer())[/ljass] // <~ 1 must be [ljass]local bat d = GetData(GetExpiredTimer())[/ljass] // <~ 1
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top