firedealer Posted April 24, 2011 Share Posted April 24, 2011 I'm new to function and I can't figure how to update/result the score. I developed a game called Rock, Paper, & Scissors, so I can learn the function itself with a simple game for now. http://pastebin.com/9MB7ATnt Any tips or instruction would be much appreciated. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/234550-score-updateresult-via-function/ Share on other sites More sharing options...
Fadion Posted April 24, 2011 Share Posted April 24, 2011 All I can see from the code is a bunch of functions, but you've given no questions. What are you trying to achieve? What do you mean by updating the score? Quote Link to comment https://forums.phpfreaks.com/topic/234550-score-updateresult-via-function/#findComment-1205412 Share on other sites More sharing options...
firedealer Posted April 24, 2011 Author Share Posted April 24, 2011 I'm try to make a score increment every time win, lose, or tie the game. Quote Link to comment https://forums.phpfreaks.com/topic/234550-score-updateresult-via-function/#findComment-1205417 Share on other sites More sharing options...
Fadion Posted April 24, 2011 Share Posted April 24, 2011 Take a look: http://pastebin.com/4PNmDyKq I added some global data storage with SESSIONs to store wins, loses and ties. There's a lot to be optimized with your script (and my modifications), but at least it works Quote Link to comment https://forums.phpfreaks.com/topic/234550-score-updateresult-via-function/#findComment-1205428 Share on other sites More sharing options...
firedealer Posted April 24, 2011 Author Share Posted April 24, 2011 Ah $_SESSION is the key. The score is working. However, the error come up which is Notice: "Undefined index: win in /Applications/MAMP/htdocs/sandbox/games/duelingcards/main_rockpaperscissors_session.php on line 57" Quote Link to comment https://forums.phpfreaks.com/topic/234550-score-updateresult-via-function/#findComment-1205433 Share on other sites More sharing options...
firedealer Posted April 24, 2011 Author Share Posted April 24, 2011 Eh, I just added: $_SESSION['win'] = empty($_SESSION['win']) ? NULL : $_SESSION['win']; $_SESSION['lose'] = empty($_SESSION['lose']) ? NULL : $_SESSION['lose']; $_SESSION['tie'] = empty($_SESSION['tie']) ? NULL : $_SESSION['tie']; Now, it's working without any glitch or burp. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/234550-score-updateresult-via-function/#findComment-1205435 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.