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

2024/12/9

Restaurant Game

BYY BYY

2024/12/9

#
if(Greenfoot.isKeyDown("space")) { if(isTouching(Cheeseburger.class)) { if(order == 1) { points++; } else { points++; } getWorld().showText("Points:" + points, 100,45); } else if(isTouching(ChickenSandwich.class)) { if(order == 2) { points++; } else { points--; } getWorld().showText("Points:" + points, 100,45); } else if(isTouching(FrenchFries.class)) { if(order == 3) { points++; } else { points--; } getWorld().showText("Points:" + points, 100,45); } else if(isTouching(Soda.class)) { if(order == 4) { points++; } else { points--; } } } This code keeps subtracting from the points, even if you click on the right food. The variables were created in another class.
danpost danpost

2024/12/9

#
BYY wrote...
i<< Code Omitted >>This code keeps subtracting from the points, even if you click on the right food. The variables were created in another class.
What do you mean by "variables were created in another class"? You cannot refer to a variable from one class in a different class just by using its declared name. You either need to prefix the variable name with a reference to an object of that class it is declared in or the class name itself (depending on the properties of the variable). There may be another issue, in that you do not seem to be removing any objects touched -- meaning that each act that the touching occurs, which will probably be several to many, the increment/decrement actions will occur multiple times during one touching (depending on how long that touch lasts).
You need to login to post a reply.