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

2022/4/26

HELLO PLS HELP ME

Beebon Beebon

2022/4/26

#
I need help to pic up items and throw them. I tried but it doesn't seem to work. the idea is to hold and throw a knife. PLS HELP FAST THANK YOU
RcCookie RcCookie

2022/4/26

#
What have you tried so far? Show some code.
Beebon Beebon

2022/4/26

#
ok sir one sec
Beebon Beebon

2022/4/26

#
if(isTouching(knife.class)) { knife c = (knife) getOneIntersectingObject(knife.class); setLocation(c.getX(),c.getY()); } but whenever it touches the knife the bear stops moving
Beebon Beebon

2022/4/26

#
and if i trying putting the same code in the knife this error comes at greenfoot.core.Simulation.runContent(Simulation.java:193) at greenfoot.core.Simulation.run(Simulation.java:183) java.lang.NullPointerException at knife.act(knife.java:20) at greenfoot.core.Simulation.actActor(Simulation.java:567) at greenfoot.core.Simulation.runOneLoop(Simulation.java:530) at greenfoot.core.Simulation.runContent(Simulation.java:193) at greenfoot.core.Simulation.run(Simulation.java:183)
RcCookie RcCookie

2022/4/27

#
Please post the full code of the knife class so that I can see where the exception occurs. PS: By convention class names in java are written in CamelCase, meaning they start with a upper case letter
RcCookie RcCookie

2022/4/27

#
I think the reason for why the bear stops moving is simply because Greenfoot pauses the execution when an exception occurs.
danpost danpost

2022/4/27

#
Try this code in the class of the player instead:
knife c = getOneIntersectingObject(knife.class);
if (c != null) setLocation(c.getX(), c.getY());
Remove all attempted codes in the knife class. However, the player will still stop because you are telling it to stay where the knife is (assuming the knife does not move).
Beebon Beebon

2022/4/27

#
thx alot :D
You need to login to post a reply.