HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Simple question

10-19-2008, 09:37 PM#1
Flame_Phoenix
Hi guys, I have a global item array. The problem here is that I need to pass it as an argument to another function. Is there a way I can do it ?
10-19-2008, 09:49 PM#2
the-thingy
You want to pass the whole array? You could take the topmost used array index as a parameter, and loop through all items from 0 to parameter i.e.
Collapse JASS:
function LoopThroughArray takes integer topIndex returns nothing
  local integer i = 0
  loop
  exitwhen i > topIndex
    call DoSomethingWithArray (variable[i])
    set i = i + 1
  endloop
endfunction
10-19-2008, 11:07 PM#3
Bobo_The_Kodo
Collapse JASS:
type ItemArr extends item array[500]

globals
    ItemArray anArray
endglobals

function bar takes ItemArr IA returns nothing
    call ShowItem( IA[2], false )
endfunction

function foo takes nothing returns nothing
    set anArray = ItemArr.create()
    call bar( anArray )
endfunction
10-20-2008, 08:19 AM#4
Flame_Phoenix
Oh, I can't use vJASS btw ....
And I need to pass the array, or at least an identifier of it.
My main problem is that I have 3 item arrays and I have code to manage them. However, the code doesn't know which array to change, and it must know.

Is there a way to define an identifier for a global array that can be used as a parameter ?
Like if I receive parameter A I know I must change array A =S
10-20-2008, 08:27 AM#5
Gwypaas
make the function take an extra integer and then make the function use ifs to compare the integer and then use the right global array.

like
Collapse JASS:
function SomeFunction takes integer n returns nothing
     if n == 1 then
          call DoSomeThingWithArrayA()
     elseif n == 2 then
          call DoSomethingWithArrayB()
     ......
endfunction
10-20-2008, 12:15 PM#6
the-thingy
So, you want to handle one of X arrays within the same function?

Collapse JASS:
function HandleItemArrayOne takes integer topIndex returns nothing
  local integer i = 0
  loop
  exitwhen i > topIndex
    call DoSomethingWithArray (variableOne[i])
    set i = i + 1
  endloop
endfunction
//And something identical for the other ones you need
//Or, see next JASS box

function HandleArray takes integer id, integer topIndex returns nothing
//Pretty much what Gwy did, except with a bit more excess above
  if id == 1 then
    call HandleItemArrayOne (topIndex)
  elseif id == 2 then
    call HandleItemArrayTwo (topIndex)
  elseif id == 3 then
    call HandleItemArrayThree (topIndex)
  endif
endfunction

Alternatively
Collapse JASS:
function HandleArray takes integer id, integer topIndex returns nothing
  local item array items
  local integer i = topIndex
  loop
  exitwhen i == 0
    if id == 0 then
      set items[i] = variableOne[i]
    elseif id == 1 then
      set items[i] = variableTwo[i]
    elseif id == 2 then
      set items[i] = variableThree[i]
    endif
    call DoSomethingWithItem (items[i])

    set items[i] = null
    set i = i - 1
  endloop
endfunction

If I'm understanding you correctly

Then, when removing items from the array (so that you're only looping through in-use values)
Collapse JASS:
set variableOne[thisItemsIndex] = items[Top]
set Top = Top - 1
10-20-2008, 02:36 PM#7
WNxCryptic
Quote:
Originally Posted by Flame_Phoenix
Oh, I can't use vJASS btw ....

Phail :(
10-20-2008, 02:56 PM#8
Anitarf
Try simulating a 2D array? Like, use one array variable for all of them, and then have indexes from 0 to 999 for array A, 1000 to 1999 for array B etc.
10-20-2008, 06:35 PM#9
Flame_Phoenix
Quote:
Try simulating a 2D array? Like, use one array variable for all of them, and then have indexes from 0 to 999 for array A, 1000 to 1999 for array B etc.
Quite useless if we keep in mind functions can't receive arrays as parameters.

Anyway, I found a solution, thx guys !
10-21-2008, 04:10 PM#10
dead_or_alivex
Order it to cast the spell that the custom spell is based off.
10-21-2008, 04:33 PM#11
Ammorth
Quote:
Originally Posted by The Dark One
I have a question, how do you use a trigger to make a unite cast a customized spell when all issuable commands are standard ones?

Second thread hi-jack, and on the same question as before: http://www.wc3campaigns.net/showthread.php?t=103074

please learn to read the forums before you ask for help, and for the love of god, don't steal other people's threads.

Quote:
Originally Posted by Flame_Phoenix
Quite useless if we keep in mind functions can't receive arrays as parameters.

Anyway, I found a solution, thx guys !

you would pass an integer and it would provide you with the starting point in the master array

Collapse JASS:
integer array Items
// 0-999 is array 0
// 1000-1999 is array 1
// 2000-2999 is array 2
// etc..

function DoSomethingWithArray takes integer arrayNumber, integer slot returns nothing
    set slot = slot*1000 // 0 will start at 0, 1 will start at 1000, etc..
    set Items[slot+arrayNumer] = someVal
endfunction

function Test takes nothing returns nothing
    call DoSomethingWithArray(0, 50) // array 0, slot 50
    call DoSomethingWithArray(3, 250) // array 3, slot 250
    call DoSomethingWithArray(4, 1222) // array 5, slot 222
    // careful when doing stuff outside of the size of the smaller arrays.
endfunction