(☁ var)
|
This article or section uses Cloud Data. Users who are New Scratchers or are using the Offline Editor cannot make projects using Cloud Data or use it in other users' projects. To use Cloud Data, the Scratcher status is needed and the Online Editor has to be used. |
| This article or section may not have content matching Scratch Wiki editing standards. Please improve it according to Scratch Wiki:Guidelines and Scratch Wiki:Editing Conventions. (March 2022) |
This tutorial explains how to check if a user is having problems connecting to Cloud Variables.
You will need to define the following variables:
(☁ Debug?) // Cloud Variable (☁ Response) // Cloud Variable (Debug?) // Local Variable (Old Response) // Local Variable
Code:
First, define a new custom block with the run without screen refresh option checked. This custom block will be run every tick of the game.
define Cloud variable connection check// Check run without screen refresh
Add a conditional if-else block. Because the custom block will be run every tick, we need to check for cloud updates from the previous tick.
if <(☁ Response) = [0]> then set [☁ Response v] to [1] set [Old Response v] to (☁ Response) else if <(☁ Response) = [1]> then set [☁ Response v] to [0] set [Old Response v] to (☁ Response) end end
The final result should look like this:
define Cloud variable connection check// Run without screen refresh if <(☁ Response) = [0]> then set [☁ Response v] to [1] set [Old Response v] to (☁ Response) else if <(☁ Response) = [1]> then set [☁ Response v] to [0] set [Old Response v] to (☁ Response) end end wait [0.5] seconds if <(☁ Response) = (Old Response)> then set [Debug? v] to (1) set [☁ Debug? v] to (1) end wait [0.5] seconds if <(☁ Debug?) = (Debug?)> then set [Debug? v] to (2) else set [Debug? v] to (0) end when green flag clicked set [Debug? v] to (0) forever if <<(Debug?) = [0]> and <(☁ Debug?) = [1]>> then set [☁ Debug? v] to (0) end end when green flag clicked hide forever Cloud variable connection check if <(Debug?) = [2]> then show say [Connection error or there are no other players on.]//This notifies you that there are no other players on or your connection isn't working. else hide end end