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

2018/11/14

Cant find symbol (variable disk)

jonah420123 jonah420123

2018/11/14

#
Hi im trying to make a score counter for my game, the 'bike' will collect the 'disk' (coins) but im having trouble trying to remove the disk once its collided. if(disk!=null) <------ says it "cannot find symbol" here as well { Arena arena = (Arena)getWorld(); arena.removeObject(disk); <------- says that it cannot find symbol here Greenfoot.playSound("pop.wav"); Counter counter = arena.getCounter(); counter.bumpCount(1); }
danpost danpost

2018/11/14

#
jonah420123 wrote...
if(disk!=null) <------ says it "cannot find symbol" here as well ... arena.removeObject(disk); <------- says that it cannot find symbol here
Apparently, you have not initialized a variable called disk before trying to reference it:
Actor disk = null;
Once it is initialized, you will need an assignment statement:
disk = ???;
to possibly acquire a reference to a disk object. Then your if statement will have a chance to be true as well as false (provided your assignment may or may not actually assign a disk object to the variable).
You need to login to post a reply.