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

2013/11/12

next level

1
2
3
danpost danpost

2013/11/13

#
payner2013 payner2013

2013/11/13

#
so could i do this
if Counter counter = (Counter)getWorld().getObjects(Counter.class).get(100);
{
Greenfoot.setWorld(new Level());
}
danpost danpost

2013/11/13

#
If you had one hundred and one counters and you wanted the last one, then yes (I guess that was a bit facetious -- I know you do not have one hundred and one counter objects). You only have one, so 'get(0)' would refer to it. You then need to get the value of the counter object using the 'getValue' method of the Counter class and compare it to 100.
payner2013 payner2013

2013/11/13

#
so how do i put together the 'getValue' and
if Counter counter = (Counter)getWorld().getObjects(Counter.class).get(0);  
{  
Greenfoot.setWorld(new Level());  
}  
together?
danpost danpost

2013/11/13

#
if (counter.getValue() >= 100)
payner2013 payner2013

2013/11/13

#
thank you! im sorry i just dont quite understand it yet.
payner2013 payner2013

2013/11/13

#
but now i get an error? non static method getValue() - cannot be refrenced from a static context... what does this mean?
danpost danpost

2013/11/13

#
If you cannot put the pieces together with what has been provided up to this point, you really need to review the Java tutorials, especially the trail on Learning the Java Language.
payner2013 payner2013

2013/11/13

#
ok
danpost danpost

2013/11/13

#
payner2013 wrote...
but now i get an error? non static method getValue() - cannot be refrenced from a static context... what does this mean?
This means you did not set the local field 'counter' which should hold a Counter object to the counter object in your world before trying to get its value.
payner2013 payner2013

2013/11/13

#
well that just went over my head :s
payner2013 payner2013

2013/11/13

#
i have no idea whats going on... :s
 /**
     * Return the current counter value.
     */
    public int getValue()
    {
        return value;
    }
       {  if (Counter.getValue() >= 100)
    {
        Greenfoot.setWorld(new Level1());
    }
    }
what does that error mean..?
payner2013 payner2013

2013/11/13

#
plz help...
danpost danpost

2013/11/13

#
In line 8, you are using the class name and not an object of that class to get the value from. I repeatedly have shown how to get an instance of the counter class if you only had one in the world.
payner2013 payner2013

2013/11/14

#
so would it be...
** 02.    * Return the current counter value. 03.    */  04.   public int getValue()  05.   {  06.       return value;  07.   }  08.      {  if (value.getValue() >= 100)  09.   {  10.       Greenfoot.setWorld(new Level1());  11.   }  12.   }  
There are more replies on the next page.
1
2
3