Card Game Help

B

bondfish

Guest
I am trying to create a simple program in which you draw cards from a deck randomly and when they show up they get deleted until there are no cards left. I got them to show up randomly but need help deleting them.
here is the code.

CREATE:
//52 is showing the back of the cards at the start
image_index = 52;
image_speed = 0;


STEP:
space = keyboard_check_pressed(vk_space);



card_number = random(51)
//ds list

deck = ds_list_create();

for( var i = 0; i<51; i++)
{
ds_list_add(deck,i);
}

ds_list_shuffle(deck);

//Random card shown
if(space){
image_index = ds_list_find_value(deck, card_number);
}
 
A

Aura

Guest
In case you missed the edit, for I was slow. ^^"

Edit: That might lead to issues anyway. Do this instead:

Code:
var card_number = irandom(ds_list_size(deck) - 1);
image_index = ds_list_find_value(deck, card_number);
ds_list_delete(deck, card_number);
 
B

bondfish

Guest
Tried that too it still just loops around picking the same cards not getting rid of them
 
B

bondfish

Guest
ive been thinking that it needs to be if the card number comes up, you shouldnt come up again. except i dont know how to do that
 

Mercerenies

Member
The problem is that you create a new deck in the step event. If you want cards to disappear from the deck, you need to use the same deck, not make a new one each time.
 
B

bondfish

Guest
thank you! that was the problem moved everything to the create event.
 
Top