• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[JASS] my first struct-using trigger = failure

Status
Not open for further replies.

Cokemonkey11

Spell Reviewer
Level 30
Joined
May 9, 2006
Messages
3,547
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.
 

Cokemonkey11

Spell Reviewer
Level 30
Joined
May 9, 2006
Messages
3,547
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