I'm working on a card game and I was trying to make a function that sets 7 attributes to the card sprites 7 variables as each card is dealt.
If I do it manually (without using a function) it works fine, but if I take the code and make it a function ("setcard") it ends up picking and setting the variables to the card instance before (one less than) the one it should set.
I'm not on my computer, but it looks something like this:
function "deal cards"
if counter < 5
spawn card sprite
set card sprite randomly from deck array
*right here is the issue. without using the function it's something like
set var 1 from array
set var 2 from array (and so on..)
wait 0.4 seconds (so it doesn't deal them all simultaneously)
I then add one to the counter variable (so it'll know when to stop dealing)
and then I recall "deal cards"
this works perfectly.
but as I'm going to be setting those 7 attributes each time a card is dealt, I wanted to replace
set var1 from array
set var 2 from array (and so on..)
with a function ("setcard") which contains the exact same code
but when I do that, it ends up setting each card with the variables that should be on the card next to it, and the last card dealt's variables all end up unset (0).
Could someone explain to me why calling a function filled with the code, and replacing the function call with the exact same code is not the same thing in this case?