Variables are more useful than you think (A brief guide on Variable Translation)

You barely ever see variables being used in guides on the forum, mainly because they’re pretty unconventional/unhelpful.

Why? Because variables are unique in the way that they are only available to use in one specific block of code, rather than being available to every device and block like a property. This renders them virtually useless in the role of holding a value.

However, if you had a property that was only being used in one specific block code, and nothing else, you could switch it out for a variable, getting rid of those pesky get property 's and etc, saving you a few blocks. I like to call this process Variable Translation.
Variable Translation is fairly simple in concept.
2 things are necessary steps:

  • Sending info in (Property → variable)
  • And taking it back out. (Edited variable → Property)

Here’s a theoretical comparison of two codes that serve the same purpose, but one replaces some properties with variables:
Exhibit A. Exhibit B

The first image has 27 pieces, and the second only has 21. It cut down on the unnecessary blocks and used variables instead. Both codes serve the same purpose, though: calculating values that are combined to create abc.

Think of it like writing a bank check. You can write these variable ‘checks’ to hold property value, which you’ll ‘pay back’ in the same block by using them to update a property. That way, you don’t have to ‘open up’ a whole new property ‘account’ which you may never ‘withdraw from’ again.

In other words, if you create a variable, it can be a one-time value and not take up so much space by using a new property.


Another good example of where VT could come in handy is unpacking save codes. You’d be allowed to unpack up to 11 letters per block, essentially more than doublinh the space you’d take up with unpacking using properties. Here’s what it would look like:


(Please feel free to correct me if this isn’t the most effective way to unpack a save code, I’m still a bit new to that part of TGK, but I try to contribute when I can : ] )

And that’s my opinion on variables when it comes to uses! Thank you for reading and please contribute your thoughts in the comments.

9 Likes

It’s about devices. If this won’t go there, what will?

1 Like

great guide! make sure to add it to Community Made Guides

1 Like

I’m not sure if it’s really a guide, since it only gives an overview on the topic rather than giving instructions on how to make something using it. Thank you for your input, though!

2 Likes

This is a great description of variables particular to GKC

@cheesebox

Your save code exportation system is good since you don’t go past 11, however if you did and couldn’t fit it in blocks then recursion would be the best method

It actually can go past 11! Notice the ‘unpack2’ at the bottom of the code. It would be received to unpack another chunk.

Ah. Then you recursion would probably be beneficial but it would require two more properties to correctly function

It’s definitely not the most effective way to unpack a save code… but it works. Best way would be to use markers to indicate the start and end of chunks of data and load those into properties.
(Guide on that coming soon)

3 Likes

I literally used variables an hour ago while helping my friends make a

Copyright alert

minecraft

map lol

By recursion do you mean concatenation?
Concatenation: cutting down on repetitive code
Recursion: Something triggering itself

Both since it would have to call itself lol

The one thing about variables is that they don’t save after the block gets run. So, unfortunately, you can’t use them as properties for a specific block. But variables are very helpful for a mod function:
image

1 Like

Real quick can you explain the uses of a mod function. I have read the guide but i don’t understand its purpose or how it accomplishes that but I do understand most other parts of technical gimkit.

First up, not everything that is complex is technical gimkit. A mod function takes the remainder of some number when divided by another number.

1 Like

Wow. Incredibly easy.

I read some stuff above and I agree with GimSolver. There’s a lot of different guides but there are only 4 categories. Do you think it’s too off topic to share my ideas on the forum?

I think it’s fine as long as you don’t go on for 3 or more replies.

Counter argument: Variables can’t be saved, but they can be set, so just have them be set to the property to save pieces when possible

I’m pretty sure that this implies that it could also store stuff.

I know this isn’t the most useful guide, but I just wanted to bring the topic of Variable Translation to light because it could save a lot of space when possible.

1 Like