Array in vJASS

Dryvnt

New Member
Reaction score
10
How do i make arrays in vJASS? (Or just JASS in general)

I need this for a WIP system :)
 

Azlier

Old World Ghost
Reaction score
461
JASS:
function lol takes nothing returns nothing
    local integer array i
    local integer index = 0
    loop
        exitwhen index == 10
        set i[index] = index
        set index = index + 1
    endloop
endfunction


Here's an example of creating an integer array known as 'i' and setting indexes one through ten to a number.
 

phyrex1an

Staff Member and irregular helper
Reaction score
447
JASS:
local type array name

JASS:
globals
     type array name
endglobals

Note that an array isn't an object like in other languages so you can't pass it as an argument to other functions. I suppose vJass has some solution for that such as struct with arrays or maybe dynamic arrays, check the documentation.
 

Azlier

Old World Ghost
Reaction score
461
By any chance, did you originally have the keyword 'array' before the type? That's what I think I saw and was going to comment on, but I checked back and it wasn't so. Now I'm befuddled (that's a real word!).:confused: Oh, and you bumped my rep up drastically. Wow.
 

Dryvnt

New Member
Reaction score
10
It wont work... Nothing happens... Have i done something wrong?

JASS:
globals
real array wut
endglobals

function Harh takes nothing returns nothing
    local integer lol
    set wut[0] = 1
    set wut[1] = 2
    set wut[2] = 3
    loop
    exitwhen lol > 2
        call BJDebugMsg(R2S(wut[lol]))
        set lol = lol + 1
    endloop
endfunction

//===========================================================================
function Test takes nothing returns nothing
    local trigger trig = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( trig, 1.00) 
    call TriggerAddAction( trig, function Harh )
endfunction
 

Azlier

Old World Ghost
Reaction score
461
Give the integer 'lol' an initial value of zero. Computers find it difficult to calculate a value that doesn't quite exist.

Oh, and you can't use a globals block without NewGen. Bah, let me rewrite it.

JASS:
function Harh takes nothing returns nothing
    local integer lol = 0
    local integer array wut
    set wut[0] = 1
    set wut[1] = 2
    set wut[2] = 3
    loop
    exitwhen lol > 2
        call BJDebugMsg(I2S(wut[lol]))
        set lol = lol + 1
    endloop
endfunction

//===========================================================================
function Test takes nothing returns nothing
    local trigger trig = CreateTrigger(  )
    call TriggerRegisterPlayerEvent(trig, Player(0) ,EVENT_PLAYER_END_CINEMATIC)
    call TriggerAddAction( trig, function Harh )
endfunction


To use that, simply press Escape ingame.

ALERT: You need your Test function to be named InitTrig_<Exact trigger name here>

Otherwise, it won't initialize... another reason why NewGen is so lovely.
 
Reaction score
456
JASS:
scope MyScope initializer Test

function Harh takes nothing returns nothing
    local integer lol = 0
    local integer array wut
    set wut[0] = 1
    set wut[1] = 2
    set wut[2] = 3
    loop
    exitwhen lol &gt; 2
        call BJDebugMsg(I2S(wut[lol]))
        set lol = lol + 1
    endloop
endfunction

//===========================================================================
function Test takes nothing returns nothing
    local trigger trig = CreateTrigger(  )
    call TriggerRegisterPlayerEvent(trig, Player(0) ,EVENT_PLAYER_END_CINEMATIC)
    call TriggerAddAction( trig, function Harh )
endfunction

endscope


Function 'Test' has to run at some point.
 

Azlier

Old World Ghost
Reaction score
461
Well, there you go. Just make sure that those functions are private.
 

Dryvnt

New Member
Reaction score
10
Thanks, this is really important to my system...

If i don't have any other questions (But i'm 99% sure i will) you guys wont hear from me in 1-3 days or more :p...
But who cares.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top