How do I Successfully set" AS Json" text to load into a TileMap object?

0 favourites
  • 4 posts
From the Asset Store
OpenAI TTS
$10 USD
Text-to-Speech plugin.Allows your Construct 3 project to convert written text into spoken words
  • Please see this video:

    Subscribe to Construct videos now

    When I use "As Json" to to retrieve a Json string from a TileMap object, that very same text throws a syntax error when I try to "set from Json"

    Any idea what the problem is here?

    This issue is the same on Construct 2 or 3.

  • The first problem is that quotation marks tells where a string start and ends. So if you have quotation marks in your string, there is no way for Construct to say if this now ends or starts a string or if this a normal character. You need an escape character for this that tells construct the handle the next character as an ordinary character. In Construct it is again a quotation mark, that means if you want a quotation mark in you string you have to make two of them "".

    Your Tilemap String should look like that:

    "{""c2"":true,""w"":{""x"":0,""y"":0,""w"":640,""h"":480,""l"":9381438636563842,""zi"":0,""hX"":0,""hY"":0},""data"":{""w"":20,""h"":15,""d"":""21x9,0,3x1,2,2x9,12,8x9,15,3x9,3,2x4,17,5,5x9,0,7x1,2,9,3,16,2x4,5,5x9,3,6x4,16,5,9,3,3x4,5,4x9,15,3,4x4,10,7,11,5,9,6,3x7,8,5x9,3,2x4,17,4,5,9,3,5,5x9,2x-1,9,15,2x9,3,4x4,13,1,14,5,3x9,0,1,7x-1,7x7,8,9,15,9,3,2x-1,2x4,-1,5,9,5x-1,2x9,15,4x9,3,-1,4x4,3x-1,1,2x-1,3x1,2,4x9,3,-1,3x4,16,5,9,3x-1,4,16,2x4,5,4x9,3,9x-1,5x4,5,4x9,3,4,17,3x4,5,9,3,2x-1,2x4,17,4,5,4x9,6,5x7,8,9,3,4,17,4x4,5,8x9,15,3x9,6,6x7,8,9""}}"

    You can use notepad for example to replace " to "".

    Another way is you put the string you got from toJSON to a string variable and use this variable in set from JSON string, then without quotation marks on the beginning and the end for a string.

    Your second problem is that you confuse download with load. Download is like from any website that you save something from the web to your PC. What you want is Load.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks very much Asmodean, both of your suggestions work perfectly. Would you know how I would go about loading this same json string from a json file in the same folder as the app without using NW,js?

    I'm trying to find an action to load a string from a file and can't find it... I can load an entire dictionary or array, but I need to load this same string from a file, not the string in an array or a dictionary.

    Thanks.

  • I'm trying to find an action to load a string from a file and can't find it... I can load an entire dictionary or array, but I need to load this same string from a file, not the string in an array or a dictionary.

    I depends where the file is. If your file is imported in the project you need ajax to load it. Is the file on a server you need ajax an a php script. If you want the user to load the file from their Computer you need the file chooser plugin.

    But be aware that the Tilemap-Plugin has Load in the JSON-Group and "Set from JSON" in Misc, because there are two different JSON Expressions: Tilemap.TilesJSON and Tilemap.AsJSON.

    AsJSON expression returns the entire object state (including position, size, behaviors etc), whereas TilesJSON returns only the tile data.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)