• 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 Array Bug

Status
Not open for further replies.
Hello again o/
I've been learning vJass. I found it simple, as I already knew Jass quite well.

But I'ge got stuck with a strange bug... I have:
JASS:
struct Heroi
    integer t
    boolean Disp
    string Icone
    
    unit u
    player Owner
    integer id
    timer Tim
    integer Revive
endstruct

globals
    Heroi array Herois
endglobals

private function DefinirHeroi takes integer i, integer t, boolean random, string icone returns nothing
    call Herois[i].create()
    set Herois[i].t = t
    set Herois[i].Disp = random
    set Herois[i].Icone = icone
    call BJDebugMsg(I2S(i) + " set to " + GetObjectName(t))
endfunction

function InicializarHerois takes nothing returns nothing
    call DefinirHeroi( 0, 'H000', true, "ReplaceableTextures\\CommandButtons\\BTNAssassin.blp" )
    call DefinirHeroi( 1, 'H001', true, "ReplaceableTextures\\CommandButtons\\BTNHeroAvatarOfFlame.blp" )
endfunction

function GetHeroId takes integer t returns integer
 local integer i = 0
    loop
        exitwhen i > 20

        call BJDebugMsg("Check " + I2S(i) + ": " + GetObjectName(Herois[i].t))
        if Herois[i].t == t then
            call BJDebugMsg("true")
            return i
        endif

        set i = i + 1
    endloop
 return -1
endfunction

If I use GetHeroId( 'H000' ), I get 20 messages saying: Check x: Volcano (the name of the hero 'H001').
So, ALL INDEXES of Heroi[] are changed when I use DefinirHeroi(...)

Why does that happen?
 
Level 13
Joined
May 11, 2008
Messages
1,198
your comment about your trigger talks about a variable array called Heroi but that's the name of your struct and Herois is the name of your variable. i'm guessing you just made a typo, but i figured the least, and well, frankly, the best i could do was that. you seem to know more about structs than i do if you're trying to use them.
 
your comment about your trigger talks about a variable array called Heroi but that's the name of your struct and Herois is the name of your variable. i'm guessing you just made a typo, but i figured the least, and well, frankly, the best i could do was that. you seem to know more about structs than i do if you're trying to use them.

Yep, sorry for similar names xD
I will change the name of the struct to upper case, thanks anyway :p

This line call Herois[i].create() should be replaced by this line: set Herois[i] = Heroi.create()

May your God save you as you saved me o/

Thanks, +rep both
 
Status
Not open for further replies.
Top