Hopscotch Notation (& Compiler)

Inspired by Hopscript: Hopscotch Text Language (Concept)

:grey_exclamation: A more detailed OP will be written in the future :grey_exclamation:


Examples

:exclamation: those are frequently updated, unlike any code in the conversation in this topic
feel free to ask any question if you do not understand those two code snippets

the following code snippet is based on this project:

When game_starts:
    background.color = rgb(0, 0, 0)
    save_input = noformat_number, "type a big number"
    noformat_number = round(noformat_number)
    if (noformat_number MATCHES /e\+/):
        set_text =
            "the number you provided is too big; hopscotch is reading it as scientific notation now (7e+12 for example).",
            hsb(28,100,100)
    else:
        # "section one: adding comma to long numbers"
        custom_ability (
            "Format Number",
            recursion = floor((length(round(noformat_number)) - 1) / 3),
            noformat_number = round(noformat_number)
            ):
            if (recursion == 0):
                self.Return = noformat_number
            else:
                custom_ability this:
                    recursion - 1,
                    noformat_number
                self.Return = join(
                    join(
                        Return[0, length(Return) - (recursion * 3 + (recursion - 1))],
                        ","[noformat_number[0] == "-"]
                    ), 
                    Return[length(Return) - (recursion * 3 + (recursion - 1)), length(Return)]
                )
    formatted_long_number = self.Return
    # "section two: cuttin long numbers down followed by an abbreviation"
    power = floor((length(noformat_number) - (1 + noformat_number[0] == "-")) / 3)
    number_w_abbr = join(
        round((noformat_number * 100) / (10 ^ (3 * power))) / 100,
        "KMBtqQsSondUDT"[power - 1]
    )
    set_text =
        join(join(formatted_long_number, "\n or "), number_w_abbr),
        rgb(255, 255, 255)

this custom rule can be found in this project:

custom_rule:
    name: "Movement Spring"
    args: "Stiffness", "Mass", "Damping"
    values: 0.4, 7.5, 1.5
    content:
        SpeedX = 0
        SpeedY = 0

        _cstm.FPS_Calculator

        When (o.Spring_Able == 1):
            # "Calculate the distance between the target point and the object itself"
            DistanceX = self.x_position - self.TargetX
            DistanceY = self.y_position - self.TargetY
            # "Calculate the acceleration to apply on the current speed"
            AccelerationX = (-1 * Stiffness * DistanceX + -1 * Damping * SpeedX) / Mass
            AccelerationY = (-1 * Stiffness * DistanceY + -1 * Damping * SpeedY) / Mass
            # "Add up the current speed to the acceleration"
            SpeedX += AccelerationX * game.Project_Speed
            SpeedY += AccelerationY * game.Project_Speed
            # "Apply the new position of the object"
            set_position = ...
                self.x_position + SpeedX * game.Project_Speed,
                self.y_position + SpeedY * game.Project_Speed

_cstm:
    custom_rule:
        name: "FPS_Calculator"
        content:
            LastT = Time
            When game_is_playing:
                # "Code Provided by @Spy_Guy_96"
                game.FPS = min(1000 / (Time - LastT), 60)
                game.Project_Speed = min(max(60 / game.FPS, 1), 3)
                LastT = Time
14 Likes

please note, i am not making a project player - i am making a textual language visualizator, and a globally spoken hopscotch textual syntax

in other words, im planning to code something that will visualise a code you have provided. example of syntax is shown above, in the op


  • tag me for deciding (vote) for the syntax of a word
0 voters
11 Likes

8-14-2023: The position.x and position.y syntax has been changed to x_position and y_position (snake_case)
8-15-2023: For the sake for being easier to code, spread operator (...) is required when you write a multiline input
8-15-2023: PREVIEW 1 OF HTX SYNTAX’S DOCS
8-16-2023: The community decided it; declare variables with local., object., game., and user. followed by the variable name
8-16-2023: The community decided it; the syntax will be turn_degrees, not turn
8-16-2023: The community decided it; the parenthetical syntax will be description (arg1, arg2)
8-16-2023: s as the shortcut of self will not be supported for readability reasons
8-18-2023: The community decided it; custom_rule ("name", arg = 1) is the proper syntax

When game.starts:
    background.color = rgb(0, 0, 0)
    l.save_input(noformat_number) = "type a big number"
    l.set(noformat_number) = round(noformat_number)
    if (noformat_number MATCHES "e\+"):
        text =
            "the number you provided is too big; hopscotch is reading it as scientific notation now (7e+12 for example).",
            hsb(28,100,100)
    else:
        # "section one: adding comma to long numbers"
        custom_block:
            name: "Format Number"
            arguments: "recursion", "noformat_number"
            values:
                floor((length(round(noformat_number)) - 1) / 3),
                round(noformat_number)
            content:
                if (recursion == 0):
                    o.set(Return) = noformat_number
                else:
                    custom.this:
                        recursion - 1,
                        noformat_number
                    o.set(Return) = join(
                        join(
                            Return[0, length(Return) - (recursion * 3 + (recursion - 1))],
                            ","[noformat_number[0] == "-"]
                        ), 
                        Return[length(Return) - (recursion * 3 + (recursion - 1)), length(Return)]
                    )
    l.set(formatted_long_number) = Return
    # "section two: cuttin long numbers down followed by an abbreviation"
    l.set(power) = floor((length(noformat_number) - (1 + noformat_number[0] == "-")) / 3)
    l.set(number_w_abbr) = join(
        round((noformat_number * 100) / (10 ^ (3 * power))) / 100,
        "KMBtqQsSondUDT"[power - 1]
    )
    text =
        join(join(formatted_long_number, "\n or "), number_w_abbr),
        rgb(255, 255, 255)

ive been copying several codes into textual notation ^^ and i think i got to a point im doing it consistently. i think that the language is easy to understand and easy enough to code it into a hopscotch notation visualisator

any suggestion to improve the syntax before i start attacking in a json file?

the original project is here

@polygons

edit: also, l.set(), o.set(), g.set(), u.set() are respectively set a local var, object var, game var, and user var

11 Likes
Superbear:
    # "Catch The Bear, Make Him Grow!"
    When game_starts:
        move_forward = 100
        if (s.position.x >= 1000):
            position.x = 100

    When s.isTouched:
        growBy = s.size * 1.1

since my project isnt going to be a whole textual hopscript, but rather a simple code visualisator, the initial image, x and y position attributes are omitted

please note: s is the fast contraction of self

12 Likes

I feel like local variables should be the default, and self and global variables could use dots. So maybe something like

local_variable_name = "value"
self.object_variable_name = local_variable_name
Monkey.object_variable_name = self.object_variable_name
▶️ global_variable_name = local_variable_name
📱user_variable_name = ▶️ global_variable_name

I used a space instead of a dot for the global one so that there isn’t confusion with an object variable for an object called global, though that shouldn’t really be a problem with your uses.

10 Likes

i really dont like the use of emojis inside something 100% textual tho - but i like the idea of local variables being default

e: also, i just noticed that if two variables of the same name but not the same type, there is absolutely no way to distinguish it if its called (not set)
gotta change that

10 Likes

I guess that makes sense since they’re harder to type. I only used them to make it clear what they meant, I couldn’t think of anything better.

10 Likes

You could do something like this, although I’m not really a fan of the inconsistency + naming + arbitrary methods:

local_var = "value"
self.var = local_var
GetObject("Monkey").var = self.var
GetGlobalVars().var = local_var
GetUserVars().var = GetGlobalVars().var

or…

Objects.Monkey.var = self.var
Globals.var = local_var
User.var = Globals.var
7 Likes

i figured out this way:

l.localvarone = "way one to declare a local var"
localvartwo = "way two to declare a local var"
o.objectvar = "object variable"
g.gamevar = "game variable"
u.uservar = "user variable"

l.position = "identifier 'l' is necessary here, see below"

basically, if you omit the l, o, g, u identifier, it means the variable is a local variable by default (suggested by petrichor). but if you have a local variable with a name that means something else (eg position is something that already exists and the compiler will not understand its a variable), you need to prefix it with the l identifier

about object variables

o.objectvar = "stands for self"
s.objectvar = "probably will also accept this way"
original_obj.objectvar = "attaches the original object"
"monkey".objectvar = "attaches the monkey obj"

im just not really a fan of very long and repetitive words. but i might as well code the non-contraction way too haha

also, do you think whether o.objectvar or s.objectvar is more intuitive? or even o.s.objectvar but that might be too long

8 Likes

actually, no, what if the name of the variable is position? s.position will not be compiled as a variable so i think im gonna stick with o.position

7 Likes

Both are almost like learning a new syntax so I’m not really sure

6 Likes

actually no - o stands for object and s stands for self

but im actually thinking i should go with o to distinguish between read-only properties (such as position and zindex) and read + write variables - reasoning is above your post :)

7 Likes

Oh this is cool! So basically you’re trying to make a textual representation of hopscotch code that everyone understands?

7 Likes

yeah, and as an extra im coding rn a little program (with js) that can read that syntax and generate the hopscotch blocks/code snippet :)

10 Likes

Oh cool! Let me know if you need any help! :smile:

6 Likes

I still think it’s creating a somewhat unintuitive way of saying something, which means you will have to document it. Like if I stumbled across something randomly, how am I “supposed to know” that o.something is for objects?

I’m not saying the design is bad or anything, it’s still just learning a new syntax

8 Likes

yes, but:

so this is why i wanted to keep it like so - you can decide to use the contraction or not because im planning to code it so that both can be understood

((unless thats not what you mean?))

8 Likes

Not at all what I meant. Either way the syntax is different enough from HS that you have to know it before you can use it. I get that is probably unavoidable though

6 Likes