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

2012/6/25

Selecting which world should be executed first?

Zamoht Zamoht

2012/6/25

#
For my game I want to create a menu world, but since I created the game world first, the game world is the one that gets executed first. I don't get how Greenfoot defines which world to execute first. So is there any simple way to change this? I think this has been asked before, but i couldn't find the discussion. Thanks for your time! About using multiple worlds, how do you transfer integer values from one world to another? (This is not the main point of this discussion)
erdelf erdelf

2012/6/25

#
To the first question, the last world you selected in the class overview (with right click, new) is the world which is executed first. Test it with pressing on reset. To the second question, ask in the constructor of the second world after an integer.
Zamoht Zamoht

2012/6/25

#
Thank you! The first problem is solved. I'm very new at programming, so can you make an example for the second question? Lets say the first world has an integer called level, then when I change world using the Greenfoot.setWorld(new world2()); the value of level from world1 is 20, what would the code for world2 look like? Thanks for your time! Please tell me if the question above doesn't make any sense.
erdelf erdelf

2012/6/25

#
well, when you change the world you have to say this:
Greenfoot.setWorld(new world2(level));
and in world 2
int level;
public world2(int level2)
{
    level = level2;
}
Zamoht Zamoht

2012/6/25

#
Oh I get it! Thanks again, and sorry for my tiny knowledge of programming!
erdelf erdelf

2012/6/25

#
everyone started. I just started before you.
SPower SPower

2012/6/25

#
A tip for you: start the name of classes with a Uppercase, that is standard. Java won't complain if you don't do it, but you confuse other programmers.
Zamoht Zamoht

2012/6/25

#
I didn't get the Uppercase part at first, then I looked at this http://www.wikihow.com/Name-a-Class-in-Java, and in my defense i would like to say that my worlds are not called world and world2. It was to make an example, but thank you anyway. I didn't know about the certain rules for naming a class. (:
erdelf erdelf

2012/6/25

#
Well, I just used the names I get.
Duta Duta

2012/6/26

#
Zamoht, there are many naming conventions like that - In Java, here's some of them:
  • Method/variable: mixedCase
  • Constant: UPPER_CASE
By which I mean: mixedCase = Starts with lowercase, when you have more than one word the new words start with a capital letter UPPER_CASE = All uppercase, when you have multiple words they're seperated with an underscore Also: CamelCase = (e.g. For naming classes) The same as mixedCase, but starts with a capital letter lowercase = (e.g. For naming packages) All lowercase, often no underscores between words Sometimes people call CamelCase Upper CamelCase, and mixedCase Lower CamelCase.
You need to login to post a reply.