• 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.

[vJASS] Circular reference

Status
Not open for further replies.
Level 20
Joined
Sep 18, 2013
Messages
169
How can i fix circle reference in Jass when im using structs??

220px-Circular_Reference.svg.png

JASS:
library libA
struct ST1
    cty array [99]
endstruct
struct cty
    ST1 ctry
endstruct
endlibrary
 
Last edited by a moderator:
Level 13
Joined
Nov 7, 2014
Messages
571
How can i fix circle reference in Jass when im using structs??

Circular references work fine when you don't have a compile time error:

JASS:
library libA
struct ST1
    cty array [99] // <-- missing name for array
endstruct
struct cty
    ST1 ctry
endstruct
endlibrary

Although calling struct cty's methods from struct ST1 would result in trigger evaluations and function copying by jasshelper.
 
Level 24
Joined
Aug 1, 2013
Messages
4,658
wut... but if they get inlined, the whole point of the function call is gone.

Anyway, back to topic.

Struct variables are never really a problem, because they are integers in the end anyways, so that shouldnt cause anythnig to break.

Function calls do have to be declared before usage.
Using libraries to organize the functions is highly recommended.

Struct methods are practically no difference.
However, if the JASSHelper finds a function being called before reference, it doesnt give a compiler error but instead creates a trigger and adds the function as condition to that trigger.
This will cause the function call to be replaced by a trigger evaluation of the respective trigger.
You should try to avoid them as much as possible, but if required, it may be used ofcourse.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,286
The question to ask yourself is "is a circular dependency necessary?".

From a design point of view circular dependencies are bad. They make maintenance bad, they make debugging confusing and they can cause all kinds of confusion. Much of the time they can be eliminated by moving the functionality to higher, more general, classes.
 
Level 13
Joined
Nov 7, 2014
Messages
571
From a design point of view circular dependencies are bad.
I think when structs/classes begin to "interact" with each other then things start to get kind of intresting.

Take for example the unit/item types in Jass.

A unit can have up to 6 items (UnitHasItem):
JASS:
struct Unit
    Item inventory array[6]
endstruct

And an item can have an owner (IsItemOwned):
JASS:
struct Item
    Unit owner
endstruct

PS: the Jass item API is lacking the native GetItemOwner takes item it returns unit and native GetItemSlot takes item it returns integer which could return -1 if it doesn't have an owner or something... =)
 
Status
Not open for further replies.
Top