How can I pass the deck(52) array from the Newgame function to the deckshuffle function
FUNCTION newgame
'New game
RANDOMIZE TIMER
CALL cardsuit
'heart$ = CHR$(3): diamond$ = CHR$(4): club$ = CHR$(5): spade$ = CHR$(6)
quitgame = 0
DIM playercards(maxhand), dealercards(maxhand), deck(52)
END FUNCTION
FUNCTION deckshuffle
'first card
CALL carddeck(deck(1))
deck(1) = INT(RND * 52)
deckindex = 2
DO
DO
cardok = 1
newcard = INT(RND * 52)
FOR j = 1 TO (deckindex - 1) STEP 1
IF newcard = deck(j) THEN
cardok = 0
EXIT FOR
END IF
NEXT j
LOOP UNTIL cardok = 1
deck(deckindex) = newcard
deckindex = deckindex + 1
LOOP UNTIL deckindex > 52
deckindex = 1
PRINT "* * * DECK SHUFFLED * * *"
END FUNCTION
currently I'm getting an "Array not defined" error when I attempt to execute the program.
You pass an array to a
SUBorFUNCTIONby adding parentheses to the sub/function argument when you call it, as indeck()below:I'm not entirely certain what
PRINT deckshuffle(deck())should display, so I'm reasonably certain you meant to makedeckshuffleandnewgamesubs, not functions. After all, a function is meant to return values. You should use a sub if there is no return value.Also, your functions have no arguments defined, which is why you're probably getting an error:
You can also use
DIM SHAREDin your main program (outside any subs/functions), and you'll no longer need to worry about sub/function parameters: