Abilities and Deleted Code
Difficulty: 4/5
Use case: Learning the mechanics of Hopscotch and using that to reduce the number of times you get filtered due to words found in deleted code,
WARNING: This tip is very word-heavy and refers to one code example throughout the post. It may be hard to understand, especially if you lose your train of thought quickly.
However, it is of the inner working space of the app that I believe everyone should try to understand. It also helps you understand how people like awesomeonion organize their code to create apps like Hopscotch.
And do remember, this one example might not cover all of your questions. If you have any, please feel free to ask and hopefully I’ll answer them.
Anyways, let’s start.
This can really only be explained with some example code, so here is your example:
How Hopscotch sorts its code (sorting blocks into abilities)
- Open the object editor.
- Anything inside a Block that you can collapse (blocks inside game rule, blocks inside conditionals, blocks inside draw blocks, Blocks inside abilities, etc.) are all classified as “ability scripts” by Hopscotch. Each set of blocks that fall under a collapsible is considered one ability script.
- Look at the image below.
- Script one is highlighted in red. It contains every block inside the game rule, but nothing inside any other collapsible blocks. The repeat forever block, as well as any other collapsible, is what we call a “pointer”. Pointers tell Hopscotch to look for another script and load that in.
Why is it called a pointer
The following is the all of the blocks’ code for the ae_json_edit ability.
{
"controlScript": {
"abilityID": "7C8820C8-ED77-4806-8E95-5299A30C30CF-328-0000002828F016FB"
},
"block_class": "conditionalControl",
"description": "Check Once If",
"type": 122,
"parameters": [
{
"defaultValue": "",
"value": "",
"key": "",
"datum": {
"block_class": "conditionalOperator",
"type": 1000,
"description": "=",
"params": [{"defaultValue":"7","value":"7","key":"","type":42},{"defaultValue":"7","value":"7","key":"=","type":42}]
},
"type": 49
}
]
}
You can see that there is just one block here. There’s information about the check once if Block (its ID, description, parameters), and a “control script”. There is no clear block here, which means that the clear block inside is actually stored in a separate ability, and that is why we call it a “pointer”. The conditional block “points” to the ability (using the control script key) that contains the clear block.
- So, applying this example to the image with highlights, we can see that the game rule only really contains ability 1. The repeat forever “points” to ability 2, containing blocks highlighted in yellow. Lastly, the repeat and conditional blocks once again “point” to separate abilities (3 & 4) that contain the final wait blocks.
How it affects deleting code (how Hopscotch deletes code)
Let’s look back at this code again, with the abilities highlighted.
We’re going to delete the “Repeat Forever” block in this example.
Background info that’s important
When does Hopscotch actually clean its code?
- When you publish a project
- When you load a project into the editor (maybe when you save/upload but i don’t think so – awesomeonion can confirm)
What does it do?
- “Removes deleted abilities”
- Removes “corrupted” variables
- Resets UUIDs throughout the project
- some other background stuff
Our focus here is going to be the first one: removing deleted abilities
Q: What is a deleted ability?
A: An ability (or control script) is considered deleted when no block, custom block, or game rule “points” to that ability anymore.
Q: So what happens to them?
A: When you open or publish a project, any abilities that don’t have a block/custom block/game rule pointing to them anymore are deleted. Let’s use our example below.
Applying that information
In a sequence, this is what happens:
- You delete the repeat forever block from your code.
- You make changes to other game rules or objects in the project (or not).
- You exit the project to play Minecraft.
- You come back to Hopscotch and tap on that draft.
- The cleaning procedure begins by detecting what abilities are “pointed to”, or “referenced”. The game rule still points to ability 1. Blocks inside Ability 2 (repeat and check if) point to abilities 3 and 4 – keep in mind, ability 2 still exists. But ability 1 no longer points to ability 2, as the repeat forever block was deleted.
- Unreferenced abilities get deleted. In this case, ability 2 gets deleted. However, abilities 3 and 4 will stay there because ability 2 still pointed to them. Weird, I know. Basically, the blocks that exist in the JSON file now go in this order: set variable, wait, wait.
- You exit the project again to go eat dinner.
- You tap on the draft again. Cleaning starts. Abilities 3 and 4 are no longer pointed to, now that ability 2 is actually removed. Therefore, they also get deleted and the only Block left is the set variable at the beginning.
How does this affect me, as the “publisher” of the project?
- If ability 3 or 4 contained a filtered word in a set text, that would only be deleted after 2 rounds of cleaning. If it was deeper in a loop, it’d take more re-entering a project. When published, that text could easily still be in your project.
- File size is bigger unless you cycle through the cleaning process enough times, but that’s minor.
How can I negate this behavior?
- You can do what I like to call a “true code deletion”, but this has to be made into a habit. When you delete any collapsible block (check if blocks, repeats, custom blocks, draw trail, game rules), delete everything inside that first, if there is a collapsible block, delete contents inside that first. If that contains a collapsible block, start the process over again. I still use this method.
- Example: in our reference image, a true delete of the repeat forever block goes like this:
- Delete abilities 3 and 4 (the wait blocks only) so that they are deleted as soon as you leave the object.
- Delete ability 2 (the increase variable, repeat, and check if). Now, when you re-enter the project, this and ability 3&4 are already gone.
- Delete the repeat forever block.
If that’s too you are too lazy to make that a habit and only care about the filtered words:
- Use my Shortcut (the web page does not work for this example).
- Save the project and run it. Skip the project preview and don’t choose to modify anything, If a known filter word is present in an ability like ability 3 (you deleted it but it is still in the code), it will ask if you want to replace it with “[AES]”, tap replace. Save your project.
- Do Bear this in mind: if a word inside that half-deleted ability cause your project to be filtered and we don’t know about that word, there is no way to tell. I can still extract the text and will find the word eventually, but you will have to remove it through lots of cycling, with my shortcut, or other means of modding the project.
Demo Project – really?
Yeah. Here’s what the project does:
- When you save & open the project or remix it, a half-deleted “set text to ‘original’ color black” gets fully removed. When looking at the JSON file, the linked project has this block in its code, but any remixes or opened drafts will not (found by searching for text “original” and excluding the match in the title).
What can you do with it?
- Not much, except filter just one copy of a project I guess. But if you can find a way to detect half-deleted code, props to you. Please @ me if that happens.
Another demo, what is this? (Yes)
- The “pointer” system is what I used to lock my EHSHQHHC project. By looping a pointer uuid into a control false script that would never actually run in a project, I made it so anything with such block would be unable to render and therefore would crash Hopscotch upon trying to preview it. This is in one game rule in every object and custom rule.
@AwesomeOnion you could probably use a part of this in your topic (How Hopscotch works) as well as correct any misconceptions or confirms any claims I have in this post, as I believe that will help inform Hopscotchers a little bit more about the JSON file of a Hopscotch project.
I think I have covered abilities to a decent extent, and that is probably the hardest one to explain.
Anyways, thanks for your time in reading this, can’t wait to see what’s next with Hopscotch