This site requires JavaScript, please enable it in your browser!
Greenfoot back
s1802055@online.houstonisd.org
s1802055@online.houstonisd.org wrote ...

2019/12/17

Spawning Coins in Game (Issue)

public void act() { //ruby movement setImage (Gif.getCurrentImage()); setLocation(getX()-3, getY()); DeleteAtEdge(); AddRubies(); } //deletes ruby if at edge public void DeleteAtEdge() { if(isAtEdge()) { World world; world = getWorld(); world.removeObject(this); } } //Ninja collects ruby after making contact //increases scoreboard by "1" after every collected Ruby public void AddRubies() { Actor Ninja; Ninja = getOneObjectAtOffset(0,0,Ninja.class); if (Ninja != null) { World world; world = getWorld(); world.removeObject(this); RubyCount++; } } } I receive this error everytime I run my code: Actor not in world. An attempt was made to use the actor's location while it is not in the world. Either it has not yet been inserted, or it has been removed. I'm not able to spawn a coin in game and have it deleted on screen.
danpost danpost

2019/12/18

#
Switch the last two lines in your act method.
If I switch DeleteAtEdge() and AddRubies(), the rubies will delete and add score when touching ninja but I will get an error when the ruby touches the edge
danpost danpost

2019/12/19

#
s1802055@online.houstonisd.org wrote...
If I switch DeleteAtEdge() and AddRubies(), the rubies will delete and add score when touching ninja but I will get an error when the ruby touches the edge
Ahhh, both methods can remove the ruby from the world (sorry I did not look closer). You probably should not have rubies check for ninjas. It would be a state of a ninja to have acquired 'x' number of rubies, so RubyCount should be non-static in the Ninja class and the ninja should check for rubies.
Thanks
You need to login to post a reply.