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

2012/7/7

How to check whether the game is running on greenfoot.org or locally on my pc?

stevenGrohe stevenGrohe

2012/7/7

#
I need to know that, because I want to change things in the game depending on whether I am testing my game on my pc locally, or someone in the internet is playing it.
darkmist255 darkmist255

2012/7/7

#
One thing you could try is check whether or not it's your username playing it. Then when you play it you would see a different thing than someone else. Also, when you're editing it in Greenfoot you can set the username you want it to pretend to use.
SPower SPower

2012/7/7

#
What do you want to accomplish? Because there may be other solutions, which would be easier
stevenGrohe stevenGrohe

2012/7/7

#
I want to create an own level editor, which is only visible for me
darkmist255 darkmist255

2012/7/7

#
I think it might work if you do something that won't work from the gallery, and if it DID work then it knows you're offline. For example, try to read a file on your computer, and if it says it isn't allowed, it must be in the gallery. If it was allowed, it must be local. Just an idea, there's probably a better way, but that's the first thought I have.
stevenGrohe stevenGrohe

2012/7/7

#
okay thank you guys, i´ll check it out!
DonaldDuck DonaldDuck

2012/7/8

#
final String my_user = "stevenGrohe"; //("Player1" while offline)

UserInfo me = Greenfoot.getUserInfo();

if(me.getUsername().equals(my_user))
{
     editor = true;
}
else
{
     editor = false;
}
This is untested but probably is a better solution than messing with file readers. EDIT: Additionally, if you navigate to the scenario folder (For me C:\Program Files (x86)\Greenfoot\scenarios\scenarioName) you can open the storage file and change values manually to ensure you have permissions offline. For example, change the first int to 99 and check to see if the getUserInfo().getInt(0) is equal to 99. If it is, then you know it's you
You need to login to post a reply.