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

2017/1/12

cannot find symbol - variable

fonsemax fonsemax

2017/1/12

#
I'm trying to make a game where when you touch the block, your character disappears, but at the last "Person" it says "cannot find symbol- variable
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * An obstical in this game
 * 
 *  
 * 0.0.1-1.10.2017
 */
public class Block extends Actor
{
    //Act command
    public void act() 
    {

    }    
    //Used for aranging the blocks
    public void turn()
    {
        turn(90);
    }
    //For losing the game
    public void eat()
    {
        if (isTouching(Person.class))
        {
            World world;
            world = getWorld();
            world:removeObject([u]Person[/u]);
        }
    }
}
Nosson1459 Nosson1459

2017/1/12

#
Just replace lines 26 - 28 with
removeTouching(Person.class);
It's saying that there is no variable person, and I agree, I don't see a variable named Person anywhere in the class,. In fact as a side point I don't see any variables defined in this class at all.
fonsemax fonsemax

2017/1/12

#
it still hasn't worked. the person goes right through it
danpost danpost

2017/1/12

#
fonsemax wrote...
it still hasn't worked. the person goes right through it
You have no code in your act method. You need to call your methods from there:
public void act()
{
    turn();
    eat();
}
Super_Hippo Super_Hippo

2017/1/12

#
You don't call the 'eat' method from anywhere. You could put the following in line 14:
eat();
This will work then, but it would probably be more clever to put the code into the Person class and check for touching the block instead of doing it the other way around as you did. I mean if you have your hand on a stone (in real life), would you say that you are touching the stone or that the stone is touching you?
You need to login to post a reply.