Persistent Variables - Saving data across project plays

#1

What should be added

In many programming languages, text-based and visual, there is some way to save data between code execution sessions - in other words, you can take a variable, and somehow save it for “next time”. In some cases, this is through file IO - saving your data in a .json file or something similar. In others, you can save data through simple methods that save or retrieve a piece of data with a key, or “name”.

Hopscotch lacks anything like this. In other words, Hopscotch variables are per-session. Nothing can be saved or retrieved at a later time. This can be very limiting for things like games, where you might want to save a player’s high score. Or maybe you want to save some parameters in a tool or simulation.

To solve this issue, I’m proposing “saved” or “persistent” variables. These are variables that will keep their value, even when you exit a project. This will allow for things like high scores, or saving a whole game state for later.

Just to clarify, saved variables will be local. They don’t go to anyone else, they are just on your device.

Implementation details

Saved variables could be saved in a .json file, or another data format, along with the project. This way, when a project is duplicated, deleted, or something else, the saved variables go along with it.

When a saved variable is created, it would get a random, unique ID, which would be used to reference its value in the save file. This way, if you delete a variable, then create a saved variable with the same name, it won’t get the value of the variable before.

Also, a way to access and modify these values in project drafts could be nice, for things like beta-testing.

Overall, saved variables would be very useful for all kinds of Hopscotch projects.

22 Likes
#2

This would be amazing! This should definitely be added.
(It might help if you tagged some people. @Ana @Rodrigo.)

First Post yes…

7 Likes
#3

That would be really cool! You could be able to do save states for games much easier then without having some code that people can easily use to cheat the game.

4 Likes
#4

If you guys look at the hopscotch roadmap, I believe this is on it. EDIT: I was wrong, they’re not on there.

2 Likes
#5

Is this the same thing as cloud variables?

4 Likes
#6

pretty much I think

2 Likes
#7

Cloud vars would be another type of game changer

2 Likes
#8

This would be really handy, and like @UTheDevHS said it would be a “game changer” for sure!

2 Likes
#9

Is it possible to code this in Hopscotch?

1 Like
#10

No. Cloud variables would be shared between all the different devices currently playing a project, while persistent variables are kept on one device.

4 Likes
#11

Not at the moment.

1 Like
#12

This would be very useful, I totally agree! Great suggestion.

3 Likes
#13

Based on prior comments, I agree :wink:

However, I think even the local persistent variables should be saved in the cloud so they’re not lost if a user reinstalls Hopscotch or switches devices.

8 Likes
#14

I just found a bug that does exactly this, it preserves the game state between plays.
I’ll try to upload footage if I can get any.
image

5 Likes
#15

Hmm there’s lots of topics like this @Valgo… I know by fact that they already took the idea into consideration

2 Likes
#16

Sadly if you look at the roadmap, it’s not on there. So it’s possible? … maybe?

2 Likes
#17

woah? I assume that it doesn’t seem to work if you exit the project though, sadly…

2 Likes
#18

I was working on something similar to that but it plays at like 5 fps.

When are you going to publish that?

2 Likes
#19

Global Highscores

But then you could code some sort of message chat room app though, with the string storage method. That’d be interesting to implement


Random multiplayer battles with real people
It’d depend if the varaibales were saved instantaneously, or only when the project is exited

3 Likes
#20

It’s probably a heap memory bug

3 Likes