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

[Solved] Array Sizes

Status
Not open for further replies.
Level 14
Joined
Dec 29, 2009
Messages
931
Hey guys, quick question. I've noticed people change the array size shown in the image below.

2lk4cwo.png


What I want to know is why bother changing it?
What does it do exactly?

I've used array variables many times before, and I've never once changed the value to anything other than 1.

What's up with that?

Any help provided is appreciated.
 
You just create them yourself when you need them... it's called instancing >.<

Or you initialize it yourself :\

It doing the initialization via creation is majorly messed up

edit
I hate GUI.. seriously, I want nothing to do with it ever. It's so awful... wow

JASS:
function InitGlobals takes nothing returns nothing
    local integer i= 0
    set i=0
    loop
        exitwhen ( i > 10 )
        set udg_test[i]=CreateTimer()
        set i=i + 1
    endloop

endfunction
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,255
The size field guarantees that size indices will be initialized. Reading from an uninitialized index causes a thread crash. Where this is useful is if you only ever need code that first reads the value and then writes something back (such as incrementing an integer). The size field saves you having to initialize it manually at some other time.

It is very bad for tasks where you write first and read back later. Examples are dynamic storage system (starts empty, you add data to it) or complex structures that you do not want to exist before they are required (you create a group on demand, not when the game starts).

Using a size of 16 is perfectly fine for an integer array counting player kills (you want it to start at 0 anyway).
Using a size of 1 is perfectly fine for an integer array that counts the cycles a custom ability will use that dynamically creates instances (you initialize the index to some number when the index is required for use).
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,255
You have any evidence at all to back that up? I have seen dozens of problems related to uninitialized variables causing a thread crash. Maybe it is uninitialized local variables but it seems strange that it should only be the one type and not the other.

Test function.
JASS:
globals
    integer test
endglobals

function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
    local integer test2
    call BJDebugMsg("local variable test")
    call BJDebugMsg(I2S(test2))
    call BJDebugMsg("global variable test")
    call BJDebugMsg(I2S(test))
    call BJDebugMsg("global to local variable signment test")
    set test2 = test
    call BJDebugMsg(I2S(test2))
endfunction
Only "call BJDebugMsg("local variable test")" is executed. The line "call BJDebugMsg(I2S(test2))" is causing a thread crash.

Attempt with globals...
JASS:
globals
    integer test
endglobals

function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
    local integer test2
    //call BJDebugMsg("local variable test")
    //call BJDebugMsg(I2S(test2))
    call BJDebugMsg("global variable test")
    call BJDebugMsg(I2S(test))
    call BJDebugMsg("global to local variable signment test")
    set test2 = test
    call BJDebugMsg(I2S(test2))
endfunction
Only "call BJDebugMsg("global variable test")" is executed. The line "call BJDebugMsg(I2S(test))" is causing a thread crash.

Now for arrays...
JASS:
globals
    integer array test
endglobals

function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
    local integer array test2
    call BJDebugMsg("local variable test")
    call BJDebugMsg(I2S(test2[0]))
    call BJDebugMsg("global variable test")
    call BJDebugMsg(I2S(test[0]))
    call BJDebugMsg("global to local variable signment test")
    set test2[0] = test[0]
    call BJDebugMsg(I2S(test2[0]))
endfunction
All of it runs. What this proves is that JASS is the biggest piece of garbage one can ever use. While what I did say does apply to non arrays, JASS some how thinks arrays are different and operates completely differently on them. From this, we can assume that this is a bug with arrays (it is meant to crash the thread but instead is reading raw memory values) probably as a result of an optimization.

You should always initialize a variable before using it. In JAVA it is illegal to use an uninitialized variable. In C/C++ uninitialized variables might have any kind of memory garbage written to them and are a very common cause of errors and crashes.
 
Last edited:
However there is no logical reason why reading from an uninitialized non-array will crash the thread yet reading from a non-initialized array does not.

I said nothing about scalars, nor did you. Your original statement was on arrays crashing the thread when they weren't initialized, and I called you on your bs. Scalars had nothing to do with this =).

There is no way you can interpret setting an index as a scalar, lol.
 
Level 7
Joined
Jan 22, 2013
Messages
293
This went from helping someone into a pissing contest. I found the thread rather entertaining from start to finish. Also I do believe ArchAnge1 only works in GUI. So yeah.. Jass in this thread doesn't help the owner of the thread.
 
Status
Not open for further replies.
Top