Discuss Scratch

WhysAlives
Scratcher
22 posts

Issues With Cloud Variables

I've created a public poll that allows users to select from the poll answer options and then their vote shows up in a list along with their user name. Everyone gets to see how everyone voted. Problem is, the cloud data is updating sporadically. Sometimes I can make a vote, leave, come back, and my vote is still there. Other times I can vote, leave, and when I come back it's gone. When I look at the cloud history, it's confusing and doesn't seem to match.

I am only storing numbers in the cloud. Why is it losing the data?

It is generally against my better judgement to make a project public before it works, but here it is: Dad's Generic Poll

Thanks for any help.
WhysAlives
Scratcher
22 posts

Issues With Cloud Variables

I've made the cloud variables visible and what it shows in the project and what it shows in the cloud data history are different. The project shows the user being stored as an encoded number, but the history shows it being set to zero. How can these two things be different?
WhysAlives
Scratcher
22 posts

Issues With Cloud Variables

Wait… wait?? It just updated on my project screen suddenly to zero. What am I missing here?
marcelzietek2006
Scratcher
500+ posts

Issues With Cloud Variables

ill take a look
marcelzietek2006
Scratcher
500+ posts

Issues With Cloud Variables

i think your cloud variables are broken….
They update on the project and Cloud History but if you reload it will magically be reverted just for you
sorry but i really dont know
and if my calculations are correct, only like max 16-20 (with normal long names) can fit in one cloud?
I would say just try deleting/repplacing the cloud variables
(also add wait between setting cloud variables (or else they dont register )
setCloudvarto131313142351453463575687wait0.1secs
WhysAlives
Scratcher
22 posts

Issues With Cloud Variables

marcelzietek2006 wrote:

i think your cloud variables are broken….
They update on the project and Cloud History but if you reload it will magically be reverted just for you

Exactly! So I am not going crazy.

marcelzietek2006 wrote:

and if my calculations are correct, only like max 16-20 (with normal long names) can fit in one cloud?

Yeah, I'm breaking up the serialized lists into 4 variables for each list, so ultimately I should get about 45 users before there is a memory error. It informs the user when that happens.

marcelzietek2006 wrote:

also add wait between setting cloud variables or else they dont register

Whaaaaat..??? That's news to me. Are you sure that isn't the whole problem here?

Thank you much for your help.

Last edited by WhysAlives (Feb. 5, 2020 21:12:53)

marcelzietek2006
Scratcher
500+ posts

Issues With Cloud Variables

WhysAlives wrote:

marcelzietek2006 wrote:

also add wait between setting cloud variables or else they dont register

Whaaaaat..??? That's news to me. Are you sure that isn't the whole problem here?
I made a remix (didnt publish) where i added the wait and it was still broken…
so unfortunately no.
WhysAlives
Scratcher
22 posts

Issues With Cloud Variables

The strangeness continues…

I deleted and remade the cloud variables and put a 0.1 wait after setting each cloud variable. But now…

I make my vote and it shows it set in the cloud. Appears to show it in the history as well. So that's a win. But when I come back the cloud data shows as zero so the vote results don't show up. Then after half a second, the cloud data suddenly updates and shows as the encoded strings they were set to before I left. But by that point, the results list has already been updated as empty. It's weird.

It looks like the fundamental problem is that the cloud variables update slowly and if you try to update them multiple times before they have had time to respond then the data gets jumbled. I might need to try a ‘wait until’ that watches for the update on the server's end before considering a cloud variable set. But oh man will this affect performance.

Last edited by WhysAlives (Feb. 5, 2020 22:12:59)

WhysAlives
Scratcher
22 posts

Issues With Cloud Variables

Thanks again for your help. I'm going to set the project to private again until I've tried a few more things. I hope you're still around if nothing I try works.
colinmacc
Scratcher
1000+ posts

Issues With Cloud Variables

My observations are sometimes it takes a couple of seconds before cloud variables are “connected”, for want of a better word, after loading the project.

Just make sure there's a delay before reading the cloud variable for the first time after the green flag is clicked, and you should be ok.

Failing that, many cloud variable problems appear to get solved if you rename the variable.
WhysAlives
Scratcher
22 posts

Issues With Cloud Variables

colinmacc wrote:

My observations are sometimes it takes a couple of seconds before cloud variables are “connected”…

The thing is, there appears to be local versions for the server variables. So if I look at them, I see my own copies. How am I supposed to know when they've been updated? I just have to wait an indefinite amount of time and hope that works? That doesn't sound ideal.

I suppose I could set them to a dummy value at startup and wait to see when they change, but that only handles startup. Is there a way to know when my local copy has been received by the server upon set? An indicator of any kind sure would be super useful right about now.

Wait.. nevermind. I can't set them to a dummy value without the server eventually receiving it. huh…

Last edited by WhysAlives (Feb. 5, 2020 23:46:10)

WhysAlives
Scratcher
22 posts

Issues With Cloud Variables

It's a little dated (2016), but TheLogFather appears to give a definitive answer here: What Is The Delay Between Cloud Variable Updates?

The delay I can live with. But no indicator? *sigh*

Given that my project will need to work for users with slow connections, synchronizing data is going to be rather slow. Times to start work on that hourglass icon…
WhysAlives
Scratcher
22 posts

Issues With Cloud Variables

Woohoo! It looks like I've gotten it all working. The most important part was insuring a 0.1 wait after setting any cloud variable. This is apparently by design. I assume to prevent flooding. Basically, the request goes into the queue and if you make another request before it is handled by the server, it overwrites the previous request.

Limited testing so far, so I am not 100% confident there aren't still problems, but I'll update this thread if there are.
colinmacc
Scratcher
1000+ posts

Issues With Cloud Variables

WhysAlives wrote:

Woohoo! It looks like I've gotten it all working. The most important part was insuring a 0.1 wait after setting any cloud variable. This is apparently by design. I assume to prevent flooding. Basically, the request goes into the queue and if you make another request before it is handled by the server, it overwrites the previous request.

Limited testing so far, so I am not 100% confident there aren't still problems, but I'll update this thread if there are.

Yeah that's correct, you need a 0.1 second delay between ANY cloud update. Nice that you got it working!

I created this project, which I thought would test the delay after pressing the green flag, before the cloud is connected…

https://scratch.mit.edu/projects/365754238/

Basically, the project is saved with “A” in the cloud var (which is obviously impossible to store in the cloud) …. so if you run the project when you're not logged in (or you're a new scratcher) the var remains as “A” because you never connect to the cloud. However when a logged-in person connects, it should calculate the time when the cloud var becomes 1 (i.e. the value from the cloud) … but as I said, it's always instant for me when I'm logged in, so I don't know anymore
WhysAlives
Scratcher
22 posts

Issues With Cloud Variables

colinmacc wrote:

…the project is saved with “A” in the cloud var (which is obviously impossible to store in the cloud) …. so if you run the project when you're not logged in (or you're a new scratcher) the var remains as “A” because you never connect to the cloud.

That's brilliant! What happens to the cloud var when you set the local copy to text? Does it remain unchanged? Because if it does… (drum roll)… we have an indicator! This can do more than detect connection. If you fill a local cloud var with dummy data and it doesn't affect the data on the server's side , then you can watch for when the dummy data is replaced with the live value from the server! That will tell us when server has received the set.

Thank you so much for sharing this idea!
colinmacc
Scratcher
1000+ posts

Issues With Cloud Variables

WhysAlives wrote:

That's brilliant! What happens to the cloud var when you set the local copy to text? Does it remain unchanged? Because if it does… (drum roll)… we have an indicator!
As far as I can tell (looking at the cloud log) it remains unchanged, yeah.
WhysAlives
Scratcher
22 posts

Issues With Cloud Variables

Wow this things is problematic.

https://scratch.mit.edu/projects/366000484/

Everything was working fine, then suddenly the server stops returning the two serialized string variables. Increasing the wait time to 0.2 didn't fix it. So I renamed the variables and named them back and now they're being updated by the server again. Unfortunately, that update delay caused votes to get overwritten when the old data was resent by other voters. What the heck makes these variables so unreliable?

I'm also not certain that page caching isn't a threat to my cloud data. I had one instance where the server didn't update the variables until I did a cntrl-shift refresh on my browser. I'm starting to wonder if this whole system is just too unstable.
colinmacc
Scratcher
1000+ posts

Issues With Cloud Variables

I just tried it and it seems to be working fine at the moment.
WhysAlives
Scratcher
22 posts

Issues With Cloud Variables

So it doesn't appear dummy data works quite the way I was hoping. Unfortunately, when you change a cloud variable, the update is only sent to the *other* clients, not your own. I can trigger another client to update a different cloud variable as an indicator sent back to the first client, but that requires two clients.
20100531T
Scratcher
11 posts

Issues With Cloud Variables

Hi, I am @20100531T,
If you want to use cloud variable, you need to become a scratcher first!

Powered by DjangoBB