My score always stays at zero

It compiled and it is still wrong

My score always stays at zero

This page is part of Intro to Java with Greenfoot. It assumes you have reached lesson 3.8. Opening it is not counted against you and is not tracked as progress.

What it actually means

The score variable is declared inside act(), so it is rebuilt from scratch every frame and never remembers anything.

The usual causes

Ranked by how often each one turns out to be the answer. Work down the list.

  1. The declaration is inside act(). Every frame starts by setting it back to zero.
  2. The variable is declared inside an if block, so it disappears when the block ends.
  3. The score is being displayed from a different object than the one counting.

How to fix it

Move the declaration out of act() and into the class body, beside the other fields and outside every method. That one move is usually the whole fix. Assign the starting value there or in the constructor.

Get in Touch

Whether you're a student, parent, or teacher — I'd love to hear from you.

Just want free AP CS resources?

Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.

Typically responds within 24 hours

Message Sent!

Thanks for reaching out. I'll get back to you within 24 hours.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

[email protected]

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at [email protected]