Tip of the Week | ๐“๐”€๐“ฎ๐“ผ๐“ธ๐“ถ๐“ฎ_๐“”

Must have been moved because I didnโ€™t see that.
Also Iโ€™m not the only one editing the categories, a couple of these I didnโ€™t do

2 Likes

Alternate to โ€œWait Untilโ€ Block!

https://c.gethopscotch.com/p/10ikolp9dv

Publish and unpublish to obtain this and the other secret blocks.


Anyways, itโ€™s super simple. Here are the steps:

  1. Enter the project. Itโ€™s open-sourced, which means you can publish and unpublish it and it will become yours.
  2. Go into the text object. It has only one rule.
  3. Mess with the conditional only in the โ€œwait til timstampโ€ block. That block will act as a wait until inner conditional is true.

Tag me on the GDT if you want to know more about the mechanic that allows this to work. This mechanic is also mentioned in the project itself.


Also obtainable with secret blocks and multiplying by conditionals or saving through presets (currently bugged โ€” @ me if you need this in your project). Constants inside the timestamp Block should be 12 digits or longer to work (minimum is 11 digits where each digit is anything from 0-9).

Last tag

@pomtl @Good-Es

And a poll

  • I should have known that (@Petrichor)
  • Very cool! Might actually use this.
  • Ew it needs secret blocks
  • I am not Petrichor.

0 voters

Small bump and now youโ€™ll miss me more.

14 Likes

What do you mean โ€˜miss me moreโ€™? Are you leaving?

Also, cool. This will be great to use.

8 Likes

Cool! Useful for us that is on lower iOS versions without the shortcut. How did you โ€œopen-sourceโ€ it (remove the remix bar)? Did you just unpublish the project, or how does that work? I could actually use that feature in the future.

6 Likes

You unpublish your project

3 Likes

Collisions Using Conditionals

So yeah, there still hasnโ€™t been a proper tutorial on this, has there? This is one of the most useful techniques in Hopscotch right now, and here I am, with a few words to close the gap.

Difficulty: 2/5
Best Use Case: Games, or really any time you use collisions with more than 3 objects on the stage. Seriously, your projects are going to feel so much smoother if you use this.

Demo Project โ€“ Fast Collisions

The Idea

Itโ€™s pretty simple. We will use basic shapes and test for collisions using math to define the hit box. Itโ€™s simpler than it sounds. Take a look.


Thereโ€™s 3 types of collisions I show the shapes for, but Iโ€™ll only go over 2 of them today. Just refer to this image and realize that those are the exact equations we are putting into Hopscotch.

The Equations

Rectangular Collsion:

  • There are two components: difference in X and difference in Y.
  • When using an โ€œandโ€ conditional, it will bound those to a rectangle like the one seen in the graph.
  • The center (objectโ€™s position) is (512,384), the width is 140, and the height is 160. (We use half of those โ€“ 70 and 80 in this graph โ€“ when dealing with the math to make things easier)
  • Equation in Hopscotch (directly copied from graph): if ( | selfX-targetX | < 1/2 width ) and ( | selfY-targetY | < 1/2 height ) then do collision action. (Note that absolute value is shown with a separator: โ€œ|โ€. Example: |-5| = absolute value [-5] )
  • What it states: if the x difference is less than <amount> and y difference is less than <amount> do the collision action.

Circular Collision:

  • There are also the same 2 components
  • In this collision type, we use the Pythagorean Theorem (a2 + b2 = c2). What it does for us is it calculates the direct distance from the center of your object to the target, thus creating a circle.
  • The center of our circle is (256, 650), and the radius is 150.
  • Equation (directly copied): if ( (selfX-targetX)2 + (selfY-targetY)2 < collisionRadius2 ) do collision action.
  • What it states: if the direct distance between the two points is less than <amount> do the collision

Elliptical Collision:

  • Like I said, I am not going to go into depth with this one. Just know that like the other collisions, itโ€™s directly copying the equation.
  • Equation (directly copied): if ( ((selfX-targetX)รท(radius along x axis))2 + ((selfY-targetY)รท(radius along y axis))2 < 1 ) then do collision action (where the expression is always set to less than 1). Talk more on the math topic if you need help with ellipses.

Coding it in Hopscotch


Collision Diagram:


Square Collision Code (this should loook familiar, if not please review the graphs and equations again):

Circle Collision Code (once again, please review graphs and equations if needed):

Honestly, I think these are pretty self-explanatory images. Just copy them over and there you go.

Changes you might make โ€“ depends on your project
  • Object offset: If you want to change the center of your collision box, just add or subtract an amount from the self x/y position.
  • To reduce file size, just calculate the values to reduce the number of math blocks displayed. This also makes your code look cleaner. For example, if you understand what is going on, you can replace 612 with 3721. Or, you could take the square root of the left side and leave the right side as โ€œ61โ€.
  • If you want to make it โ€œbumpsโ€ instead of โ€œis touchingโ€ or want to use other conditionals to limit when the collision action can occur, use a tracker variable and put the collision conditionals in another โ€œandโ€ conditional. This is useful for invisible objects, as youโ€™ll probably want to use โ€œif (collision conditional) & (invis < 100)โ€ rather than just โ€œif (collision conditional)โ€.


The Final Result of the Code:
Image


General Tips & Procedure
  1. Have your objects that you want to test collisions for. Know an approximate width and height (or radius) for your collision.
  2. If your objects are shapes and short text strings, use their width/height traits (orange variables). If they are characters or more complicated text, play guess and check until you think the collision box is fair. Itโ€™s not actually that tedious. Use one action while testing this so that you can isolate only one thing to change at a time.
  3. Test your project to make sure that tthe hit boxes are reliable, then add actions or other conditionals. You donโ€™t want to any actions (besides one that will let you know when the collision hit) before you know that the hit box works.
  • Be sure to experiment with this. Playing projects and actively seeking improvement on this technique will help you get used to it much faster.
  • Make sure your hit box is far. Itโ€™s better to hit a favorable hitbox more often and to hit an unfavorable one less, but donโ€™t make it too lenient either. It should be fair in the playerโ€™s eyes, even if it seems โ€œgood enoughโ€ to you.
  • Check out the demo project โ€“ itโ€™s also open sourced, which means that you can remix it without the watermark :wink:

Iโ€™ve been using this technique for longer than some of you have been using Hopscotch! a while now; here are some projects that use it:

  • Flight of the Turkey
  • Snowman Stacker
  • Zombie Run
  • EHSHQHHC19
  • Minigames 2
  • Some 2 or 3 projects in 2015-17 that I forgot about.

Last tag for real this time?

@Good-Es @Eddie @PeriltheSkywing @pomtl

Also, try these trivia questions on the YCTAYHCH:
https://forum.gethopscotch.com/t/you-can-talk-about-your-hopscotch-coding-here-11-official/53937/4957
And see the latest project I made:
https://forum.gethopscotch.com/t/general-project-updates-topic/51305/7452

17 Likes

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)
  1. Open the object editor.
  2. 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.
  3. Look at the image below.
  4. 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.


  1. 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?

  1. When you publish a project
  2. 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:

  1. You delete the repeat forever block from your code.
  2. You make changes to other game rules or objects in the project (or not).
  3. You exit the project to play Minecraft.
  4. You come back to Hopscotch and tap on that draft.
  5. 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.
  6. 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.
  7. You exit the project again to go eat dinner.
  8. 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:
    1. Delete abilities 3 and 4 (the wait blocks only) so that they are deleted as soon as you leave the object.
    2. 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.
    3. 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 :slight_smile:

13 Likes

FAQ on Hopscotch Code Storage:

(Ask a question and I might add it here)

6 Likes

Nice, this is always a good skill to have at hand, Iโ€™ve known about it for a while and planned to use it, but it canโ€™t be used on clones colliding with clones (that I know of)

4 Likes

While that is true, itโ€™s usually good to use this rule when there is one player-type object and multiple obstacles; you use the rule in the obstacles and set a variable or do stuff there.

4 Likes

That, literally, was the name of my project for the autumn contest, which turned out to be flight of the penguin because of my procrastination.

5 Likes

What would you say is your favorite tip?

4 Likes

Probably multiplying by conditionals and conditional collisions. Those are super helpful to have.

7 Likes

This is really useful! Has tht made regular collisions faster yet?
And has anyone found an easy way to multiply by conditionals yet? Json editing is a bit tough and the glitch never seems to work.

4 Likes

Theyโ€™ve made it less laggy but itโ€™s still laggy

4 Likes

You can find them in the secret blocks project, insert it using secret blocks, use the glitch, or request a project mod from my github site

5 Likes

I know this is really old, but how does it actually work? What do the โ€˜times -9999999โ€™ and โ€˜+999999999โ€™ do?

4 Likes

Lol, why does this even work? Why does hs let us change the parameters after it has started running?

4 Likes

Thatโ€™s a great question @MISSION_IMPOSSIBLE (and @tehgreatdoge).

Basically, it waits til an infinite time, but the wait til timestamp checks the time and compares it every frame. So, when you set a condition that cancels that 999999999999 number, the time it waits until becomes zero and therefore moves on

5 Likes

@RonAstern123 this explains it well

3 Likes