Interface Detection: различия между версиями

Материал из Поле цифровой дидактики
м
 
м (1 версия импортирована)
 
(нет различий)

Текущая версия на 11:33, 21 июля 2022

Шаблон:Obsolete feature Interface detection is a process in which a project determines what player it is running in. For example, a script can detect whether a project is running on the Online Editor or the Offline Editor. These take advantage of slight differences between the compared player.

1.4-Java Player

Using these methods, it can be determined whether the player is Scratch 1.4 or the Java Player.

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.

1.4-Java-Flash

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.

Example Uses

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