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

2013/10/21

Way to check if scenario is being played on the Gallery?

Entity1037 Entity1037

2013/10/21

#
I want my game to save to userInfo only if it's being played on the gallery, and to save to a .dat file if not. Is there a method to check for this?
Entity1037 Entity1037

2013/10/21

#
Oops, I accidentally clicked other without realizing it. :/
danpost danpost

2013/10/21

#
If you can write to a file, you are not on the gallery.
bourne bourne

2013/10/21

#
If you consider within the Greenfoot workspace equivalent to being on the gallery (which is the assumption when working with UserInfo), then yes - use the method isStorageAvailable()
Entity1037 Entity1037

2013/10/21

#
OK I feel stupid...
davmac davmac

2013/10/21

#
Another way:
private boolean isRunningAsApplet()
{
    return null != System.getSecurityManager();
}
I think this is probably the most reliable. I can't remember what Greenfoot.isStorageAvailable() returns if someone is running an applet on the site without being logged in, but I think it is probably false.
Entity1037 Entity1037

2013/10/21

#
Thank you!
You need to login to post a reply.