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

2023/5/5

Can you help me to solve this error?

MuchieBun MuchieBun

2023/5/5

#
Well, I'm coding about the enemy is chasing the player in the maze, but I encounter an error along the way. I don't know how to solve it or any alternative code. I'm new btw in greenfoot so yeah. Thanks in advance. The problem is, the reason of the error is "actual and argument list differ in length". I really don't know how to solve it.
public void SpawnManager () 
    {
        if (count % spawnSpeed == 0)
        {
            switch (rdmSpawn)
            {
                case 0 :addObject(new Manager(mainPlayer), 256,223); 
                break;
                case 1 :addObject(new Manager(mainPlayer), 67,226); 
                break;
                
            }
                
        }
    }
danpost danpost

2023/5/6

#
MuchieBun wrote...
Well, I'm coding about the enemy is chasing the player in the maze, but I encounter an error along the way. I don't know how to solve it or any alternative code. I'm new btw in greenfoot so yeah. Thanks in advance. The problem is, the reason of the error is "actual and argument list differ in length". I really don't know how to solve it. << Code Omitted >>
Please provide the codes of the Manager class constructor. -- public Manager(Player ...) ...
MuchieBun MuchieBun

2023/5/6

#
public class Manager extends Actor
{
    Protagonist protagonist;
    /**
     * Act - do whatever the Manager wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act (Protagonist mainPlayer)
    {
        movement ();
        Wall();
        protagonist = mainPlayer;
    }
    public void movement ()
    {
        move (1);
        turnTowards(protagonist.getX(), protagonist.getY());
    }
    private boolean Wall()
    {
        if (isTouching(Block.class))
        {
            return true;
        }
        {
            return false;
        }
    }
    }

danpost danpost

2023/5/6

#
danpost wrote...
Please provide the codes of the Manager class constructor. -- public Manager(Player ...) ...
MuchieBun wrote...
<< Code Omitted >>
Apparently, you do not have any constructors written into your Manager class. Replace lines 8 through 13 with the following:
public Manager()
{
    this Manager(new Protagonist());
}

public Manager(Protagonist mainPlayer)
{
    protagonist = mainPlayer;
}

public void act()
{
    movement();
    Wall();
}
Not sure what calling the Wall method from act does, as the code is given,. I presume you have not implemented anything for that yet. Also, the turnTowards call could cause an error if the main player is removed from the world at some point (actually, it would be the getX in the argument list that would cause the error)..
MuchieBun MuchieBun

2023/5/6

#
can you give me example of constructors? I just wanna see the correct way. I called the Wall method because I don't want the manager to walk through to the walls. My concept is- the manager is gonna chase the player in the maze. That's why. Thanks thoughhh. :DD
MuchieBun MuchieBun

2023/5/6

#
Oh. nvm I got it- thanks alottt. one question- how can i make my manager not to go through walls. Because, when the manager start to chase the player, it goes through the walls. :((
danpost danpost

2023/5/6

#
MuchieBun wrote...
how can i make my manager not to go through walls. Because, when the manager start to chase the player, it goes through the walls. :((
Well, you probably just want to reverse the moving if a wall is encountered. That is:
if (isTouching(Wall.class)) move(-1);
There is no need for a separate method for this (remove the "public void Wall()' method). The order of instructions in your act method should probably be as follows:
public void act() {
    if (protagonist != null && protagonist.getWorld() != null) {
        turnTowards(protagonist.getX(), protagonist.getY());
    }
    move(1);
    if (isTouching(Block.class)) {
        move(-1);
    }
}
The if statement on line 2 will ensure no errors will occur if the protagonist is not in the world or the variable that is to hold it is not set. Now, this may not work as hoped. The manager will probably just stop at a wall, instead of "sliding" along it. You will probably have to test the relationship between orientation of the blocking wall with respect to the rotation of the manager to determine how to move.
You need to login to post a reply.