• 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] Struct issues. :(

Status
Not open for further replies.
Level 7
Joined
Jun 16, 2008
Messages
253
*big sad face*

The struct I made (thanks to an example made by a dude that I unfortunately can't remember) is absolutely fine, and works perfectly, but certain functions that I do using it keep stuffing up, and I tihnk I found out why. I'll try to give an example of the struct thingy.

JASS:
scope test

struct Attribute
    public real mass
    public real strength
    ...
    public integer array hate[8000]
endstruct

public function Add takes unit u returns nothing //This function is not really relevant to the problem. But it's here anyway. :D
    local Attribute d = CreateAttribute()
    set d = GetUnitUserData(u) //Sticks the struct to the unit's custom value.
endfunction

public function Get takes unit u returns nothing
    local Attribute d = GetUnitUserData(u)
    call DisplayTextToPlayer(Player(0), 0, 0, R2S(d.mass)) //I tihnk that's how it goes. You guys should know anyway. This function isn't important here.
endfunction

endscope

That's what I can remember of it.

Now I got a trigger to set the hate values of a bunch of units in certain regions. Every unit in Region Red Tribe, hate every unit in Tribe Area matching not in Red Tribe kind of deal.

It looks vaguely like this.

JASS:
function bleh takes nothing returns nothing //in response to GroupENumUnit thingy, or Pick Every unit/
    local unit u = GetEnumUnit()
    local Attribute d = GetUnitUserData(Unit1) //I'm just putting arbitrary unit values in here to save extended explanations.
    set d.hate[GetUnitUserData(u)] = 100
    set d = GetUnitUserData(Unit2)
    set d.hate[GetUnitUserData(u)] = 100
    ...
endfunction

The problem starts from about line 6 onwards. I'm trying just to get the struct of various units to use in the function, but instead it seems I am actually setting the initial struct to the units, instead of getting the struct from the unit, as it already has one from melee init.

Do you see what I mean?

Could someone puh-lease explain to me how to just get the structs without sticking them around? Otherwise I'm going to have a whole bunch of bored soldiers on my map with nothing but fuzzy feelings for each other, and that's no fun. We want WAR!

:D
 
Last edited:
Level 7
Joined
Jun 16, 2008
Messages
253
That's how it was originally, but it was a big fail. All my units needed to have unique custom values (for ids), but creating Attribute, and then setting the custom value to it, always came out as 0. That was the only integer it gave me, so all my units would then have the same struct.

Regardless, I just need a method of changing which struct I am considering, which changing the struct itself.

Unit1: Custom Value = 15
Unit2: Custom Value = 16
Unit3: Custom Value = 17

Struct1: 15
Struct2: 16
Struct3: 17

At the moment, when I go set d = new number, it overwrites it. So if I go d(15) = Customvalue: 16 I might get

Struct1: 16
Struct2:16
Struct3:17

Which leaves Unit1 high and dry. Everything else is perfect, (as far as I can see) except that I can't change what struct I'm using without the changing the struct itself. The only method I can currently see is a brand spanking new function everytime I go to switch structs. Otherwise I'm permanently stuck with the first one.
It's like having elastic doublesided cellotape superglued to your fingers, it's sticky and frustrating all at the same time.

As a sidenote: I'm vaguely aware that when you create a struct, Attribute.Create() gives it a unique number. But that doesn't seem to translate to custom value as anything other than 0. Integer/Real/Rawcode/something conversion problems?
 
Level 7
Joined
Jun 16, 2008
Messages
253
Yep, I had that already, I just forgot to put it in the example.

I've also got another struct issue which is really wierd.

I've made it so that every unit in a certain rect would set hate[65] = 100.

For some reason EVERY single unit on the map will set it to 100, even though I'm not doing anything with them.

I can only assume that somehow when I modify information in one struct, it spreads to every single other struct that I've made.

???
 
Level 7
Joined
Jun 16, 2008
Messages
253
Ok, I've figgered out the problem, and the jassnewgen manual gave me the solution.

The problem was that there is a member instance limit, which completely took me by surprise. There can only be a total of 8191 instances or hate. And since I made the array size 8000, that means the limit is used up almost instantly. Sucks how there's a total cap.

Also perplexing becase I easily solved it by redeclaring the struct size..

Example

struct whoopee[10000]
integer array love[100]
endstruct

I can use the above struct on 100 units (100*100 = 10000) before running out of usable space.

I was getting some interesting chaotic effects before though, with every unit trying to attack any other unit, changing their minds every half second.

So, problem solved!
 
Status
Not open for further replies.
Top