This site requires JavaScript, please enable it in your browser!
Greenfoot back
CrazyGamer1122
CrazyGamer1122 wrote ...

2012/6/25

Counter Trouble

1
2
CrazyGamer1122 CrazyGamer1122

2012/6/25

#
I am trying to add a counter to my game, but i keep getting a error message about the actor knot knowing a variable "Counter" even though i gave it a reference to the counter already. Can anyone help me?
erdelf erdelf

2012/6/25

#
could you give us your code?
CrazyGamer1122 CrazyGamer1122

2012/6/25

#
yeah sure..... if you play the one I uploaded it is different from the one i am giving you though.... (added a "you-win" when you eat the burger.... removed the burgers move() act for testing purposes..... only one alligator.) *bugs*-- the person transforms into the you-win sign and therefore can still be eaten by the alligator. i will upload the code shortly
CrazyGamer1122 CrazyGamer1122

2012/6/25

#
okay... i have updated the game so that the source code is published
CrazyGamer1122 CrazyGamer1122

2012/6/25

#
i published the source code with the game----- just open it in G-foot
CrazyGamer1122 CrazyGamer1122

2012/6/25

#
also, when i uploaded the code..... I had already deleted the counter because it didn't work.
davmac davmac

2012/6/26

#
also, when i uploaded the code..... I had already deleted the counter because it didn't work.
There's not much point at us looking at it then, right...? You can post code snippets here in the discussion, it's often the easiest way to share code. Just make sure that you use the 'code' tags (click 'code' and copy/paste your code), that you indent your code properly, and that you make it clear which line you're getting the error on.
CrazyGamer1122 CrazyGamer1122

2012/6/26

#
oh..... i probobly should have thought of that...... i feel dumb now :|
CrazyGamer1122 CrazyGamer1122

2012/6/26

#

import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
/**
 * Write a description of class Counter here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Counter extends Actor
{
private int score;
  public Counter()
  {
      score = 0;
      setImage (new GreenfootImage(200, 30));
      update();
  }   
  
  public void addScore()
  {
    score++;
    update();
  }
  
  public void update()
  {
    GreenfootImage img = getImage();
    img.clear();
    img.setColor(Color.WHITE);
    img.drawString("Score: " + score, 4, 20); 
    
  }      
}

CrazyGamer1122 CrazyGamer1122

2012/6/26

#
there's the code for the counter
erdelf erdelf

2012/6/26

#
what was your error, again? I implemented it unchanged in your scenario and it works fine
CrazyGamer1122 CrazyGamer1122

2012/6/26

#
the counter wont count up when the man eats the burger
CrazyGamer1122 CrazyGamer1122

2012/6/26

#
"person cannot find variable counter" or something along those lines
erdelf erdelf

2012/6/26

#
oh ok, that's because you didn't wrote it. You didn't wrote that it should add Score
CrazyGamer1122 CrazyGamer1122

2012/6/26

#
as i said before, i deleted that part of the code because it didn't work.
There are more replies on the next page.
1
2