• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[vJASS] Structs that reference eachother

Status
Not open for further replies.
Level 6
Joined
Mar 7, 2011
Messages
124
I want to have two structs that look like

Code:
library Foo

struct B
    public Foo_A parent
endstruct

struct A
    public B array children
endstruct

endlibrary

how do I design them so that JASSHelper doesn't complain? My actual setup is more complicated, with a few more classes having 0-many children with 1 parent, but the basic idea applies. I need to depth first search to find a single child, and then I want to be able to look up the parent chain from that child

my only idea so far sucks: consolidating all the classes into a single one, adding a property to specify the generic classes specific type, and implementing the original differences between them as very complex switch statements around that type
 
Last edited:
Level 6
Joined
Mar 7, 2011
Messages
124
oh... well that's awkward, so it does

looks like the difference i overlooked before is mine are inside a library, and it can compile just fine so long as I put

Code:
library Foo

struct B
    public Foo_A parent
endstruct

struct A
    public B array children
endstruct

endlibrary

seems a little weird to me that A's properties can bind automatically while B's needs help to find A, but maybe most of that weirdness is just me feeling dumb haha. thanks for the help trigger happy
 
Level 7
Joined
Oct 19, 2015
Messages
286
Your example does not show the whole picture. First of all, you forgot to define the size of the array. Second, even with the size defined, it does not compile. Changing "Foo_A" to just "A" works.

I'm guessing that in your actual code, your structs have the "public" prefix, which is why you need to replace "A" with "Foo_A". You can get around this by either dropping the public prefix, or adding a line at the start of your library that says "public keyword A".
 
Level 6
Joined
Mar 7, 2011
Messages
124
Thanks for your points, Anitarf

Correct array syntax aside, my point of disconnect from what i intuitively expected was when struct A's property: 'children' could bind to type B with no additional help while struct B's property 'parent' could not. in this case, i think my intuition, coming from other languages, wasn't in Kansas anymore

I think it'd be best to leave them both public since I didn't choose very specific names. It's totally fine to include the lib name for references that appear below, I just needed to remember/be reminded that was the fix
 
Last edited:
Level 7
Joined
Oct 19, 2015
Messages
286
Again, if you keep the public prefix then the proper fix is to use keyword:
JASS:
library Foo

    public keyword A

    public struct B
        public A parent
    endstruct

    public struct A
        public B array children[10]
    endstruct

endlibrary
This same method can be used in case of private structs (you would just replace "public keyword" with "private keyword"), while your current solution would not work in that case.
 
Status
Not open for further replies.
Top