Discuss Scratch

MCAnimator3D
Scratcher
500+ posts

Decompiling a Variable

I need to decompile a variable that includes the player's costume, rank, and some other data so if you play again, you put the code in and it takes all of the numbers apart and puts them into the game. All of the things that go into the variable can be converted to an integer. The only thing I know about decompiling is that you can separate the numbers with something like a semicolon or a period. Can someone help me?


scratch
scimonster
Scratcher
1000+ posts

Decompiling a Variable

Wouldn't it be easier to use a list, which is meant for storing multiple values?

Retired Community Moderator
BTW, i run Google Chrome 41.0.2272.101 on a Linux system - Ubuntu 14.04. NEW: iPad 4th gen. w/retina.

418 I'm a teapot (original - to be read by bored computer geeks)
THE GAME (you just lost)
; THE SEMICOLON LIVES ON IN OUR SIGS
MCAnimator3D
Scratcher
500+ posts

Decompiling a Variable

scimonster wrote:

Wouldn't it be easier to use a list, which is meant for storing multiple values?
Yes, but you'll need to decompile the value in the list to put it in the game.

Last edited by MCAnimator3D (Nov. 9, 2013 20:36:45)



scratch
scubajerry
Scratcher
1000+ posts

Decompiling a Variable

http://scratch.mit.edu/projects/13636615/

You can use any single character separator. The examples are space and comma.
derniersamourai
Scratcher
100+ posts

Decompiling a Variable

If you use cloud vars, only digits are allowed.

Strategy 1: Just pack any data item within a string of digits having a fixed length. So pack and unpack is easy because you unpack a fixed number of digits for each item.

Strategy 2:for each data item use the format <length of data item><data item> and of course the <length of data item> is of fixed length.
For instance
14 is packed as 0214 (02 is the length, and 14 is the data)
1234 is packed as 041234 (04 is the length, and 1234 is the data)
1234567890 is packed as 101234567890 (10 is the length, and 1234567890 is the data)
You unpack with a loop such as:
repeat join (letter i of myvar) (letter i+1 of myvar)
….
endrepeat
MCAnimator3D
Scratcher
500+ posts

Decompiling a Variable

derniersamourai wrote:

If you use cloud vars, only digits are allowed.

Strategy 1: Just pack any data item within a string of digits having a fixed length. So pack and unpack is easy because you unpack a fixed number of digits for each item.

Strategy 2:for each data item use the format <length of data item><data item> and of course the <length of data item> is of fixed length.
For instance
14 is packed as 0214 (02 is the length, and 14 is the data)
1234 is packed as 041234 (04 is the length, and 1234 is the data)
1234567890 is packed as 101234567890 (10 is the length, and 1234567890 is the data)
You unpack with a loop such as:
repeat join (letter i of myvar) (letter i+1 of myvar)
….
endrepeat

Haha! I love how smart new Scratchers are! Thanks!


scratch
sonicfan12p
Scratcher
1000+ posts

Decompiling a Variable

Allow me to demonstrate in Scratch blocks.

derniersamourai wrote:

If you use cloud vars, only digits are allowed.

Strategy 1: Just pack any data item within a string of digits having a fixed length. So pack and unpack is easy because you unpack a fixed number of digits for each item.

Strategy 2:for each data item use the format <length of data item><data item> and of course the <length of data item> is of fixed length.
For instance
14 is packed as 0214 (02 is the length, and 14 is the data)
1234 is packed as 041234 (04 is the length, and 1234 is the data)
1234567890 is packed as 101234567890 (10 is the length, and 1234567890 is the data)

Save (1234567890)

Define Save (value)
if <(length of (value)) < [10]
set [Cloud Variable 1 v] to (join (Cloud Variable 1) (join [0] (join(length of (value)) (value))))
else
set [Cloud Variable 1 v] to (join (Cloud Variable 1) (join (length of (value)) (value)))

You unpack with a loop such as:
Unpack (Cloud Variable 1) to (Unpacked List 1)

Define Unpack (Variable) to (List)
Delete [all v] of (List)
set [Counter v] to [1]
Repeat until <(Counter) > (length of (Variable))>
set [I.V. v] to (join (letter (Counter) of (Variable)) (letter ((Counter) + [1]) of (Variable))
set [Unpacker v] to []// The above is an Intermediate Variable, I.V. for short.
change [Counter v] by [2]
repeat (I.V.)
set [Unpacker v] to (join (Unpacker) (letter (Counter) of (Variable)))
change [Counter v] by [1]
end
add (Unpacker) to (List)
Very intuitive for someone not allowed to access cloud data, do you have another account? Or are you just that good?

Last edited by sonicfan12p (Nov. 10, 2013 01:18:42)


Comeback time? Maybe?
derniersamourai
Scratcher
100+ posts

Decompiling a Variable

sonicfan12p wrote:

Very intuitive for someone not allowed to access cloud data, do you have another account? Or are you just that good?

Cloud vars have nothing to do with this.
This is just pack and unpack.

I like simple solutions, even if you have to weaken the features you want.
sonicfan12p
Scratcher
1000+ posts

Decompiling a Variable

derniersamourai wrote:

sonicfan12p wrote:

Very intuitive for someone not allowed to access cloud data, do you have another account? Or are you just that good?

Cloud vars have nothing to do with this.
This is just pack and unpack.

I like simple solutions, even if you have to weaken the features you want.
Tis true, but still. Why would you have to pack and unpack if you don't mess with the cloud?

Comeback time? Maybe?
scimonster
Scratcher
1000+ posts

Decompiling a Variable

sonicfan12p wrote:

derniersamourai wrote:

sonicfan12p wrote:

Very intuitive for someone not allowed to access cloud data, do you have another account? Or are you just that good?

Cloud vars have nothing to do with this.
This is just pack and unpack.

I like simple solutions, even if you have to weaken the features you want.
Tis true, but still. Why would you have to pack and unpack if you don't mess with the cloud?
Perhaps a non-cloud save game state, where you copy a value.

Retired Community Moderator
BTW, i run Google Chrome 41.0.2272.101 on a Linux system - Ubuntu 14.04. NEW: iPad 4th gen. w/retina.

418 I'm a teapot (original - to be read by bored computer geeks)
THE GAME (you just lost)
; THE SEMICOLON LIVES ON IN OUR SIGS
Sonickyle
Scratcher
1000+ posts

Decompiling a Variable

sonicfan12p wrote:

Allow me to demonstrate in Scratch blocks.

derniersamourai wrote:

If you use cloud vars, only digits are allowed.

Strategy 1: Just pack any data item within a string of digits having a fixed length. So pack and unpack is easy because you unpack a fixed number of digits for each item.

Strategy 2:for each data item use the format <length of data item><data item> and of course the <length of data item> is of fixed length.
For instance
14 is packed as 0214 (02 is the length, and 14 is the data)
1234 is packed as 041234 (04 is the length, and 1234 is the data)
1234567890 is packed as 101234567890 (10 is the length, and 1234567890 is the data)

Save (1234567890)

Define Save (value)
if <(length of (value)) < [10]
set [Cloud Variable 1 v] to (join (Cloud Variable 1) (join [0] (join(length of (value)) (value))))
else
set [Cloud Variable 1 v] to (join (Cloud Variable 1) (join (length of (value)) (value)))

You unpack with a loop such as:
Unpack (Cloud Variable 1) to (Unpacked List 1)

Define Unpack (Variable) to (List)
Delete [all v] of (List)
set [Counter v] to [1]
Repeat until <(Counter) > (length of (Variable))>
set [I.V. v] to (join (letter (Counter) of (Variable)) (letter ((Counter) + [1]) of (Variable))
set [Unpacker v] to []// The above is an Intermediate Variable, I.V. for short.
change [Counter v] by [2]
repeat (I.V.)
set [Unpacker v] to (join (Unpacker) (letter (Counter) of (Variable)))
change [Counter v] by [1]
end
add (Unpacker) to (List)
Very intuitive for someone not allowed to access cloud data, do you have another account? Or are you just that good?
Wow.

No I don't make projects anymore. I left some time ago.
I only check the forums every now and then, but other than that consider me retired.
epictester000
Scratcher
7 posts

Decompiling a Variable

Another method of separation is to have a unique sequence of digits that will never appear in another context. I have create a custom block here that lets you search for a string (instead of a character) within another string. The position(s) at which this is true is also given, so you could have a separator code that will be detected by a scanner variable using this block. You could also program other commands in this way. Hope this helps…
hppavilion
Scratcher
100+ posts

Decompiling a Variable

scubajerry wrote:

http://scratch.mit.edu/projects/13636615/

You can use any single character separator. The examples are space and comma.
I like to use § (section sign). I usually use it for programs that use chatroom encoding-like mechanics (mostly just submitting ideas to a group, or recording any sort of data that can use any normal character.) The benefits are that it will almost never be input, but it does need to be copy pasted (or on an apple product, option+4) into the programming.

Powered by DjangoBB