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

2012/4/9

error

1
2
-nic- -nic-

2012/4/9

#
i got this error
public void act()
{
  if (Bosshealth.getValue()==1500)
  {setImage("150")}
}
i get the error=non static method getValue() cannot be referanced from a static context ?????
SPower SPower

2012/4/9

#
Can you show the code for getValue(), I think the error is there.
-nic- -nic-

2012/4/9

#
public int getValue() {return value;}
thats in the Bosshealth class
SPower SPower

2012/4/9

#
In which class did you write:
public void act()  
    {  
      if (Bosshealth.getValue()==1500)  
      {setImage("150")}  
    }
-nic- -nic-

2012/4/9

#
the Boss class
SPower SPower

2012/4/9

#
Now I know what you did wrong. The Boss class has no acces to the Bosshealth object in the world. You have to do this via your world. Do this: 1)Add this variable to your world:
private Bosshealth bossHealth;
2)Give this a value in yourWorld()
public yourWorld()
{
....add some objects to the world.....
bossHealth = new Bosshealth();
}
3)add this method to your world:
public Bosshealth getBossHealth()
{
return bossHealth;
}
4)Change act() in Boss to this:
public void act()
{
Yourworld world = (Yourwold) getWorld();
      if (world.getBossHealth.getValue()==1500)    
      {setImage("150")}    
    } 
}
Succes!
-nic- -nic-

2012/4/9

#
:D:D:D:D:D:D:D:D:D:D:D:D:D thank you soo much ivbeen scratching my head trying to do this well all i got to do now is do it 150 times :(
-nic- -nic-

2012/4/9

#
it says cannot find symbol- consructure Bosshealth()
danpost danpost

2012/4/9

#
If Bosshealth is an Actor class, and Boss (obviously) is an Actor class, then, in the world class, create the Bosshealth object first (with (2) above),
Bosshealth bosshealth = new Bosshealth();
then when you create the Boss object, send it the reference to the Bosshealth object.
Boss boss = new Boss(bosshealth);
You will have to write a constructor in the Boss class that recieves a Bosshealth object as a parameter.
private Bosshealth bosshealth;

public Boss(Bosshealth health)
{
    bosshealth = health;
}
At this point, you should be able to call methods and retrieve information from the bosshealth object
if (bosshealth.getValue()==1500)
From your last post, it appears you do not have a constructor method in your Bosshealth class. You should have something that looks like the following (or at least starts with the first line)
public Bosshealth()
{
    // code that creates the Bosshealth object image, sets an image to it, or nothing (if an image is already assigned)
    // any code that may be needed to prepare the object for its existence.
}
-nic- -nic-

2012/4/10

#
this is in the Bosshealth class=
public Bosshealth(String refText, String unitType,int initValue, int maxValue)
{referenceText = refText;
unitOfMeasure = unitType;
maximumValue = maxValue;
add(initValue);
}
but it still says ==cannot find symbol- consructure Bosshealth()==
danpost danpost

2012/4/10

#
So, the compiler is NOT finding the constructor 'Bosshealth()', although, it does find 'Bosshealth(String, String, int, int)'. It cannot find the constructor with NO parameters. Your Bosshealth constructor takes 4 parameters (two String and two int). When you create it, you need to supply those values.
Bosshealth bosshealth = new Bosshealth("Boss", "health points", 50, 50);
The above was just an example. The values supplied should be altered to match what you want.
-nic- -nic-

2012/4/10

#
hand on forehead its allredy there oh i am so dum thank you :{)
-nic- -nic-

2012/4/10

#
ok its working all i got to do now is write if (Bosshealth.getValue()==1500) {setImage("150")} 150 times yay
SPower SPower

2012/4/10

#
Why don't you use a for loop:
for (int i = 0; i < 150; i++) {
       if (Bosshealth.getValue() == i *10) {
             setImage(Integer.toString(i));
       }
}
This will do this:
if (Bosshealth.getValue() == 10 or 20 or 30 or 40 etc.) {
    setImage("0" or "1" or "2" or "3" etc.);
}
I hope this helps
-nic- -nic-

2012/4/10

#
what oh any way ive done it now :)
There are more replies on the next page.
1
2