vJass Struct Bug?

Dangerb0y

New Member
Reaction score
0
Maybe someone can help me understand why this is happening. It makes no freaking sense to me! :nuts:

Don't ask me how I got to this point, but say for example that you have the following script...

JASS:
scope test initializer init

private struct data
    unit u
endstruct

globals
    private data array d
endglobals

private function testactions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local data d1
    local data d2
    set d1 = data.create()
    set d1.u = u
    set d[0] = d1
    set d2 = data.create()
    set d2.u = u
    set d[1] = d2
    set d1 = d[0]
    set d2 = d[1]
    call BJDebugMsg( GetUnitName(d1.u) )
    call BJDebugMsg( GetUnitName(d2.u) )
    set d1.u = null
    call d1.destroy()
    set d2.u = null
    call d2.destroy()
    call BJDebugMsg( GetUnitName(d1.u) )
    call BJDebugMsg( GetUnitName(d2.u) )
    set d1 = data.create()
    set d1.u = u
    call BJDebugMsg( GetUnitName(d1.u) )
    call BJDebugMsg( GetUnitName(d2.u) )
endfunction

private function init takes nothing returns nothing
    // etc...
endfunction

endscope


Let's call the trigger unit "Bob". If I looked at that script I would be willing to bet my mother that when the testactions function is called, it would print:

Bob
Bob
(null)
(null)
Bob
(null)


Right? My mom sure wouldn't think so. For some reason it displays this:

Bob
Bob
(null)
(null)
Bob
Bob
<- notice the "Bob" that should be a "(null)"

Is this a bug? or is it working as it should be and I'm just not understanding exactly how structs function behind the scenes?
 

Laiev

Hey Listen!!
Reaction score
188
JASS:
private function testactions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local data d1 = data.create()
    local data d2 = data.create()

    set d1.u = u
    set d[0] = d1

    set d2.u = u
    set d[1] = d2

    set d1 = d[0] //why you set the value of the struct to the value of struct?
    set d2 = d[1] //ditto

    call BJDebugMsg( GetUnitName(d1.u) ) //should return right
    call BJDebugMsg( GetUnitName(d2.u) ) //ditto

    set d1.u = null //you don&#039;t need to null because struct member = globals
    call d1.destroy()
    set d2.u = null //ditto d1.u = null
    call d2.destroy()

    call BJDebugMsg( GetUnitName(d1.u) ) //should return null because u = null
    call BJDebugMsg( GetUnitName(d2.u) ) //ditto

    set d1 = data.create()
    set d1.u = u

    call BJDebugMsg( GetUnitName(d1.u) ) //should return right
    call BJDebugMsg( GetUnitName(d2.u) ) //should return any value because you don&#039;t create it, in other vision, it store the name of the old unit
endfunctiona
 

Dangerb0y

New Member
Reaction score
0
Ok sure, I didn't condense it to its simplest form, but that still doesn't explain why setting the 0 index of an array would affect the 1 index at all. I've just tested this phenomenon with a basic global unit array without structs, and it worked like it should.

I understand that vJASS isn't 100% perfect as you can only make JASS do so much before it becomes ASS - I am just curious as to whether this is in fact an issue/bug, or if for some reason this IS what is meant to happen in this situation. Food for thought...
 

Romek

Super Moderator
Reaction score
963
What's meant to happen? Bugs.

What happens? Bugs.

The conclusion? Don't 'use' destroyed structs.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      • Ghan
        Administrator - Servers are fun

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top