Tip of the Week | 𝓐𝔀𝓮𝓼𝓸𝓶𝓮_𝓔

:clap: Next :clap: Topic – Coding Tip of the Week

Please do not edit tags, #ae_was_here is explained on the cliving topic Posts 647-650

About Tip of the Week

Basically, I came up with this after I used a couple of really neat tricks to code efficiently in E-Pad, and they are definitely worth sharing. Every week or two, I will post a cool little coding trick for y’all to work with. About these ideas:

  1. They can be very simple and sometimes obvious, while other times they may be a little more far-fetched.
  2. Sometimes these tips require tinkering with code in the JSON file, other times they don’t. When that is the case, you can always do it with my Shortcut, through a link to an open-sourced project, or you can send me a link to add the trick into. Others can also help with that as well.
  3. I will teach you how to get the trick, how to use it, and some use cases for the trick, so that way, you can actually apply these to your projects!
  4. I keep these tips fresh and original, so if I cannot come up with any, then I just haven’t had an idea. Read more below.

ePoints :)

Once again, from an AE topic – You can earn ePoints through this. Here’s how:

  1. Suppose it’s been 3-4 weeks and I have not had an idea. You must first wait for me to announce this, but I will post a cue to suggest an idea. The first unique, original, or brilliant idea holds a reward of 20 ePoints. Way to code!
  2. Help others in need! I will be reading through every reply of this topic. Any time you successfully help somebody else understand a concept, you will be rewarded with 5-15 ePoints (this varies on the tip and the explanation). @HopscotchRemixer and leads, this one’s for you, adopt this currency system lol
  3. The One-Up image: This one has never been seen before. Go ahead, I encourage you to 1UP me on my own tips. Make it better, easier to access, more efficient, or give another use case for the weekly (or biweekly) tip. ePoint rewards vary.
  4. Show your skills! First five to tag me with a project get ePoints for how well they used the skill and how impressive the project is. ePoints vary.

This Week's Tip

Multiplying by Conditionals

Now this is a fun one. I am using it in E-Pad and already used it in Finders Keepers. Difficulty: 4/5

You can find the open-sourced fundamentals project here – just publish & unpublish.
You can find the open-source demo project here – take w/o credit if you’d like.

The Full Picture – I suggest looking at this later

The Fundamental Mechanic – How Conditionals Work

Here’s a snippet of code from my open-sourced demo project:

If you play the project, you can see exactly how conditionals work. If your finger is on the left side of the screen, the text will display 1 because the statement is true.

This is the foundation of our whole concept. We can manipulate this to any condition and set it to any number, which is what I have done.


Usage Example 1 – Your Typical Conditional

Here, you can see the last game rule in my full concept.


Photo edited using Workflow for iOS 11

Try to notice that the only conditional that really matters is the one in the parameter. It’s like an if block or when rule. If those would be run, then this will be one. (Try to remember that phrase :wink:)

For our example: If both Value 1 and Value 2 are equal to one, then the “outmost” conditional is true. Seen in the Fundamental Mechanic, the number value outputted by the conditional is one. If either is not equal to one, then the outer conditional outputs a zero.

When it’s true: The Turn Degrees block tells Robo to rotate ( 1 × -360 ), or 360 degrees clockwise. The conditional outputs a 1, and it is multiplied by -360. I think you’re starting to get it by now.

When it’s false: The Turn Degrees block tells Robo to rotate ( 0 × -360 ), or zero. Since the conditional was false, it outputs a zero and Robo does not turn.

Important Note: We multiply the conditional 9 out of 10 times because then you can set the output to be either your number or nothing. Example: Turn “nothing at all” or “a full circle”. This eliminates the use of an if block and helps keep your code in less space. It may be hard to read at first, but you will get used to it. It may not be the best with a simple statement like this, but it is far more useful for managing clones. See the next example.


Usage Example 2 – Grouping

This is another basic conditional. In fact, it’s simpler than the first. But here is a more practical way of using it.


The Y Position is managed by modulo, or remainder. See the folder “Full Picture” for an explanation on that

This method increases the readability of the code. You can see an easy-to-understand explanation in the image itself. Here’s a comparison:


The top code is read: If Clone Index is greater than 3, add 512 to x.
The bottom code is read: Offset the clone index and divide it into groups of 3, then multiply the group ID by 512.

Both pieces of code add the same number for clones 1-6, but the top one is much easier to read through.

The bottom code is more efficient with more groups, but take “Finders Keepers” for example. The “Singleplayer” and “Multiplayer” buttons are one object. I add some number to set the object to the right side if it belongs to multiplayer (clones 4-6).


Usage Example 3 – Adding it Up (Lists)

This may look complicated at first, I know. But, try to look at as “groups” of conditionals.


Excuse the fact that I had to cover up a duplicate if Clone Index = 4. I ended up needing that room

I’ll explain a little more than the given description, but here’s how it goes:
There are 3 groups, right? You can see that all of them add up.

Each group has a conditional multiplied by a number.

Group 1: If (Clone Index = 1 or 3) output 23
Group 2: If (Clone Index = 2 or 5) output 8
Group 3: If (Clone Index = 4 or 6) output 17

In our example, each group will either give its output or zero. Also in our example, only one group can be true.

Here are the possible outcomes

Group 1 True: The equation is [ ( 1 × 23 ) + ( 0 × 8 ) + ( 0 ×17 ) ] = ( 23 + 0 + 0 ) = 23
Group 2 True: The equation is [ ( 0 × 23 ) + ( 1 × 8 ) + ( 0 ×17 ) ] = ( 0 + 8 + 0 ) = 8
Group 3 True: The equation is [ ( 0 × 23 ) + ( 0 × 8 ) + ( 1 ×17 ) ] = ( 0 + 0 + 17 ) = 17

Equivalent Code:

This is how much space it would take to write the same code. It is fine for those who are new or still gaining experience. But, this technique is for those who are seeking a new challenge. Minifying code like this is super helpful in large projects that would otherwise be filled with far too many if blocks. (If blocks because the “if statement” is still there).


Final Result of Our Code:


Robos only turn when both switches are on, and colors applied successfully. Clones 1 and 3 are normal, 2 and 5 are orange, and 3 and 6 are blue.

In the end, it’s your decision. If you’re not ready for it, don’t use it. If you need to tidy your code in a large project, this is one method of doing that.

Rate my service by quality of teaching not by if you would use it:

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
0 voters

Feedback appreciated as always

The First 1UP image goes to @MISSION_IMPOSSIBLE, congratulations!

MISSION_IMPOSSIBLE reminded me of a glitch that allows you to place operators in the wrong spot. Here’s how you can use this to get conditionals in the multiplication operator.

  1. Have the following set up: One “check once if” block with a conditional, one “multiply” operator.
  2. Begin to drag the conditional to the multiply. Start quickly tapping the original parameter, then click the multiply slot. When the multiply slot has a teal outline, drop the conditional onto it. It should show up. This trick can also be used with other draggable items.

See post 20 or tag MISSION_IMPOSSIBLE for additional help.
+10 ePoints and a :smile:!


@⁣pomtl @Good-E’s (20) (lmk if you want to join)

26 Likes

My first reply for a reason.

Quickly Refer to any Tutorials Here:

Week of Date Name of Tutorial Link to Post
6/24 6/28 Multiplying by Conditionals Post #1
7/1 7/5 Bit Storage in Hopscotch Post #32
7/22 7/25 The Frame Rule Post #53
8/5 8/7 Loops Using Abilities Post #69
10/21 10/23 “Wait Until” Block Post #91
12/30 1/3 Conditional Collisions Post #95
12/30 1/3 Code Storage – Abilities Post #96

(I want the Saturday and the Sunday directly after it to be in the same week)

17 Likes

First user reply :crazy_face:

Awesome_E, this is very helpful!

17 Likes

Thank you :upside_down_face:

7 Likes

Well that was interesting.

Also, YAY I know how to say thank you in 10 or more characters now

5 Likes

This is awesome ae!

Wow thanks a lot!

2 Likes

yw! I know this one isn’t the easiest, but it’s not something you see in any other drag-n-drop apps: JSON editing to multiply by a conditional.

Next week’s is gonna be like 3 lines of code

3 Likes

Nice topic

I haven’t read most of it as reading isn’t fun on the forum lol
But I looked at the demo and if that’s all of the first trick then I get it.

2 Likes

You might already know this, but you can put text like <this> and then it doesn’t show up in your post. Therefore, you can do short posts as <this> counts towards the character limit.

2 Likes

Absolutely amazing tutorial! I had no idea about this! :smile:

3 Likes

Thanks!

3 Likes

eating watermelons my goodness
that’s pretty great

2 Likes

IDK how I would use it but seems useful.

2 Likes

Yep, this is very helpful! We can definitely allow more topic like this in the future @Awesome_E!

4 Likes

Can I join Good-E’s? If not is there a way I can?

4 Likes

It’s unfortunate that this can only be done by editing the JSON file. If users could at least drag the conditionals into the math formula this would be really useful…

6 Likes

Yeah, like you can with colors

2 Likes

Sure, you’re in!

3 Likes

Super helpful n well written tutorial AE :))

6 Likes

You can.
image
(Sorry for bad quality.)

2 Likes