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

2014/2/24

Problem with Class-Connection

Pointifix Pointifix

2014/2/24

#
Hey Guys! I got a problem with getting a String from my Violator.class in Player.class Greenfoot says: cannot find symbol - variable type Code in Violator.class: public class Violator extends Actor { public String type; ....Rest of Code Code in Player.class: Actor violator = getOneIntersectingObject(Violator.class); if(violator.type=="red")((Play)getWorld()).health-=5; .............................................. violator.type cannot be found? But why? Thanks for help
danpost danpost

2014/2/24

#
This line: Actor violator = getOneIntersectingObject(Violator.class); sets the field 'violator' to an Actor object (not a Violator object). Instead, use: Violator violator = (Violator)getOneIntersectingObject(Violator.class); As a Violator object, the compiler will look in that class for the 'type' field.
Pointifix Pointifix

2014/2/24

#
It works jeah ;) Thank you a lot danpost, it was such a small mistake i couldn“t find -.- Really great thanks to you i already searched for an hour ;)
You need to login to post a reply.