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

2016/12/3

Need help with a character change

BonJunzi BonJunzi

2016/12/3

#
        public void stopAtWalls()
    {
        if(getOneIntersectingObject(Walls.class)!=null)
        {
            setLocation(x,y);
        }
        else
        {
            x= getX();
            y= getY();
        }
when switching between 2 different classes that have this same code i get an error pointing me to this command no idea what is wrong plz help if possible it says null point exception don't even know what that means
danpost danpost

2016/12/3

#
BonJunzi wrote...
it says null point exception don't even know what that means
A nullPointerException will occur when you call a method on an object reference that does not point to a specific object. There is nothing in the code given that will do that. I suggest you show the complete class code so we have a better idea of what is going on.
BonJunzi BonJunzi

2016/12/4

#
    public void moving()
    {
        if(Greenfoot.isKeyDown("w"))
        {
            setLocation(getX(), getY()-Wspeed);
            frameup++;
            if(frameup==5)
            {
                setImage("Wizard1.png");
            }
            if(frameup==10)
            {
                setImage("Wizard2.png");
            }
            if(frameup==1)
            {
                setImage("Wizard3.png");
            }
            if(frameup>=10)
            {
                frameup=0;
            }
        }
        else if(Greenfoot.isKeyDown("s"))
        {
            setLocation(getX(), getY()+Wspeed);
            framedown++;
            if(framedown==4)
            {
                setImage("Wizard7.png");
            }
            if(framedown==6)
            {
                setImage("Wizard8.png");
            }
            if(framedown==2)
            {
                setImage("Wizard9.png");
            }
            if(framedown>=7)
            {
                framedown=0;
            }
        }
        else if(Greenfoot.isKeyDown("a"))
        {
            setLocation(getX()-Wspeed, getY());
            frameleft++;
            if(frameleft==5)
            {
                setImage("Wizard10.png");
            }
            if(frameleft==10)
            {
                setImage("Wizard11.png");
            }
            if(frameleft==1)
            {
                setImage("Wizard12.png");
            }
            if(frameleft>=10)
            {
                frameleft=0;
            }
        }
        else if(Greenfoot.isKeyDown("d"))
        {
            setLocation(getX()+Wspeed, getY());
            frameright++;
            if(frameright==5)
            {
                setImage("Wizard4.png");
            }
            if(frameright==10)
            {
                setImage("Wizard5.png");
            }
            if(frameright==1)
            {
                setImage("Wizard6.png");
            }
            if(frameright>=10)
            {
                frameright=0;
            }
        }
    }
    
    public void evolve()
    {
        Actor magepickup = getOneObjectAtOffset(0,0,firemagepickup.class);
        Actor magepickupice = getOneObjectAtOffset(0,0,iceMagepickup.class);
        if(magepickup!=null && Greenfoot.isKeyDown("enter"))
        {
            getWorld().addObject(new FireMage(),getX(),getY());
            getWorld().removeObject(this);
        }
        else if(magepickupice!=null && Greenfoot.isKeyDown("enter"))
        {
            getWorld().addObject(new IceMage(),getX(),getY());
            getWorld().removeObject(this);
        }
    }
    
        public void fight()
    {
        if(Greenfoot.isKeyDown("space")&& ProjectRot == 2 && firing == false)
        {
            getWorld().addObject(new LEFTNorm(), getX(), getY()+25);
            firing = true;
        }
        else if(Greenfoot.isKeyDown("space")&& ProjectRot == 1 && firing == false)
        {
            getWorld().addObject(new UPNorm(), getX(), getY()+25);
            firing = true;
        }
        else if(Greenfoot.isKeyDown("space")&& ProjectRot == 0 && firing == false)
        {
            getWorld().addObject(new RIGHTNorm(), getX(), getY()+20);
            firing = true;
        }
        else if(Greenfoot.isKeyDown("space")&& ProjectRot == 3 && firing == false)
        {
            getWorld().addObject(new DOWNNorm(), getX(), getY()+25);
            firing = true;
        }
    }
        public void respond()
    {
        if(Greenfoot.isKeyDown("w"))
        {
            ProjectRot = 1;
        }
        if(Greenfoot.isKeyDown("a"))
        {
            ProjectRot = 2;
        }
        if(Greenfoot.isKeyDown("s"))
        {
            ProjectRot = 3;
        }
        if(Greenfoot.isKeyDown("d"))
        {
            ProjectRot = 0;
        }
    }
    public void reset()
    {
        firereset++;
        if(firereset == 1)
        {
            firing = false;
        }
        if(firereset == 10)
        {
            firereset = 0;
        }
    }
    
        public void stopAtWalls()
    {
        Actor walls = getOneIntersectingObject(Walls.class);
        if(walls!=null)
        {
            setLocation(x,y);
        }
        else
        {
            x= getX();
            y= getY();
        }
    }
   
}
That is everything in first class
BonJunzi BonJunzi

2016/12/4

#
        public void movingIce()
    {
        if(Greenfoot.isKeyDown("w"))
        {
            setLocation(getX(), getY()-5);
            frameup++;
            if(frameup==5)
            {
                setImage("IceMage1.png");
            }
            if(frameup==10)
            {
                setImage("IceMage2.png");
            }
            if(frameup==1)
            {
                setImage("IceMage3.png");
            }
            if(frameup>=10)
            {
                frameup=0;
            }
        }
        else if(Greenfoot.isKeyDown("s"))
        {
            setLocation(getX(), getY()+5);
            framedown++;
            if(framedown==4)
            {
                setImage("IceMage7.png");
            }
            if(framedown==6)
            {
                setImage("IceMage8.png");
            }
            if(framedown==2)
            {
                setImage("IceMage9.png");
            }
            if(framedown>=7)
            {
                framedown=0;
            }
        }
        else if(Greenfoot.isKeyDown("a"))
        {
            setLocation(getX()-5, getY());
            frameleft++;
            if(frameleft==5)
            {
                setImage("IceMage10.png");
            }
            if(frameleft==10)
            {
                setImage("IceMage11.png");
            }
            if(frameleft==1)
            {
                setImage("IceMage12.png");
            }
            if(frameleft>=10)
            {
                frameleft=0;
            }
        }
        else if(Greenfoot.isKeyDown("d"))
        {
            setLocation(getX()+5, getY());
            frameright++;
            if(frameright==5)
            {
                setImage("IceMage4.png");
            }
            if(frameright==10)
            {
                setImage("IceMage5.png");
            }
            if(frameright==1)
            {
                setImage("IceMage6.png");
            }
            if(frameright>=10)
            {
                frameright=0;
            }
        }
    }
    
    public void finalform()
    {
        Actor GMPU = getOneObjectAtOffset(0,0, iceGrandMasterpickup.class);
        if(GMPU!=null)
        {
            getWorld().addObject(new IceGrandMaster(),getX(),getY());
            getWorld().removeObject(this);
        }
    }
}
this is everything in the class it is turning into
BonJunzi BonJunzi

2016/12/4

#
Any help at all would be helpful even help in what to look for. Please really need help it's a school project :)
Super_Hippo Super_Hippo

2016/12/4

#
This is not ALL of the class codes. You are not showing the field declarations and I am not even seeing an act method.
Nosson1459 Nosson1459

2016/12/4

#
BonJunzi wrote...
<Code Omitted>That is everything in first class
BonJunzi wrote...
<Code Omitted>this is everything in the class it is turning into
If that is all you have in your classes then you will for sure have syntax errors for:
  • Not importing the necessary imports for the used methods
  • Not having a class method
  • Not having an act method
  • Using undefined variables
you should
danpost wrote...
show the complete class code
(not just methods). If you are on windows then: 1) open your source code 2) press <Ctrl> 'a' (to select everything) 3) press <Ctrl> 'c' (to copy) then in the/this discussion click on code-tag link and press <Ctrl> 'v' to paste everything in post (I'm not saying you don't know the windows shortcuts, but above are all the necessary steps (besides for pressing the green check in code-tags and pressing "Post" to post) needed to post the whole code).
You need to login to post a reply.