(See the best response by DarkCampainger.)
for(var/obj/card/c in client.screen)
c.layer = OBJ_LAYER
client.screen -= c //remove all cards from screen.

var/hand_length = 1
while(hand_length <= hand.len)
var/obj/card/c = hand[hand_length]
c.layer = MOB_LAYER+1

for(var/obj/hand/h in client.screen)
if(istype(h, text2path("/obj/hand/h[hand_length]")))
screen_spot = h

c.icon = c.hand_icon
screen_spot.card = c
c.screen_loc = screen_spot.screen_loc
client.screen += c
hand_length ++

Problem description:
Pretty much what I am using seems fine, but I have narrowed it down to what seems to be this block of code. I can't be 100% certain though, as whatever it is is crashing the game so much I can't even read the error messages.

Anyways, the point of this block of code is to add cards to a screen based on the cards in the player's list; "hand". Does anyone see any reason why this code could potentially cause an infinite loop?


Also it might be worth mentioning that I call this procedure everytime I add a new card to the hand, so this means if I were to draw 5 cards at the beginning of a game, it would call this block 5 times (including sleep(10) between each draw card to add to the effect).

EDIT: Also this Update_Hand() procedure actually does work entirely, but when I end a game and start a new one, the issue seems to stem from here. I am not sure why though.
Best response
What do you mean by crashing? Does the game close, or are you getting the "further runtimes are being suppressed" message?

I don't see any obvious problems with that code. The only errors I could see appearing are if the hand list is null or contains null entries, or there are more cards in the hand than screen_spot types to hold them (all of which would give you "cannot read null.[var]" errors). I don't see any infinite loops.

Can you show us how you're clearing the hand card list?
        Draw_Card(mob/player, n)

if(player.hand.len > 17)
player << "\red Hand is full, so discarding top card of deck."
player.deck -= player.deck[1]

player.hand += player.deck[1]
player.deck -= player.deck[1]
world << "update hand was a success [player] ([n])"
world << "\red [player] has ran out of cards to draw!"

I have removed all the unrelated parts to make the code easier to read. At the end of a card game, I remove the hand list by using hand.Cut() followed by Update_Hand() to remove the images of the cards from the screen. I have not had any issue stump me for this long.

Here's the other interesting thing: I do not receive any error messages, the game completely freezes until I close out of it - including moving icons etc.

When I try to start the second battle, it seems to happen with the last card being drawn that it actually freezes; all the others are successful. I have made sure I have a deck, and that there are no cards in my hand already with debugs. Also the amount of screen_spots is 1 to 18, so I cannot see it being that - it is always the last card regardless of how many I draw before stopping.


I used to have you added on MSN many years ago, we tried to make a fishing game :). Do you remember?
Problem solved. Thanks DarkCampainger for helping me through the debugging process!