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

2016/8/28

How to unload worlds?

1
2
Laurence Laurence

2016/8/30

#
True, but in my previous version of the code, I didn't change it either yet it still yielded results. Either that or I'm ignorant to what is going wrong.
danpost danpost

2016/8/31

#
Laurence wrote...
True, but in my previous version of the code, I didn't change it either yet it still yielded results. Either that or I'm ignorant to what is going wrong.
In your initial code, you had line 26:
timer--;
Laurence Laurence

2016/8/31

#
Yeah, I found out it was that which was reasonable for making the timer go down. So how would I in cooperate that line of code into making the new improved version work?
danpost danpost

2016/8/31

#
Laurence wrote...
how would I incorporate that line of code into making the new improved version work?
As usual, you would want to check the value of the field using 'if' statements AFTER each time the value is changed. Therefore, right before the 'if' statements.
Laurence Laurence

2016/8/31

#
 timer--;	
 if (timer == 145*60) 
     addObject(text1,117,427);
    	timer--;
 if (timer == 140*60) 
     addObject(text2,117,627);
Like this?
Super_Hippo Super_Hippo

2016/8/31

#
Line 4 is probably not needed.
Laurence Laurence

2016/8/31

#
Gotcha! Appreciate the help so far!
Laurence Laurence

2016/8/31

#
Would you know which thing I need to import for lists to be converted into Greenfoot.actor? awt.list and util.list doesn't seem to work.
danpost danpost

2016/8/31

#
Laurence wrote...
Would you know which thing I need to import for lists to be converted into Greenfoot.actor? awt.list and util.list doesn't seem to work.
Not sure exactly what you mean (as lists cannot be converted into Greenfoot actor). Explain in more detail and show some attempted code (this helps to understand what you are trying to do also). The List class is 'java.util.List' (in case you really need to import it).
Laurence Laurence

2016/9/1

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.List;
public class IntroSequence extends World
{
    private int timer = 9000;
    Text1 text1 = new Text1();
    Text2 text2 = new Text2();
    List objects = getObjects(null);
    public IntroSequence()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(800, 600, 1); 
        prepare();
        act();
    }
     public void act()
    {
     timer--; 
     if (timer == 148*60) 
     addObject(text1,117,427);
     if (timer == 147*60) 
     addObject(text2,309,502);
     if (timer == 144*60) 
     removeObjects(objects);
     
    }
Since it seems I can only input one command per timer if statement (I tried putting multiple and it tears apart the whole neat sequence), I tried making a list to gather all objects then make it null as seen here, but the 'objects' appears as an error stating that converting a list to greenfoot.actor is an incompatible type. The overall concept is the idea that text appears in the introduction, is removed, next sequence happens and so on.
danpost danpost

2016/9/1

#
First things first -- it is 'util', not 'awt'. Next, line 8 is only executed once, when the world is created. There will be no actors in the world at that time and therefore the list would be empty. Therefore, it makes no sense to have, or even create, the list until you are ready to remove all the objects from the world. Remove lines 2 and 8 and change line 24 to:
removeObjects(getObjects(null));
Laurence Laurence

2016/9/1

#
Alrighty! Everything I needed to know about sequence making, timers, and all that stuff is settled. I thank you beyond belief for the kind support you have supplied me with throughout this thread. I should be able to 'swim' on my own throughout my project's progress for now.
Super_Hippo Super_Hippo

2016/9/1

#
Laurence wrote...
Since it seems I can only input one command per timer if statement (I tried putting multiple and it tears apart the whole neat sequence)
For your info:
//This...
if (timer == 148*60) addObject(text1,117,427);

//... is the same as
if (timer == 148*60)
{
    addObject(text1,117,427);
    //but here you can add more statements if needed
}
danpost danpost

2016/9/1

#
Laurence wrote...
Since it seems I can only input one command per timer if statement (I tried putting multiple and it tears apart the whole neat sequence),
A switch statement could also be used here:
switch (--timer)
{
    case 148*60:
        addObject(text1,117,427);
        break;
    case 147*60:
        addObject(text2,309,502);
        break;
    case 144*60:
        removeObjects(getObjects(null));
        //  add new text here
        break;
    // etc.
    
    case 0:
        Greenfoot.setWorld(nextWorld);
        break;
}
You need to login to post a reply.
1
2