Undeclared Variables

Tyman2007

Ya Rly >.
Reaction score
74
Possibly simple problem.
I get an undeclared variable error for variables u and p
the errors are where the sets are in the actions where u and p is set.

JASS:
scope Fireball initializer Init

globals
    private constant integer ABIL_CODE = 'A000'     //ID of the ability
    private constant integer DUMM_CODE = 'h000'     //ID of the dummy unit (Fireball)
    
    private constant real P_DIST = 150              //Distance from the dummy
    private constant real S = 10                    //Initial scale of the dummy (in percent)
    
    private constant sound FIRE_SOUND = gg_snd_RainOfFireTarget1 //Sound of the initial cast
endglobals

private struct DATA
    unit u
    player p
    
    location l1
    location l2
    location l3
    
    real r1
    real r2
endstruct

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

private function Actions takes nothing returns nothing
    local DATA d = DATA.create()
    
    set d.u = GetSpellAbilityUnit()
    set d.p = GetOwningPlayer(u)
    
    set d.l1 = GetUnitLoc(u)
    set d.l2 = GetSpellTargetLoc()
    set d.l3 = PolarProjectionBJ(d.l1, P_DIST, d.r1)
    
    set d.r1 = AngleBetweenPoints(d.l1, d.l2)
    set d.r2 = DistanceBetweenPoints(d.l1, d.l2)
    
    call PauseUnit( GetSpellAbilityUnit(), true )
    call CreateUnitAtLoc( p, DUMM_CODE, d.l3, 270 )
    call SetUnitScalePercent( u, S, S, S )
    
    call PlaySoundAtPointBJ( FIRE_SOUND, 100, d.l3, 10.00 )
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( trig, Condition( function Conditions ) )
    call TriggerAddAction( trig, function Actions )
endfunction

endscope


I have started JASS a long time ago, (a year or 2 ago) and yet I still fail...
I've yet to fully grasp structs and how to use them
I don't know if you can call methods from inside structs inside other methods (Method 2 calls method 1)
And if you can I don't know how.

Someone told me that structs were just better to use and now I'm getting this error and I don't know what is going on.
 

Nestharus

o-o
Reaction score
84
u -> d.u like below

[ljass]GetOwningPlayer(u)[/ljass]

p -> d.p


They are members of the struct and so you need to access them through the struct.

In the background it looks like this-
u[d]
p[d]

Where d is an instance of the struct (an int) and the members (u, p) are arrays. That's how structs work in vJASS : ).

Now, you can't actually type out what I typed out (d.u, d.p instead), but that's what it does translate into : p.

That's also how OO programming typically works.
 

Tyman2007

Ya Rly >.
Reaction score
74
Thanks for your reply.

Overall, your message just told me to double-check the arguments on the functions.

Silly me, I really am going blind.
 
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