Help with Code ?

bruno1440

Member
Hi to all , first time posting here something .
I am trying to make a simple card game but i am having a problem with the " Hand Loop code "

just so you understand i am using Ds_lists , and when i click deck , it should read the last card value from the ds_list , save it on a variable called "topcard" and then read the Hand ( if there is any card already on the hand ) and add it.

so i have the following code on Left Button Press on object deck

GML:
global.handsize +=1
global.topcard = ds_list_find_value(global.playerdeck,0 );
ds_list_delete(global.playerdeck, 0);

for(var u=0; u<global.handsize; u++){
    global.hand[u] =global.topcard
    }
now the loop is not working because hand[0] , hand[1] when drawn , stay all with the same value..
the draw event is below:

GML:
draw_text(5,200,global.hand[0])
draw_self()
for(var f=0; f<global.handsize; f++){

    draw_text(5+(100*f), 200, global.hand[f]);
    }
Can you guys help figuring out the problem?

thanks !
 

Nidoking

Member
It would help if you put your code in CODE blocks so it doesn't turn into underlines. But global.topcard is a single card... why are you assigning it in a loop? If you want the top card each time through the loop, you'll have to read it each time.
 

TsukaYuriko

☄️
Forum Staff
Moderator
for(var u=0; u<global.handsize; u++){
global.hand =global.topcard
}
I'll take the liberty of fixing the formatting for you, because as it stands, this is entirely different code...

for(var u=0; u<global.handsize; u++){
global.hand[u] =global.topcard
}
... than this. ;) Please use [CODE=gml]code[/CODE] tags for code.


On to the problem...

All of the indices of the array are the same value because you set them to the same value. You set them to global.topcard, and you set its value once and then never change it.
 
Top