![]() |
Tried to make a guessing game, what do u think?
So I just started a week ago to learn php. Today I tried to make a guessing game.My first tryout :D
What do u think? PHP Code:
|
One problem, karq, and that is your number (not the guess) doesn't persist. This means that if the number is 1 the first time and I say 3, the returned message is that the number is smaller. So, next time I pick 2 ... only to have it tell me the number is bigger.
Try using a cookie to make the random number persist. PHP Code:
arva. Now it'll persist between guesses and you can get it right. :-) |
Thanks to my ability to speak PHP I can more or less understand the estonian, and you could also use sessions
|
So I made 2 games 1 with cookies and 1 with sessions.
Here are the codes: Cookies: PHP Code:
PHP Code:
Maybe U can explane to me why thosent it change the number with this code: PHP Code:
PHP Code:
|
Sure.
What the script does, is it checks if a cookie named "arva" is set. If it is your first visit/guess with a new browser session (IE, the browser was closed before running the script) then it knows the cookie isn't there, and it sets "arva" to be a random number. It then pulls from the cookie the random number for the script's use. The other one, your original one, always sets "arva" to be a random value. This value is never saved anywhere in your script. Thus, if you run it again you have a different number--in fact, your last answer could have been right this time. That is the basic explanation of the two executions. |
| All times are GMT. The time now is 07:37 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0