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:
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.