Discuss Scratch

space_elephant
Scratcher
500+ posts

How to Make a Cloud Var Watcher?

How do I simulate a cloud var watcher?
EDIT: many have been confused about what I mean so:
I can do
set[☁ cloud variable v]to[0]

change[☁ cloud variable v]by(1)
(☁ cloud variable)
and I can also do

the only thing that I need help for is


Also the I can do that last one without the slider.

Last edited by space_elephant (Oct. 13, 2018 16:16:14)

Garamol56
Scratcher
100+ posts

How to Make a Cloud Var Watcher?

What do you mean by watcher? Like something that detects when they change?
ninjagolloyd
Scratcher
500+ posts

How to Make a Cloud Var Watcher?

space_elephant wrote:

How do I simulate a cloud var watcher?
I know how to do blocks but not watchers.
Do you mean an API that tells you when a cloud var changes?

you should be able to, as long as your programming language has web requests
space_elephant
Scratcher
500+ posts

How to Make a Cloud Var Watcher?

Garamol56 wrote:

What do you mean by watcher? Like something that detects when they change?
I mean these:
(12::variables)
(☁ score(12::variables)::grey)
☁ score(12::variables)::grey hat
------+-----------------::grey cap
I can do these
(☁ score)
set[☁ score v]to[0]

change[☁ score v]by(1)
Jonathan50
Scratcher
1000+ posts

How to Make a Cloud Var Watcher?

It should appear on the stage once you make a cloud variable. You can toggle it with the checkbpx next to the variable in the palette.
space_elephant
Scratcher
500+ posts

How to Make a Cloud Var Watcher?

Jonathan50 wrote:

It should appear on the stage once you make a cloud variable. You can toggle it with the checkbpxcheckbox next to the variable in the palette.
I mean like another program, not scratch, using a cloud var watcher.
Jonathan50
Scratcher
1000+ posts

How to Make a Cloud Var Watcher?

space_elephant wrote:

I mean like another program, not scratch, using a cloud var watcher.
Oh, okay, sorry. Then you will have to write code to draw the watcher, using whatever graphics library you use (if that's what you want.)

Last edited by Jonathan50 (Oct. 3, 2018 21:33:17)

ninjagolloyd
Scratcher
500+ posts

How to Make a Cloud Var Watcher?

space_elephant wrote:

Jonathan50 wrote:

It should appear on the stage once you make a cloud variable. You can toggle it with the checkbpxcheckbox next to the variable in the palette.
I mean like another program, not scratch, using a cloud var watcher.
can you specify which program???

i doubt you can do it in a blocks environment
Wettining
Scratcher
500+ posts

How to Make a Cloud Var Watcher?

Do you mean something like the ScratchAPI that will get your cloud variables from an external client?
space_elephant
Scratcher
500+ posts

How to Make a Cloud Var Watcher?

Jonathan50 wrote:

space_elephant wrote:

I mean like another program, not scratch, using a cloud var watcher.
Oh, okay, sorry. Then you will have to write code to draw the watcher, using whatever graphics library you use (if that's what you want.)
I don't care about the drawing it. I mean the API.
space_elephant
Scratcher
500+ posts

How to Make a Cloud Var Watcher?

Wettining wrote:

Do you mean something like the ScratchAPI that will get your cloud variables from an external client?
In C++ but yes kind of
Jonathan50
Scratcher
1000+ posts

How to Make a Cloud Var Watcher?

space_elephant wrote:

I don't care about the drawing it. I mean the API.
What do you want? Are you already able to read cloud variables?
jokebookservice1
Scratcher
1000+ posts

How to Make a Cloud Var Watcher?

Scratch uses WebSockets (RFC6455) for it's Cloud Data API. You want to open a connection to

wss://clouddata.scratch.mit.edu

For security, you'll need to send an Origin: header of scratch.mit.edu, and be logged in (i.e., have your Cookie: header set)

Basic Structure
All data is sent backwards and forwards as JSON objects. Here are the properties that all such objects will have
  • method (string) - the action that this object represents
  • project_id (string) - the numeric ID (as seen in the URL bar) of the project in question. Note that this value is a string.

In addition, client-to-server objects must have an additional property that server-to-client messages don't need.
  • user (string) - your username

Setting data
On top of the basic structure, you also need to send the following to set a cloud variable to a specific value. The “method” property should be set to “set”.

  • name (string) - the name of the cloud variable, including the cloud symbol
  • value (string) - the value of the cloud variable - always a string

Getting data
The server will send you the same data as in Setting data if the value of a cloud variable changes (and you weren't the person who set it). It'll still be the “set” method, but note that the “user” parameter will not be given to you (that's only given on client-to-server data)

Example
Here's a generic example of what a connection might look like:

  1. Client connects to clouddata.scratch.mit.edu
  2. Client sends handshake
    {
      "user": "exampleuser",
      "project_id": "1234567",
      "method": "handshake"
    }
    
  3. Server tells client what the current value of the cloud variable is
    {
      "project_id": "1234567",
      "method": "set",
      "name": "☁ counter",
      "value": "12"
    }
    
  4. Client tells server about a change to the cloud variable
    {
      "user": "exampleuser",
      "project_id": "1234567",
      "method": "set",
      "name": "☁ counter",
      "value": "13"
    }
    
space_elephant
Scratcher
500+ posts

How to Make a Cloud Var Watcher?

jokebookservice1 wrote:

Scratch uses WebSockets (RFC6455) for it's Cloud Data API. You want to open a connection to

wss://clouddata.scratch.mit.edu

For security, you'll need to send an Origin: header of scratch.mit.edu, and be logged in (i.e., have your Cookie: header set)

Basic Structure
All data is sent backwards and forwards as JSON objects. Here are the properties that all such objects will have
  • method (string) - the action that this object represents
  • project_id (string) - the numeric ID (as seen in the URL bar) of the project in question. Note that this value is a string.

In addition, client-to-server objects must have an additional property that server-to-client messages don't need.
  • user (string) - your username

Setting data
On top of the basic structure, you also need to send the following to set a cloud variable to a specific value. The “method” property should be set to “set”.

  • name (string) - the name of the cloud variable, including the cloud symbol
  • value (string) - the value of the cloud variable - always a string

Getting data
The server will send you the same data as in Setting data if the value of a cloud variable changes (and you weren't the person who set it). It'll still be the “set” method, but note that the “user” parameter will not be given to you (that's only given on client-to-server data)

Example
Here's a generic example of what a connection might look like:

  1. Client connects to clouddata.scratch.mit.edu
  2. Client sends handshake
    {
      "user": "exampleuser",
      "project_id": "1234567",
      "method": "handshake"
    }
    
  3. Server tells client what the current value of the cloud variable is
    {
      "project_id": "1234567",
      "method": "set",
      "name": "☁ counter",
      "value": "12"
    }
    
  4. Client tells server about a change to the cloud variable
    {
      "user": "exampleuser",
      "project_id": "1234567",
      "method": "set",
      "name": "☁ counter",
      "value": "13"
    }
    
But how does the slider work? And how do I know who changed it?

Last edited by space_elephant (Oct. 14, 2018 06:40:53)

jokebookservice1
Scratcher
1000+ posts

How to Make a Cloud Var Watcher?

But how does the slider work?
As you drag it, it updates the server as normal…
And how do I know who changed it?
Good question! As far as people have discovered, the only way is to parse the HTML of the cloud logs. (The URL of these logs can be found by clicking a link below the relevant project)
space_elephant
Scratcher
500+ posts

How to Make a Cloud Var Watcher?

jokebookservice1 wrote:

space-elephant wrote:

And how do I know who changed it?
Good question! As far as people have discovered, the only way is to parse the HTML of the cloud logs. (The URL of these logs can be found by clicking a link below the relevant project)
Looking at this, the HTML does not help at all. the correct file is at https://clouddata.scratch.mit.edu/logs?projectid=279457375&limit=1&offset=0 and is JSON, not HTML.

Last edited by space_elephant (Jan. 26, 2019 16:01:50)

Raytracing
Scratcher
86 posts

How to Make a Cloud Var Watcher?

space_elephant wrote:

How do I simulate a cloud var watcher?
EDIT: many have been confused about what I mean so:
I can do
set[☁ cloud variable v]to[0]

change[☁ cloud variable v]by(1)
(☁ cloud variable)
and I can also do

the only thing that I need help for is


Also the I can do that last one without the slider.

Check out my userstats project (it takes your info and uploads it to the cloud)
Then I made a python script to check what has been uploaded. so now I have a log of everyone >
Also my python script doesn't use and API's it only uses the tools provided in 3.0 . I could give you the script if you want
space_elephant
Scratcher
500+ posts

How to Make a Cloud Var Watcher?

Raytracing wrote:

space_elephant wrote:

How do I simulate a cloud var watcher?
EDIT: many have been confused about what I mean so:
I can do
set[☁ cloud variable v]to[0]

change[☁ cloud variable v]by(1)
(☁ cloud variable)
and I can also do

the only thing that I need help for is


Also the I can do that last one without the slider.

Check out my userstats project (it takes your info and uploads it to the cloud)
Then I made a python script to check what has been uploaded. so now I have a log of everyone >
Also my python script doesn't use and API's it only uses the tools provided in 3.0 . I could give you the script if you want
Unable to find either by hyperlinks on this page. Can you make one here?
space_elephant
Scratcher
500+ posts

How to Make a Cloud Var Watcher?

space_elephant wrote:

jokebookservice1 wrote:

space-elephant wrote:

And how do I know who changed it?
Good question! As far as people have discovered, the only way is to parse the HTML of the cloud logs. (The URL of these logs can be found by clicking a link below the relevant project)
Looking at this, the HTML does not help at all. the correct file is at https://clouddata.scratch.mit.edu/logs?projectid=279457375&limit=1&offset=0 and is JSON, not HTML.
With limit=0 you can get all logs.

Last edited by space_elephant (Jan. 26, 2019 16:02:35)

HowToLogic
Scratcher
34 posts

How to Make a Cloud Var Watcher?

space_elephant wrote:

Unable to find either by hyperlinks on this page. Can you make one here?

I think they mean: https://scratch.mit.edu/projects/277229912/

Powered by DjangoBB