How do I sync Json with Instance/Global Variables?

Not favoritedFavorited Favorited 0 favourites
  • 4 posts
From the Asset Store
Sync animations, animation frames, mirror state, sounds and anything else using these methods.
  • Just keep in mind for all of this that I'm very inexperienced when it comes to using JSON, this is my first time properly trying it actually...

    I have a World Map system for my game that reads off a JSON file to check what state a "node" (level marker) should be in. It then applies that state to the instance variable. This worked fine for that, but when I tried to do something similar with level clears it kind of didn't work. I wanted to have it so that depending on if the player got a collectable or not, they'd be sent back to the world map or to a short intermission layout that has an extra scene or something along those lines. The way it'd do that is by setting a "HasCollectedMemory" variable in the JSON to true. The once the level is over, it checks to see if HasCollectedMemory is equal to 0 or 1. Despite this, nothing happens. And really I'm not sure why the same set up worked for one thing but not the other. If I have the "set path to Nodes." in the function it will immediately stop the loop after just checking the first index. Obviously not what I want. If I remove it, it does loop properly but still doesn't work.

    Anyway I'm probably doing a bad job of explaining this so it's probably better if you take a look at the code and project file yourself:

    example of the function that works:

    Function that doesn't work:

    (Note that !LevelEnder means that its collectable here, if LevelEnder is true then its not a collectable.)

    (Left out any irrelevant code, but this is for a version of the object that has LevelEnder set to true. The condition is the same as the other one just inverted if you were wondering.)

    The JSON:

    (Note: The SetMemory/CheckMemoryStatus functions are in a separate event sheet from the AJAX request. However the AJAX request is made on an event sheet included within the event sheet those functions are in. So, it shouldn't matter but I thought id mention it.)

    And finally here is the C3P file for the basic systems... Hopefully this should be enough. It's a bit sloppy and thrown together but it should(?) get the job done. Let me know if there are any issues:

    dropbox.com/scl/fi/hzqewi40vm4q8h6flhr6l/NODEDATAEXAMPLE.c3p

  • Hi there. I altered the functions of "SetMemoryColleted" and "CheckMemoryStatus" like this: https://www.dropbox.com/scl/fi/tmc0ytm255978d9sbtlip/NODEDATAEXAMPLE-edited.c3p?rlkey=x54h06jgkjlhamk988ml95zec&st=33bke333&dl=0.

    Basically, JSON objects "for each entry" loops can't be stopped. So usually, to check JSON arrays, I use System's "repeat" condition instead.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hi there. I altered the functions of "SetMemoryColleted" and "CheckMemoryStatus" like this: https://www.dropbox.com/scl/fi/tmc0ytm255978d9sbtlip/NODEDATAEXAMPLE-edited.c3p?rlkey=x54h06jgkjlhamk988ml95zec&st=33bke333&dl=0.

    Basically, JSON objects "for each entry" loops can't be stopped. So usually, to check JSON arrays, I use System's "repeat" condition instead.

    Oh thank you! Your comments were very helpful, it makes complete sense now why it wasn't working before. This is probably pretty basic information (the loops cant be stopped thing) but you know, this is just my first time using json so I guess something like that was bound to happen. lol

  • Haha yep, I also learnt about how to use JSONs just some months ago. Best of luck to you and your projects.

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