Coding Global Background
Coding Global

need help with basic stuff

Archived a year ago
55 messages
1 members
2 years ago
Open in Discord
N
nbhjlkjkl

i'm really new to this so i'm starting out with greenfoot and i'm trying to make a game where the rat can eat the cherry to open (remove) a gate so he could pass through it and i'm trying to make it so once you eat the cherry both the cherry and the maze gate is removed and my code looks fine and has no syntax errors but it still doesn't remove the maze gate (the cherry is removed when the rat goes on it) can someone take a look at my code? public void eatObject() { Actor Gate = getOneIntersectingObject(Cherry.class); Actor Cherry = getOneIntersectingObject(Cherry.class); if (Cherry != null) System.out.println("Cherry eaten"); getWorld().removeObject(Cherry); if (Gate != null) { System.out.println("MazeGate found and removed"); getWorld().removeObject(Gate); } else { System.out.println("MazeGate not found"); } Maze gate found and removed prints fine on the console but the gate still doesn't disappear (the class is named Gate)

Replies (55)