Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Platforms and ladders
#3
(01-04-2024, 10:49 PM)johnno56 Wrote: Gotta love the platformers.... Nicely done!

Question: Why use 'json' format for the level files? Smaller size? Easier to 'translate/interpret'? Not judging... just curious. I am so used to using the plain text 'grid' file... lol

The json library can convert any naalaa table to a json string and the other way around, so it's quite simple to use for saving an entire level structure to file, and you get files that are nice to look at in a text editor Smile

Code:
include "json.n7"

' Create a table.
foo = []
foo.position = []
foo.position.x = 10
foo.position.y = 35
foo.speed = []
foo.speed.x = 2.3
foo.speed.y = 1.27
foo.name = "dude"

' Convert table to a json string and print it.
fooAsJson = JSON_ToString(foo)
pln fooAsJson

' Create a new table from the json string - a copy of foo.
bar = JSON_FromString(fooAsJson)
pln bar.position.x + ", " + bar.position.y

system "pause"

Output:
Code:
{"position":{"x":10,"y":35},"name":"dude","speed":{"x":2.3,"y":1.27}}
10, 35
Press any key to continue . . .
Reply


Messages In This Thread
Platforms and ladders - by Marcus - 01-04-2024, 05:20 PM
RE: Platforms and ladders - by johnno56 - 01-04-2024, 10:49 PM
RE: Platforms and ladders - by Marcus - 01-05-2024, 05:54 PM
RE: Platforms and ladders - by 1micha.elok - 01-13-2024, 09:09 AM
RE: Platforms and ladders - by johnno56 - 01-05-2024, 07:32 PM
RE: Platforms and ladders - by 1micha.elok - 01-08-2024, 01:51 PM
RE: Platforms and ladders - by johnno56 - 01-09-2024, 03:59 AM
RE: Platforms and ladders - by johnno56 - 01-13-2024, 07:29 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)