Project JSON modification — Topic


#245

Hopscotch JSON structure

A hopscotch project json file contains all of its code, objects and attributes, written in JSON(see this) that a program can take and convert to dictionaries (see this).

This is how the JSON of Hopscotch projects are built up:

Abilities

Stored in an array in the main dictionary
Abilities have UUID:s.

Abilites are groups of code blocks, such as in a rule or in a Check Once If block. They have an array containing all the code blocks in them.

Blocks

Stored in an array in an Ability
Blocks have no UUID.

Information about a single block. Has “block_class” and “description” attributes. Has an array of parameters (if the block has a bubble).

Rules

Stored in an array in the main dictionary
Rules have UUID:s.

Rules are the “When ()” blocks. Has “name” (seems to be unused), “id”, “objectID” (referencing which Object the rule is in) and “abilityID” (references which Ability is used in the rule). “parameters” array contain one object describing which of the When types it is.

Parameter

Stored in an array in either Rules or Blocks in Abilities
Parameters don’t have UUID:s

Parameters have “default_value”, “value” and “key” attributes. “datum” array is used if the parameter is not a plain number. “datum” objects can be math blocks, conditions in a When block or reference traits.

More will be coming, I just don’t have time rn. @Petrichor, you were interested in this. @William04GamerA, @Awesome_E, @XxFoxxedxX


I wrote a small program that takes a JSON file and pretty-prints it, if anyone needs that:

Pretty-print JSON files

No libraries needed

#Python 3
import json

#take the filename/directory as a user input
print ("Warning! This will overwrite your current file.")
file_name = input("File Directory:")

#get the text in the file
with open(file_name, mode = 'r' , encoding= "utf-8") as file_info:
    file_text = file_info.read()
    loaded_json = json.loads(file_text)

#save pretty-printed text to the same file
with open(file_name, mode = 'w' , encoding='utf-8') as f:
    f.write(json.dumps(loaded_json, sort_keys=True,indent=4, separators=(',', ': '))).

print ("Saved pretty-printed json to",file_name).

#246

Thank you for that information, it is really helpful! I often use www.jsonviewer.stack.hu to get a more graphical overview of JSONs. www.jsonlint.com is a really good JSON validator too.


#247

I can paste it in Game Maker and it formats it with no clicks.
I also use jsonlint.com


#248

I feel like this is OMTL worthy, but @pomtl:

There are two webplayer versions: The old and the new
  • The old one does NOT have custom rules, and variables apply to one object only (individual). This version has Last Touch variables, but can also support MULTI-TOUCH input (more than one object can be pressed correctly at once). It does NOT have Clone Index as a variable/parameter.
  • The new webplayer has all the fancy stuff like object-assigned variables (and that one variable created applies to all objects), custom rules, and clone index. BUT: Multi-touch is not supported (two or more objects can NOT be pressed properly at the same time).

What did I do? I put the biggest feature of the new webplayer into the old one: Clone Index. All of the variables inside the “Secret Parameters” ability apply to “Self”. That way, one project can have both Clone Index and multi-touch. I am going to make a new HS Duel between characters using this trick, as I want to be able to identify Clone Index (obvious reasons) and have multi-touch support (so both players can actually press the arrow keys to move properly – obvious reasons).


#249

I don’t know why I booked marked this topic I don’t know anything about json


#250

That’s cool. How did you get the ability with a parameter? Was it an existing block, or is it just faked?


#251

That is awesome! Maybe THT could use that in some way?


#252

It’s probably just an ability with a parameter added.


#253

Faked; just so I didn’t have to name the ability otherwise


#254

is it possible to access Hs’s code @Awesome_E @Petrichor @William04GamerA @CreationsOfaNoob and turn it into javascript

then paste it into a website


#255

The webplayer code is JavaScript already.

The rest of it is not, and you can probably access it, I just don’t know how’s.


#256

Do you need iTunes?

Also what is this:


#257

Usually.

I think you might be able to see webplayer code in pages using the files app.


#258

I can send you a link to the webplayer code that you can access online, if you’d like to. Then, you can just use an online JavaScript code viewer if you want to edit and view the file. Just tell me and I will fix it!


#259

Not if you have Google Drive to swap files between – works just as well


#260

Do you need JavaScript?


#261

What do you mean? If you want to execute the file and/or read it, you can just use a website. I will show you.
You can find the webplayer here.
Edit: I probably misspelled the addres s… I will check it on my computer tomorrow.

But keep in mind that this is The Hopscotch Team’s code. I know the link to it, but I take no responsibility for what people potentially use that information for. You can take a look at it and maybe try changing some things, but you should not use it to make a “Hopscotch clone” or something similar. I just wanted to point that out.


#262

I couldn’t open it.



#264

Could it be possible to add a hyperlink by editing the .json files…?.??

@William04GamerA
@Petrichor


#265

Probably not.