• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] my first struct-using trigger = failure

Status
Not open for further replies.
JASS:
struct knockDat
    unit uni
    real speed
    real direc
    timer time
endstruct

function tideTimeCall takes nothing returns nothing
    local knockDat knockD
    local location offset = PolarProjectionBJ(GetUnitLoc(knockD.uni),knockD.speed,knockD.direc)
    call SetUnitPositionLoc(knockD.uni,offset)
    set knockD.direc = knockD.direc - 1
    if knockD.direc < 30 then
        call DestroyTimer(knockD.time)
    endif
endfunction

function tideKnock takes nothing returns nothing
    local knockDat knockD = knockDat.create()
    local knockDat knockCastD
    local unit kdunit = CreateUnitAtLoc(GetOwningPlayer(knockCastD.uni),'hfoo',GetUnitLoc(knockCastD.uni),knockCastD.direc)
    call BJDebugMsg(GetUnitName(kdunit))
    //-->
    set knockD.uni = kdunit
    call BJDebugMsg(GetUnitName(knockD.uni))
    set knockD.speed = 15
    set knockD.direc = GetUnitFacing(GetSpellAbilityUnit())
    call TimerStart(knockD.time,.03,true,function tideTimeCall)
endfunction

function tideActions takes nothing returns nothing
    local knockDat knockCastD = knockDat.create()
    if GetSpellAbilityId()=='A001' then
        set knockCastD.uni = GetSpellAbilityUnit()
        set knockCastD.direc = GetUnitFacing(GetSpellAbilityUnit())
        call tideKnock()
    else
        call knockCastD.destroy()
    endif
endfunction

function InitTrig_tide takes nothing returns nothing
    set gg_trg_tide = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_tide,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddAction(gg_trg_tide,function tideActions)
endfunction

what am i doing wrong? everything seems to work until it gets to by debug messages (look for the comment)
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
Code:
PolarProjectionBJ(GetUnitLoc(knockD.uni),knockD.speed,knockD.direc)

call SetUnitPositionLoc(knockD.uni,offset)

if knockD.direc < 30 then
    call DestroyTimer(knockD.time)
endif

local unit kdunit = CreateUnitAtLoc(GetOwningPlayer(knockCastD.uni),'hfoo',GetUnitLoc(knockCastD.uni),knockCastD.direc)

set knockD.uni = kdunit

call BJDebugMsg(GetUnitName(knockD.uni))

set knockD.speed = 15
    
set knockD.direc = GetUnitFacing(GetSpellAbilityUnit())
    
call TimerStart(knockD.time,.03,true,function tideTimeCall)

All this lines fail seeing as your structs aren't even initialized.
Do not forget the struct.create/allocate methods.

As to the fact that it wouldn't work also if you would initialize them - how exactly do your functions know of your locals in other functions? Structs aren't magical, they are locals like any other locals.
 
the first line of tideActions and tideKnock ".create" the structs.

Is there something I'm missing?

I thought the whole point of structs was passing multiple values in an object oriented system from function to function.

Can you tell me specifically what I need to change?

Am I supposed to do .create again in each function the struct is used?
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
local knockDat knockD = knockDat.create()
local knockDat knockCastD

The first one is fine, but you try to add to it a value from the second one which isn't even initialized, not to mention it can't know what "GetOwningPlayer(knockCastD.uni)" is.

JASS:
function bla takes nothing returns nothing
    local meh m = meh.allocate() // allocate or create don't really matter
endfunction
function ble takes nothing returns nothing
    local meh m = meh.allocate() // DUDE I DON'T KNOW THAT OTHER M GUY !
endfunction

You can either pass your struct (in your first function call, anyways), or use a global, or use yet another H2I system which isn't really recommended this days as you can simply put private globals.

JASS:
globals
    private meh MEH = meh.allocate() // yey no body out side this scope knows me (not sure as to how Vexorian made the private and thus if it has to use the scope tags or it's working according to triggers)
endglobals
 
Status
Not open for further replies.
Top