Skip to main content
GameDev.net gamedev.net
🔒 Locked

Really annoying BUG

Started by bikola_p Mar 23, 2006 at 5:49 AM 3 replies 550+ views
Original Post
bikola_p
bikola_p
Hello, im getting raelly frustrated at this bug, i cant seem to figure out what im doing wrong. I recieve no compile errors however, when i run the following piece of code. Which is a member function of a class. I can only run it once, the second time irun it, the program exits after printing STUCK HERE hundreds of times. I figured the value_suit array was filled with true's hence jump to the else. SO i wrote a function which initializes all back to false after first running. value_suit is a global variable so its not like each card object requires the array to be re-initialized. I still get hundreds of STUCK HERE's (which i put there for debugging) and the program jumps out and quits. However even though this class is being used by another class which runs in a loop for about 20 times. So not only does it stop the execution of the program, it some how gets out of the loop without passing this point. Any and every bit of help will be very much appreciated. Here is the code of the member function causing the prob.


Card::card_checker(){
	if (value_suit[possible_value][possible_suit] == false)
	{
		value_suit[possible_value][possible_suit]= true;
		setValue(possible_value);
		setSuit(possible_suit);
		
	}
	else
	{
		cout<<"STUCK HERE!!";
		create_card();
		return 0;       //do not set the Value or Suit of Card
	}

	return 0;
};
I even tried commenting out the return 0; in the else clause, however it didnt fix anything. So i put it back for my program to run perfect each and everytime, but that aint happening atm.
Nitage
Nitage
Does create_card call card_checker?
bikola_p
bikola_p
Yes, create card calls card_checker()
Codarki
Codarki
Once you get into the else block, unless you change the possible_value, possible_suit or the value indexed by them, you keep calling card_checker() (by creating a card) until crash. It doesn't ever get to return.

Also, this function doesnt need to return value.
bikola_p
bikola_p
umm, there seems to be problem. I cant simply change the index of the possible_value and suit. This is so when i randomly generate a suit and value, the function checks if the value and suit is the only one of its kind in the deck of cards. So once it sees card 5 of spades exists, it goes back to create_card, to generate new value and suit.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.