Discuss Scratch

TimMcCool
Scratcher
100+ posts

scratchattach - A Scratch API wrapper (Python)

TheMobileGames wrote:

…Am I really supposed to make 10 connections and a function that takes in “event.var” and sets it to the last used connection? If there isn’t one already, there should be a function in Scratchattach that can “just” handle setting 5-10 cloud variables with each being changed 10 times a second. Maybe there could be one that opens as many connections as it needs and automatically closes them, all internally, so all someone has to do is use it and it works even when it’s setting a lot quickly.

I think in the use case you described, the gain in speed wouldn't justify the effort to code something like that. Using multiple connections can be beneficial if you want to set multiple cloud variables simultaneously, because one cloud connection only allows you to perform a total of 10 cloud var sets per second.

TheMobileGames wrote:

If there isn’t one already, there should be a function in Scratchattach that can “just” handle setting 5-10 cloud variables with each being changed 10 times a second.
That's an interesting idea tho. This feature doesn't exist atm, but I might add something like this to scratchattach in the future

import scratchattach as scratch3
session = scratch3.login("TheMobileGames", os.environ["PASSWORD"])
conn1 = session.connect_cloud("project_id")
events = scratch3.CloudEvents("project_id")
@events.event
def on_set(event):
    conn1.set_var("event.var", "0")
@events.event
def on_ready():
   print("Event listener ready!")
events.start()
When coding something like this, beware that the on_set event will also be called when the cloud variable is set to 0 by the Python script. To prevent an infinite loop of on_set events caused by the Python script itself, add something like this to the on_set event:
    if str(event.value) != "0":
        ...

Last edited by TimMcCool (Jan. 21, 2024 02:22:20)


Developer of scratchattach, the most popular Python Scratch API wrapper
Eason_9
Scratcher
1000+ posts

scratchattach - A Scratch API wrapper (Python)

Eason_9 wrote:

(#2276)

EpicCoderGamer1000 wrote:

(#2268)

Eason_9 wrote:

I already installed scratchattach but it says I haven't. Can anyone help?

Picture here btw: https://u.cubeupload.com/eason_9_lol/Screenshot2024012015.png

(also cloud logs are up!!!! )

What are you using to code

Also you don't need to use the cloud emoji to set a var
I used VS Code for coding and cmd for downloading
bump for my post

*This is my signature, more info on it here! Scroll down by highlighting anywhere and press shift and the down arrow key.

Get your images up to the forums with my shop: Imagif Hosters (for free!)
If you have some time to spare, perhaps go read my Scratch Wiki essays!
And since I'm here I should probably advertise my projects but I can't find a good project I made.
11 (almost 12) - He/Him
TheMobileGames
Scratcher
100+ posts

scratchattach - A Scratch API wrapper (Python)

TimMcCool wrote:

I think in the use case you described, the gain in speed wouldn't justify the effort to code something like that.
Correct since this is just an example; I’m coding something different but I feel that there is no need to explain it as it will cause more confusion to answer the original question directly.

TimMcCool wrote:

TheMobileGames wrote:

If there isn’t one already, there should be a function in Scratchattach that can “just” handle setting 5-10 cloud variables with each being changed 10 times a second.
That's an interesting idea tho. This feature doesn't exist atm, but I might add something like this to scratchattach in the future
That would be really nice if you could add that feature, which does whatever is needed internally to set many cloud variables (up to 10) at max speed (10 times a second).

TimMcCool wrote:

When coding something like this, beware that the on_set event will also be called when the cloud variable is set to 0 by the Python script. To prevent an infinite loop of on_set events caused by the Python script itself, add something like this to the on_set event:
    if str(event.value) != "0":
        ...
Yep, I already have fixed that problem in my actual script that I am working on.

I am going to try to make a similar function to the one I made in the code below. It takes in “event.var” as an input and uses the last used connection to set the variable to “0”.
import scratchattach as scratch3
session = scratch3.login("TheMobileGames", os.environ["PASSWORD"])
conn_list = [session.connect_cloud("project_id") for i in range(10)]
print(conn_list) # yep it works
next_conn_to_use = 0
def set_var_with_old_conn(var_name):
    global next_conn_to_use
    conn_list[next_conn_to_use].set_var(var_name, 0")
    if next_conn_to_use == 9:
        next_conn_to_use = 0
    else:
        next_conn_to_use += 1
events = scratch3.CloudEvents("project_id")
@events.event
def on_set(event):
    if str(event.value) != "0":
        set_var_with_old_conn(event.var)
@events.event
def on_ready():
   print("Event listener ready!")
events.start()

Last edited by TheMobileGames (Jan. 21, 2024 04:47:27)


—————————— —————————— —————————— —————————— ——————————
A way to make any game easily mobile (no remixing needed): https://scratch.mit.edu/discuss/topic/733837
My mobile engine (use to add buttons/controls to a game): https://scratch.mit.edu/projects/778848092/
—————————— —————————— —————————— —————————— ——————————
TheMobileGames
Scratcher
100+ posts

scratchattach - A Scratch API wrapper (Python)

Update: Much much less data is lost which is very exciting but there are still a few problems. After a while (about 30 seconds) setting cloud variables no longer works although I can see, in console, when an event is triggered. To fix this do I really have to open a bunch of connections and after 20-30 seconds, I would need create more connections and switch to them, afterwards, I need to close the old connections and repeat? Also how often should I create new connections?

Last edited by TheMobileGames (Jan. 21, 2024 21:14:26)


—————————— —————————— —————————— —————————— ——————————
A way to make any game easily mobile (no remixing needed): https://scratch.mit.edu/discuss/topic/733837
My mobile engine (use to add buttons/controls to a game): https://scratch.mit.edu/projects/778848092/
—————————— —————————— —————————— —————————— ——————————
ShadowMilo
Scratcher
13 posts

scratchattach - A Scratch API wrapper (Python)

yoooo the cloud logs are back!!!!!!!![/b]:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D
EpicCoderGamer1000
Scratcher
74 posts

scratchattach - A Scratch API wrapper (Python)

Eason_9 wrote:

Eason_9 wrote:

(#2276)

EpicCoderGamer1000 wrote:

(#2268)

Eason_9 wrote:

I already installed scratchattach but it says I haven't. Can anyone help?

Picture here btw: https://u.cubeupload.com/eason_9_lol/Screenshot2024012015.png

(also cloud logs are up!!!! )

What are you using to code

Also you don't need to use the cloud emoji to set a var
I used VS Code for coding and cmd for downloading
bump for my post
Hey I also use vs code for all of my coding using scratch attach and I used the terminal inside vs code to install scratchattach. I did not use the cmd to install scratch attach. Hope this helps!

epic coder gamer 1000
Mooaus2940
Scratcher
90 posts

scratchattach - A Scratch API wrapper (Python)

Hello, im austin and im wondering, do you use the scratches api, or did you make your own?



big thanks to @Pixilized for the awesome photo! /|\
Air_heads
Scratcher
89 posts

scratchattach - A Scratch API wrapper (Python)

Mooaus2940 wrote:

Hello, im austin and im wondering, do you use the scratches api, or did you make your own?

Scratchattach utilizes the API provided by Scratch.
Mooaus2940
Scratcher
90 posts

scratchattach - A Scratch API wrapper (Python)

Air_heads wrote:

Mooaus2940 wrote:

Hello, im austin and im wondering, do you use the scratches api, or did you make your own?

Scratchattach utilizes the API provided by Scratch.
Ok, how did they get the Auth token?



big thanks to @Pixilized for the awesome photo! /|\
Eason_9
Scratcher
1000+ posts

scratchattach - A Scratch API wrapper (Python)

EpicCoderGamer1000 wrote:

(#2283)
Hey I also use vs code for all of my coding using scratch attach and I used the terminal inside vs code to install scratchattach. I did not use the cmd to install scratch attach. Hope this helps!
Is it required to use the terminal inside vs code to install scratch attach for it to work?

*This is my signature, more info on it here! Scroll down by highlighting anywhere and press shift and the down arrow key.

Get your images up to the forums with my shop: Imagif Hosters (for free!)
If you have some time to spare, perhaps go read my Scratch Wiki essays!
And since I'm here I should probably advertise my projects but I can't find a good project I made.
11 (almost 12) - He/Him
ajskateboarder
Scratcher
1000+ posts

scratchattach - A Scratch API wrapper (Python)

Mooaus2940 wrote:

Air_heads wrote:

Mooaus2940 wrote:

Hello, im austin and im wondering, do you use the scratches api, or did you make your own?

Scratchattach utilizes the API provided by Scratch.
Ok, how did they get the Auth token?
I'm pretty sure scratchattach POSTs user credentials to scratch.mit.edu/login and gets the session ID cookie from the response, which is basically the token used to do user-specific actions

Eason_9 wrote:

EpicCoderGamer1000 wrote:

(#2283)
Hey I also use vs code for all of my coding using scratch attach and I used the terminal inside vs code to install scratchattach. I did not use the cmd to install scratch attach. Hope this helps!
Is it required to use the terminal inside vs code to install scratch attach for it to work?
It doesn't matter what terminal you use, but the terminal in VSCode is recommended since it opens alongside code

Last edited by ajskateboarder (Jan. 22, 2024 13:05:26)

Eason_9
Scratcher
1000+ posts

scratchattach - A Scratch API wrapper (Python)

ajskateboarder wrote:

(#2288)
It doesn't matter what terminal you use, but the terminal in VSCode is recommended since it opens alongside code
umm then how about this?

Eason_9 wrote:

(#2267)
I already installed scratchattach but it says I haven't. Can anyone help?

Picture here btw: https://u.cubeupload.com/eason_9_lol/Screenshot2024012015.png

*This is my signature, more info on it here! Scroll down by highlighting anywhere and press shift and the down arrow key.

Get your images up to the forums with my shop: Imagif Hosters (for free!)
If you have some time to spare, perhaps go read my Scratch Wiki essays!
And since I'm here I should probably advertise my projects but I can't find a good project I made.
11 (almost 12) - He/Him
EpicCoderGamer1000
Scratcher
74 posts

scratchattach - A Scratch API wrapper (Python)

Eason_9 wrote:

ajskateboarder wrote:

(#2288)
It doesn't matter what terminal you use, but the terminal in VSCode is recommended since it opens alongside code
umm then how about this?

Eason_9 wrote:

(#2267)
I already installed scratchattach but it says I haven't. Can anyone help?

Picture here btw: https://u.cubeupload.com/eason_9_lol/Screenshot2024012015.png
Its better to use the terminal in vs code because thats how i got scratchattach to work

epic coder gamer 1000
caftingdead261
Scratcher
96 posts

scratchattach - A Scratch API wrapper (Python)

TimMcCool wrote:

RandomPerson13764 wrote:

bro, remove the module. delete it now. people are hacking with it like crazy!
Just like every useful tool, scratchattach can be abused. However, deleting the library would harm Scratch's Python dev community while it wouldn't stop hackers at all: There are plenty of other libraries that support setting cloud variables (many of these existed before scratchattach). Hackers could just use one of these libraries instead.
I don't get it what is so bad about scratch attach?
can someone tell me?

I make random stuff and experiment with cloud variables.
I love Scratch mods and projects that use scratch in unique ways.
(semi-active) (only active on forms)
when F5 is clicked :: hat events
unlock a whole new perspective

ScratchTheCoder12345
Scratcher
500+ posts

scratchattach - A Scratch API wrapper (Python)

W W W CLOUD LOGS ARE BACK!!!

Hello, I'm Brandon a Python developer who loves math and coding.
he/him
Feel free to message me with any questions
ajskateboarder
Scratcher
1000+ posts

scratchattach - A Scratch API wrapper (Python)

caftingdead261 wrote:

TimMcCool wrote:

RandomPerson13764 wrote:

bro, remove the module. delete it now. people are hacking with it like crazy!
Just like every useful tool, scratchattach can be abused. However, deleting the library would harm Scratch's Python dev community while it wouldn't stop hackers at all: There are plenty of other libraries that support setting cloud variables (many of these existed before scratchattach). Hackers could just use one of these libraries instead.
I don't get it what is so bad about scratch attach?
can someone tell me?
People are using it for various “exploits” by setting cloud variables to values so they can show up on the leaderboard. Deleting the module is pointless – what really should be done on Scratch's part is securing their cloud variable interfaces
Eason_9
Scratcher
1000+ posts

scratchattach - A Scratch API wrapper (Python)

Eason_9 wrote:

(#2290)

ajskateboarder wrote:

(#2288)
It doesn't matter what terminal you use, but the terminal in VSCode is recommended since it opens alongside code
umm then how about this?

Eason_9 wrote:

(#2267)
I already installed scratchattach but it says I haven't. Can anyone help?

Picture here btw: https://u.cubeupload.com/eason_9_lol/Screenshot2024012015.png

bump for my post

*This is my signature, more info on it here! Scroll down by highlighting anywhere and press shift and the down arrow key.

Get your images up to the forums with my shop: Imagif Hosters (for free!)
If you have some time to spare, perhaps go read my Scratch Wiki essays!
And since I'm here I should probably advertise my projects but I can't find a good project I made.
11 (almost 12) - He/Him
EpicCoderGamer1000
Scratcher
74 posts

scratchattach - A Scratch API wrapper (Python)

Eason_9 wrote:

Eason_9 wrote:

(#2290)

ajskateboarder wrote:

(#2288)
It doesn't matter what terminal you use, but the terminal in VSCode is recommended since it opens alongside code
umm then how about this?

Eason_9 wrote:

(#2267)
I already installed scratchattach but it says I haven't. Can anyone help?

Picture here btw: https://u.cubeupload.com/eason_9_lol/Screenshot2024012015.png

bump for my post
So you must have downloaded the file onto your pc when you ran the command in the cmd. To use scratchattach in vs code download scratchattach using the terminal in vs code.

epic coder gamer 1000
Eason_9
Scratcher
1000+ posts

scratchattach - A Scratch API wrapper (Python)

EpicCoderGamer1000 wrote:

(#2281)
So you must have downloaded the file onto your pc when you ran the command in the cmd. To use scratchattach in vs code download scratchattach using the terminal in vs code.
I tried, but it said that requirements are already satisfied and refused to download

Last edited by Eason_9 (Jan. 30, 2024 06:34:50)


*This is my signature, more info on it here! Scroll down by highlighting anywhere and press shift and the down arrow key.

Get your images up to the forums with my shop: Imagif Hosters (for free!)
If you have some time to spare, perhaps go read my Scratch Wiki essays!
And since I'm here I should probably advertise my projects but I can't find a good project I made.
11 (almost 12) - He/Him
caftingdead261
Scratcher
96 posts

scratchattach - A Scratch API wrapper (Python)

ajskateboarder wrote:

caftingdead261 wrote:

TimMcCool wrote:

RandomPerson13764 wrote:

bro, remove the module. delete it now. people are hacking with it like crazy!
Just like every useful tool, scratchattach can be abused. However, deleting the library would harm Scratch's Python dev community while it wouldn't stop hackers at all: There are plenty of other libraries that support setting cloud variables (many of these existed before scratchattach). Hackers could just use one of these libraries instead.
I don't get it what is so bad about scratch attach?
can someone tell me?
People are using it for various “exploits” by setting cloud variables to values so they can show up on the leaderboard. Deleting the module is pointless – what really should be done on Scratch's part is securing their cloud variable interfaces
Don't you need to own the project to change them?

I make random stuff and experiment with cloud variables.
I love Scratch mods and projects that use scratch in unique ways.
(semi-active) (only active on forms)
when F5 is clicked :: hat events
unlock a whole new perspective

Powered by DjangoBB