Discuss Scratch

suswhopper123
Scratcher
1000+ posts

How do I make my import/export system SHORTER?

In my game, Youtube Simulator X (https://scratch.mit.edu/projects/1164514604 ), you can import your game by pressing I and export it by pressing E. The problem with this system is that it`s VERY long. To simply have 1k subs and 1k SD, this code is used ~|!~~~|~|!|!|!~~~|!|!| which has a whopping 22 CHARACTERS. I wanna know how to make it shorter, because I am planning to add prestige and more mechanics, which will add a lot of characters to the code and will make comment sections that show their projects A MESS. (all the import/export code is in the “Import/Export” sprite)
AHypnoman
Scratcher
1000+ posts

How do I make my import/export system SHORTER?

22 characters seems reasonable, but if you want to reduce it you'll need a different format.

A more human-readable format, and something similar to what I often use, may look something like this:

|@subs|1000|@SD|1000

but this is still 20 characters. You can reduce that somewhat if you don't care about readability, i.e. |@1|1000|@2|1000 (16 characters), and can reduce it by a further 1 char per entry if you don't intend on saving strings – |a|1000|b|1000

To generate a savecode like this, it's fairly simple: use join blocks to join the ‘keys’ (names of values like ‘@subs’) to their values, something like this:

set [savecode v] to (join [|@subs|] (join (subs) (join [|@SD|] (SD))))

To load the savecode, you'll need to iterate through it with a loop and add everything between the pipes (these things -> | ) to a separate list. From there, to get a value by its corresponding key you can use this code:

(item ((item # of [@subs] in [loaded savecode v]) + (1)) of [loaded savecode v] :: list)

– If you want to reduce the length even further, remove the keys altogether and just join the values (still separated by pipes) to create a savecode: |1000|1000. You load the savecode into a list in the same way, but getting the values back is slightly different:

Without keys, you'll need to make sure that the savecode is always put together in the same order. This means that we can get values out in the same order we put them in (so if the first value put into the savecode is ‘subs’, item 1 of the list will be the value of subs).

This is less human-friendly and possibly harder to change in the future, but does reduce it down to 10 characters.
suswhopper123
Scratcher
1000+ posts

How do I make my import/export system SHORTER?

The other values are there for other variables, that's why it's so long.
AHypnoman
Scratcher
1000+ posts

How do I make my import/export system SHORTER?

suswhopper123 wrote:

The other values are there for other variables, that's why it's so long.
If that's the case I think you're going to struggle to reduce the length. I don't really see why longer savecodes would be a problem for you anyways.
nomos13
Scratcher
16 posts

How do I make my import/export system SHORTER?

it looks like your current format is BASICALLY ternary, try looking up base conversion projects.

Last edited by nomos13 (Aug. 18, 2025 23:50:24)

Powered by DjangoBB