(Redirected from Offline/Online Detection)
|This article or section documents something not included in the current version of Scratch (3.0). It is only useful from a historical perspective.|
|The subject of this article or section has changed dramatically and requires updating. Please keep in mind that some of the information or images may not be accurate or relevant to the current version of Scratch, the Scratch website, or the article subject. (January 2021)|
Specifically: 2.0 site no more; flash player obsolete
Interface detection is when a project determines what player it is running in. For example, 3.0-1.4; player-editor; 1.4-Java-Flash. These take advantage of slight differences between the compared player.
|Please expand this section. You can help by talk page. (April 1, 2018)if you are an editor. More information might be found in a section of the|
Here is an example of online and offline detection.
Using Obsolete Blocks
The following script requires obsolete blocks to properly check if the viewer was running projects in the offline or online editor.
when gf clicked set [Online/Offline v] to [Online] obsolete! set [Online/Offline v] to [Offline]
How it Works
First the script sets the variable Online/Offline to Online. In the Java Player, it will stop at an obsolete block. Therefore, it sets it to Offline if it is being played in the Experimental Viewer or offline because it will ignore the obsolete block and the script will continue to turn the variable online/offline to offline.
Using Script Errors
when gf clicked set [Online/Offline v] to [Offline] wait ([sqrt v] of (-1)) secs set [Online/Offline v] to [Online]
Other script errors, such as dividing by zero, can also be used.
How it Works
First the script sets the variable, Online/Offline, to Offline. In the Scratch Program (offline) it will not continue the script when it reaches the script error but online it will continue to run the script.
This script is similar to the previous ones, but it additionally checks whether the project is playing in the modern Flash Player.
when gf clicked set [Playing... v] to [Offline] broadcast ([sqrt v] of (-1)) set [Playing... v] to [Java] obsolete! set [Playing... v] to [Flash]
How it Works
First, the script sets the variable "Playing..." to "Offline". Offline the script stops immediately. However, in the Java Player, the script ignores the error and carries on the script, therefore setting the variable to "Java". The Experimental Viewer and Flash Player will continue with the script no matter how many errors so it will then set the variable to "Flash".
Similarly, a script could be made that checks "Java", "offline", or "Flash". It works by first setting the variable to Java. If it is on Java, then it will stop there because of the obsolete block. Then if it is offline it will make it through the obsolete block but stop at the script error. Then if it is on Flash it will run through all of it setting it to Flash.
There are many reasons a user may want to detect if a project is online or offline. For example, you may want to automatically suggest the user to download the project (or use the Flash player) in case the project requires Turbo Mode. It is also useful to prompt a user to download and remix a project, or to disable certain features online which may not work properly. However, you can make a user download the project to play it by disconnecting a vital script.
- Only showing a sprite online
when gf clicked hide if <((0) / (0)) = (0)> then end show
- Changing the appearance of a sprite for online/offline
when gf clicked switch costume to [costume v] if <((0) / (0)) = (0)> then end switch costume to [costume2 v]
- Disallowing a feature online
when gf clicked if <(Online?) = [True]> then stop script :: control end say [Welcome to the bonus level!] repeat (50) turn cw (5) degrees end
- Reporting where the user is playing the project
when this sprite clicked if <(Online?) = [True]> then say [You are on the internet!] else say [You are not on the internet!] end