• 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] Problem with an array of a custom Struct

Status
Not open for further replies.
Level 4
Joined
Nov 24, 2007
Messages
55
I can't seem to get the array of my custom "locStack" to work properly...at all. I am quite confused. I *can* theoretically do this without the Array (since there are only 4 stacks...but having them in array makes a lot of my code a bunch prettier and simpler.

Here is my code in my header (I am using JassNewGenPack if that helps).

JASS:
struct locStack
    location array a[100]
    // the Top Of Stack represents our empty position
    integer tos = 0
endstruct

function pushStack takes locStack s, location loc returns nothing
    if( s.tos <= 99 ) then
        set s.a[s.tos] = loc
        set s.tos = s.tos + 1
    else
    endif
endfunction

function popStack takes locStack s returns location
    if( s.tos >= 1 ) then
        set s.tos = s.tos - 1
        return s.a[s.tos]
    else
        return null
    endif
endfunction

function peekStack takes locStack s returns location
    return s.a[s.tos-1]
endfunction

globals
    locStack array theGYs[4]
endglobals

function pingStack takes locStack s returns nothing
    call PingMinimapLocForPlayer( Player(0), s.a[s.tos-1], 2 )
endfunction

I added the pingStack for testing purposes. Here is where the stack array is initialized...

JASS:
    set loc1 = GetRectCenter(gg_rct_Lvlr1)
    call pushStack(theGYs[0], loc1)
    set loc2 = GetRectCenter(gg_rct_Lvlr3)
    call pushStack(theGYs[1], loc2)
    //set loc3 = GetRectCenter(gg_rct_Lvlr3)
    //call pushStack(theGYs[2], loc3)
    //set loc4 = GetRectCenter(gg_rct_Lvlr4)
    //call pushStack(theGYs[3], loc4)

I commented out those last ones for testing and changed the loc of 2. Also i wasn't reusing a single 'loc' because i thought that maybe that was what was causing the bug. And here is the "testing" function that runs when i type in -stack in game.

JASS:
function Trig_stack_messing_Actions takes nothing returns nothing
    call pingStack( theGYs[0] )
    call BJDebugMsg("ping coming")
    call PolledWait( 3.0 )
    call pingStack( theGYs[1] )
    call BJDebugMsg("2nd Ping")
    call PolledWait( 3.0 )
    call pingStack( theGYs[2] )
    call BJDebugMsg("3rd ping")
    call PolledWait( 3.0 )
    call pingStack( theGYs[3] )
    call BJDebugMsg("4th ping")
endfunction

What this ends up doing is actually putting all four pings on the center of that gg_rct_Lvlr3...even though theGYs[2] and theGYs[3] theoretically haven't had any data put in them...

I will assume this has somethign with the way that JassNewGen or w/e converts my struct?

Any help (or a simple, "No, you will just have to make 4 seperate locStacks and have ugly code") would be greatly appreciated.

Thanks
 
Level 4
Joined
Nov 24, 2007
Messages
55
I know I shouldn't double post <edit: thanks redscores lol>

but i solved this problem.

I apologize to the 3 (as of 8:45 pm) people who have 'viewed' this thread (1 probably me lol) and to anyone else who gets this far.

If you are curious to what i was doing wrong, I had not made the call of

JASS:
    set theGYs[0] = locStack.create()
    set theGYs[1] = locStack.create()
    set theGYs[2] = locStack.create()
    set theGYs[3] = locStack.create()

which makes a ton of sense. Sorry for the cluttering of the forum, but on the other hand, big thanks to Hive for the "similar" threads which pointed me to another thread on structs where a guy had a .create() call...i wish i coudl give that guy a rep point...
 
Status
Not open for further replies.
Top