Skip to main content

The Power of Pride Bundle 2026 — $10 PWYC Edition
On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Unclear how to pass arrays to procs & use them inside the proc

A topic by JavaJack created 4 days ago Views: 19 Replies: 1
Viewing posts 1 to 2

I have a 1D array of u8 and I want to write a "shuffle" proc to shuffle it like a deck of cards. As a stepping stone to this I tried something simpler:

proc shuffleArr(arr as addr of u8)
    arr[2] = 99 'just to see if I can do ANYTHING with the passed array
endproc
This doesn't compile:

 'arr' is a scalar variable, not an array or STRING; remove the index

Almost certainly user error on my part, but not clear how to proceed.

(+1)

Hey Javajack, yes, you can do what you are trying to do, but `ARR AS ADDR OF U8` is an address parameter, not an array parameter. So inside the PROC you use PEEK/POKE with address math instead of ARR[I].

PROC SHUFFLE(ARR AS ADDR OF U8)      
    VAL AS U8
    POKE ARR + 2, 99          ' write 99 to the 2nd index of ARR (3rd element 0 based)
    V = PEEK(ARR + 2)         ' read it back  
ENDPROC

then call that with the address of the array

  DECK[51] AS U8
  SHUFFLE(ADDR(DECK))     ' or SHUFFLE(&DECK)

Array indexing on an address parameter, like ARR[2] or ARR(2), is not supported currently. I think I would like that too, for now you'd use PEEK/POKE.

For a real shuffle you pass the length too to handle the bounds of the array

SHUFFLEARR ADDR DECK, LEN(DECK)

thanks for the question!