• Check out the results of the Techtree Contest #19!
  • 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.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

[JASS] Trouble with Structs

Status
Not open for further replies.
Level 3
Joined
Feb 17, 2008
Messages
41
I am learning some vJass so I played with struct so I have the ability to move local vars across functions. Here is an example I have so far.

Setup Data Trigger
JASS:
struct Peasant
    unit u
    real x
    real y
endstruct

function Trig_Setup_Data_Actions takes nothing returns nothing
    local Peasant pea = Peasant.create()
    local unit u = gg_unit_hpea_0001
    local real y = GetUnitY(u)
    local real x = GetUnitX(u)
    set pea.u = u
    set pea.y = y
    set pea.x = x
endfunction

//===========================================================================
function InitTrig_Setup_Data takes nothing returns nothing
    set gg_trg_Setup_Data = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Setup_Data, function Trig_Setup_Data_Actions )
endfunction

Data Show Trigger
JASS:
function Trig_DataShow_Actions takes nothing returns nothing
    local Peasant pea
    call BJDebugMsg("I am being called!")
    call BJDebugMsg(GetUnitName(pea.u))
    call BJDebugMsg(R2S(pea.x))
    call BJDebugMsg(R2S(pea.y))
endfunction

//===========================================================================
function InitTrig_DataShow takes nothing returns nothing
    set gg_trg_DataShow = CreateTrigger(  )
    call TriggerRegisterTimerEvent( gg_trg_DataShow, 5, false)
    call TriggerAddAction( gg_trg_DataShow, function Trig_DataShow_Actions )
endfunction

It shows "I am being called!" Debug message but it doesn't not show the data being transferred.
 
Yes, PurplePoot was better explaining structs to me. Can you please post the correct form of code so I understand better.
 
Don't get it. The whole SetHandleInt part.

He's attaching the struct data to a timer?
 
well fuck, im totally lost now. Reading that just made me more confused.

JASS:
struct Peasant
    unit u
    real x
    real y
endstruct

function showData takes nothing returns nothing
    local Peasant pea = Peasant( GetHandleInt(u,"dat") )
    call BJDebugMsg("I am being called!")
    call BJDebugMsg(GetUnitName(pea.u))
    call BJDebugMsg(R2S(pea.x))
    call BJDebugMsg(R2S(pea.y))
    endfunction

function Trig_Setup_Data_Actions takes nothing returns nothing
    local Peasant pea = Peasant.create()
    local unit u = gg_unit_hpea_0001
    set pea.u = u
    set pea.y = GetUnitY(u)
    set pea.x = GetUnitX(u)
    call SetHandleInt(u,"dat",pea)
    call showData(u)
endfunction

//===========================================================================
function InitTrig_Setup_Data takes nothing returns nothing
    set gg_trg_Setup_Data = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Setup_Data, function Trig_Setup_Data_Actions )
endfunction


See what I mean.
 
Okay, just no.

JASS:
globals
    Peasant pea
endglobals

//struct def. (Or maybe it has to go above the globals def, I can never remember)

function f2 takes nothing returns nothing
    //do stuff with pea
endfunction

function f takes nothing returns nothing
    set pea = Peasant.create()
    //setup
endfunction

In this case, I get the impression that that's what you want.
 
Status
Not open for further replies.
Back
Top