Trying to make a basic Python score counter in a game... will not count.

D

Darrien Glasser

Hey guys, I'm working on a Python rock paper scissors (lizard spock) game, and the beginning is complete. After I finished it, I thought, "You know what? I think I can make this even better, and add a score counter." And so I did.

The problem is that it doesn't seem to actually keep track of score. In fact it always keeps the score at 0 for both players. It's fully functional otherwise, but it's bothering me that I can't get it to work.

Currently using Windows Python 32 bit v2.6.8

Download of the code here:

https://www.box.com/s/2lupxeyk5jvsxs0zkdfb

Copy of the code here:

http://pastebin.com/MNdgiuSY

Thanks in advance for your help...
 
K

Kwpolska

Hey guys, I'm working on a Python rock paper scissors (lizard spock) game, and the beginning is complete. After I finished it, I thought, "You know what? I think I can make this even better, and add a score counter." And so I did.

The problem is that it doesn't seem to actually keep track of score. In fact it always keeps the score at 0 for both players. It's fully functional otherwise, but it's bothering me that I can't get it to work.

Currently using Windows Python 32 bit v2.6.8

Download of the code here:

https://www.box.com/s/2lupxeyk5jvsxs0zkdfb

Copy of the code here:

http://pastebin.com/MNdgiuSY

Thanks in advance for your help...

winx = winx + 1
winy = winy + 1

PS. please do not use pastebin.com.
 
R

rurpy

Hey guys, I'm working on a Python rock paper scissors (lizard spock)
game, and the beginning is complete. After I finished it, I thought,
"You know what? I think I can make this even better, and add a score
counter." And so I did.

The problem is that it doesn't seem to actually keep track of score.
In fact it always keeps the score at 0 for both players. It's fully
functional otherwise, but it's bothering me that I can't get it to
work.

Currently using Windows Python 32 bit v2.6.8

Download of the code here:
https://www.box.com/s/2lupxeyk5jvsxs0zkdfb

Copy of the code here:
http://pastebin.com/MNdgiuSY

If you are keeping the score in 'winx 'and 'winy' then you are adding
one to the the values but not saving the results.

I think you want

winx = winx + 1

or more concisely,

winx += 1
 
T

tbg

Actually, I was just going to post that it wasn't saving the scores. Great timing, I'll try it.
 
T

tbg

If you are keeping the score in 'winx 'and 'winy' then you are adding

one to the the values but not saving the results.



I think you want



winx = winx + 1



or more concisely,



winx += 1

I changed it so that it said winx += 1 etc. and it doesn't seem to save it. I also tried pulling the variables from the loop and making them global variables at the top.

The latter game me a traceback error when printing out the results. Any ideas?

http://puu.sh/1BCbG

Code Preview/Download

https://www.box.com/s/jiu0259nohx0kae2am57
 
T

tbg

Put this on top of your function:



global winx, winy





PS. Why did you put those delays in? They are useless.

--

Kwpolska <http://kwpolska.tk>

stop html mail | always bottom-post

www.asciiribbon.org | www.netmeister.org/news/learn2quote.html

GPG KEY: 5EAAEA16

I figured it would be too much for the person playing the game. Getting attacked with lines of text and all. Although it is a pain developing with it.

And by the way, works perfectly now. Thanks for your help.
 
T

tbg

Put this on top of your function:



global winx, winy





PS. Why did you put those delays in? They are useless.

--

Kwpolska <http://kwpolska.tk>

stop html mail | always bottom-post

www.asciiribbon.org | www.netmeister.org/news/learn2quote.html

GPG KEY: 5EAAEA16

I figured it would be too much for the person playing the game. Getting attacked with lines of text and all. Although it is a pain developing with it.

And by the way, works perfectly now. Thanks for your help.
 
M

Mitya Sirenef

Hey guys, I'm working on a Python rock paper scissors (lizard spock) game, and the beginning is
complete. After I finished it, I thought, "You know what? I think I can
make this even better, and add a score counter." And so I did.
The problem is that it doesn't seem to actually keep track of score.
In fact it always keeps the score at 0 for both players. It's fully
functional otherwise, but it's bothering me that I can't get it to work.
Currently using Windows Python 32 bit v2.6.8

Download of the code here:

https://www.box.com/s/2lupxeyk5jvsxs0zkdfb

Copy of the code here:

http://pastebin.com/MNdgiuSY

Thanks in advance for your help...


I was actually thinking of making a simple rock paper scissors game so I
went ahead and cobbled it together, using a design with a class and
generally a structured approach.. It keeps the scores, too, and you can
set both players to be AI, or one to be AI, or both to be humans:

https://github.com/pythonbyexample/PBE/blob/master/code/rockpaper.py

(it needs python3 but can be easily changed to work with python2.x)


- mitya
 
T

tbg

complete. After I finished it, I thought, "You know what? I think I can

make this even better, and add a score counter." And so I did.



In fact it always keeps the score at 0 for both players. It's fully

functional otherwise, but it's bothering me that I can't get it to work.







I was actually thinking of making a simple rock paper scissors game so I

went ahead and cobbled it together, using a design with a class and

generally a structured approach.. It keeps the scores, too, and you can

set both players to be AI, or one to be AI, or both to be humans:



https://github.com/pythonbyexample/PBE/blob/master/code/rockpaper.py



(it needs python3 but can be easily changed to work with python2.x)





- mitya

Well there goes my hopes and dreams of being the first one to do that. Nice job by the way.
 
T

tbg

complete. After I finished it, I thought, "You know what? I think I can

make this even better, and add a score counter." And so I did.



In fact it always keeps the score at 0 for both players. It's fully

functional otherwise, but it's bothering me that I can't get it to work.







I was actually thinking of making a simple rock paper scissors game so I

went ahead and cobbled it together, using a design with a class and

generally a structured approach.. It keeps the scores, too, and you can

set both players to be AI, or one to be AI, or both to be humans:



https://github.com/pythonbyexample/PBE/blob/master/code/rockpaper.py



(it needs python3 but can be easily changed to work with python2.x)





- mitya

Well there goes my hopes and dreams of being the first one to do that. Nice job by the way.
 
M

Mitya Sirenef

Well there goes my hopes and dreams of being the first one to do that. Nice job by the way.

Well you were the first :) I just did it to illustrate a modular
approach, I think a
simple game like that is a great learning opportunity.

I posted an update with some small cleanups just now..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,516
Members
44,983
Latest member
BuyX10BoostKeto

Latest Threads

Top