Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
[SOLVED] What's wrong with my code?
-
@Pythonistapro777 Please don't open multiple topics for the same thing. You can edit your existing posts (or reply to them) if you need to add more details or clarify something.
-
Sorry
-
Lmao, I still need help
-
Here's a very simple scene that counts clicks/touches, hope that helps:
from scene import * clicks = 0 class ClickScene(Scene): def touch_began(self, touch): # the "global" keyword is important here: global clicks clicks += 1 def draw(self): background(0, 0, 0) text('Clicks: %i' % clicks, 'Helvetica', 30, self.size.w/2, self.size.h/2, 5) run(ClickScene())
-
I NEED HELP AGAIN!!!
-
@omz what can I do about the global error
-
What "global error"? You need to be a little more specific.
-
When the code is run there is a global error on the text().
-
Why not in your setup method, just do self.clicks = 0. Then reference self.clicks thereafter. I had to do that before in your previous code to get it to run. No need for the global.
-
This should work
from scene import * #clicks = 0 class ClickScene(Scene): def setup(self): self.clicks = 0 def touch_began(self, touch): # the "global" keyword is important here: #global clicks #clicks += 1 self.clicks += 1 def draw(self): background(0, 0, 0) # clicks, changed to self.clicks below text('Clicks: %i' % self.clicks, 'Helvetica', 30, self.size.w/2, self.size.h/2, 5) run(ClickScene())
-
Man, stop writing in caps and pretending answers like a little kid -.-
-
😑
-
So much for your help @filippocld
-
The global error in the original script is caused by the fact that the first
click
is singular (without an 's') and the secondclicks
is plural (with an 's') so they are not the same variable. -
Changed the question.
-
Add the following line as the last line of
setup()
:self.add_layer(self.button)
This will make the counter update but you will have a screen refresh problem to solve. See the
draw()
methods that @omz and @Phukett2 have provided above for a partial answer to your refresh problem. -
THANK YOU!
-
I figured out how to fix the screen refresh error.
Thanks a lot everyone!