• 🏆 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!

[JASS] Struct Problem (Samples of structs using the same variable.)

Status
Not open for further replies.
Level 4
Joined
Aug 9, 2004
Messages
70
Hey guys, I wanted to share a strange problem I got. vJass or some coding experience is needed to solve this problem I guess.

JASS:
struct Temp
    unit u
    real array x[100]
    integer d
endstruct

I have a struct similar to this one.
And these are the globals I'll be using.

JASS:
globals
   Temp array ArTemp
   integer Num
endglobals

Now let me show you the code and the problem.

JASS:
   local integer i = 0
   local Temp sample = Temp.create()
   loop 
      exitwhen i >= Num
      set sample = ArTemp[i]
      set sample.x[sample.d] = ...something...
      set sample.d = sample.d + 1
      call BJDebugMsg("Ar[" + I2S(i) + "].d is now equal to " + R2S(sample.d))
   endloop

The problem is if I run this for Num = 3 (There are codes to fill those Ar[Num]'s.)
I'll get a debug message's like this:
Ar[0].d is now equal to 1
Ar[1].d is now equal to 2
Ar[2].d is now equal to 3
Ar[0].d is now equal to 4
Ar[1].d is now equal to 5
...
...
Why do I get it? Don't I have different integer d's for all of my samples?
What I expected to get is:
Ar[0].d is now equal to 1
Ar[1].d is now equal to 1
Ar[2].d is now equal to 1
Ar[0].d is now equal to 2
Ar[1].d is now equal to 2
...
...


I'll be very glad if someone can tell me where I do wrong. I'll go crazy with this sh.t.
Thanks.
 
Last edited:
Level 4
Joined
Aug 9, 2004
Messages
70
Ok I guess you got a little confused, so I'm changing "i" inside the struct to "d". I will edit the first post.

This is not the whole code, just imagine that,
ArTemp[1], ArTemp[2], ArTemp[3] have got values at somewhere else in the code. So they are not empty. Set sample = ArTemp enables me to load the values inside of the ArTemp to sample, so the code is not wrong.
 
Level 4
Joined
Aug 9, 2004
Messages
70
I get the messages because I set it in the original code.

And I found out what's wrong. Again, in the original code I made the unit u in the struct as "static". The reason I do that is I got compiling error messages when I use, GetUnitName(sample.u) in somewhere. It tells me that I can't do that because u is not static. So making u static causes my problem to happen.

Sorry to take your time guys. Thanks for trying to help me. My bad.
 
Status
Not open for further replies.
Top