Need help getting the JSON data load into Arrays properly

0 favourites
  • 9 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • The file is a prototype example for my game's ketchup saving mechanism.

    Here's how it works before talking about the problems:

    I have 6 arrays (they are ketchup dots' X, Y positions & sizes) .

    arX, arY, arS are for the ketchup 'Draw Screen' (no issues) &

    recX, recY, recS are for the 'Record Screen'. (patterns saved permanently)

    Click any to draw ketchup dots, the 'Save Record' button will appear at top-right.

    Click the 'Save Record' button saves the ketchup pattern and goes to 'Record Screen' to view all the saved patterns.

    At 'Record Screen' click left & right arrows to navigate the saved patterns. ('1' being the first)

    The small pink button at the bottom-left clears all the data(localstorage).

    Click 'Return' on the top-left to go back to 'Draw Screen' & it will start a new blank.

    I added allXSave, allYSave & allSSave (json files) for storing array's data.

    The Problems:

    There's no ketchup patterns on the 'Record' screen when they are created from previous plays or after reset , resulting blanks on the spot. The ketchup patterns that I've made at this play will show up on 'Record' screen, but not after reset.

    The JSON files do have the data stored, though.

    I'm not familiar using JSON. I followed the codings from the tutorial but it won't work. Also the 'download as JSON' lines (event 15) pops up unwanted new windows with 'Download link' when testing on browser.

    Can anyone help me for the codings cos' I am not too bright at this

    Thanks.

    (UPDATED: This is the fixed version, without using AJAX & Json files)

    Capx Here: Ketchup Record- Fixed (2nd Update with much better control over dot counts)

  • At this moment there are lots of things that i dont understand.

    Most basecaly: why not use two 2D arrays ? But that is besides the question. It works with 4 arrays too.

    More to the point: You seem to try to use the AJAX plugin to retreive data from the LocalStorage plugin. I am afraid you have to make a choise. Or AJAX or LocalStorage.

    If you choose for AJAX, then i can not help you. Because then you have to deal with security related issue's that go with browsers. Something i know zip about. Its is quite normal that you do not want a browser to download and store whatever file without the user knowing.

    If you choose for LocalStorage, then i will look in to it. Meaning: clear your system, wich i dont understand. And set up a logical system.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • At this moment there are lots of things that i dont understand.

    Most basecaly: why not use two 2D arrays ? But that is besides the question. It works with 4 arrays too.

    More to the point: You seem to try to use the AJAX plugin to retreive data from the LocalStorage plugin. I am afraid you have to make a choise. Or AJAX or LocalStorage.

    If you choose for AJAX, then i can not help you. Because then you have to deal with security related issue's that go with browsers. Something i know zip about. Its is quite normal that you do not want a browser to download and store whatever file without the user knowing.

    If you choose for LocalStorage, then i will look in to it. Meaning: clear your system, wich i dont understand. And set up a logical system.

    Sorry for it took a while to reply, 99Instances2Go !

    Yeah it's possible to make 2D arrays instead of 1D. But ya I'm pretty much prefer easy coding to efficiency, unless it's totally necessary. the recX, recY, recS are actually 2D arrays, for the record. (Width X is the total amount of the dots, Height Y=2: The 'amount of saved records' are added into index 1.)

    Anyway, I did try LocalStorage before, but I don't see a code that can save all the dots into 1 array slot. The dots could be as much as 1 to 1000 or more. (50~250 on average)

    Take a look at this code example that I can possibly come up with:

    This is only limited up to 20 data entries, so It will be very-unwise if i made 1000 of them, right?

    At the least it could work using this method, but it'll compromise & limits the ketchup feature greatly.

    Also, I can't add a condition like "Array:For each X element", because it simply won't work for LocalStorage.

    I don't know much about AJAX & the browser and security stuff. It's kind of a bummer about the intrusive download pop-ups.

    Should I use 'dictionary' instead? I don't know if it's suitable for 2D arrays like mine (all numbers).

    Sorry for those who wants to help but confused, I couldn't explain any clearer with my poor choice of words.

    Thanks anyway 99Instances2Go !

  • You use Array.AsJSON to save your data as one string!

  • You use Array.AsJSON to save your data as one string!

    Thank you, blackhornet . I tried the code just now. Now I see some changes on the debug layout.

    Looks like it doesn't involve Json files but saved all array data in LocalStorage like this, right?

    Am I doing alright? Am I in the right direction?

    Then I don't really need to use any AJAX codes, do I?

    However, I still can't get them load into arrays, clearly I don't know the proper codes.

    Below is the current codes for loading saved data. I had the AJAX codes disabled for now.

    I can't wrap my head around this part Could you (or anybody) help me out on this screenshot?

    Thank you & sorry for the inconvenience.

  • On "AllXSave" exist -> recX.Load LocalStorage.ItemValue.

    Do the same for the others. This should all fit into a 3D array, I think. If AmountSaved is just the number of dots, the array length itself gives you that number. If you start with an empty array and push data on it, it will only ever be the correct length.

  • Yes! This is the correct code!

    To be exact, It's:

    On "AllXSave" exist -> recX: Load from JSON string LocalStorage.ItemValue

    'AmountSaved' is actually: amount of saved records btw.

    FINALLY, Everything works perfectly It's almost surreal! This issue has bugged me for many weeks.

    I'm surprised that it doesn't need JSON files & AJAX at all. (at least in my case.)

    Thank you so much, blackhornet , you had helped me a great deal!

    Have a wonderful day!

    (For everyone who have similar coding problem, this might help a bit)

    Capx Here: Ketchup Record- Fixed (2nd Update with much better control over dot counts)

  • I see things got solved allready when i was looking in to your cap. I post my cap anywayz.

    https://

    drive.google.com/open?id=0B1SSuCVV8v74ZTdZZmQ1QTNTS00

    Still, when i see the arrays, there a lot of dots created. In fact, to much. Many on the same place. That will have an impact on the save/load times.

    Mayby you should do two things in your code.

    1/ When the touch speed is very low, dont make new dots, just grow the last one made in size.

    2/ Dont make a new dot when the touch is overlapping an old dot.

  • Good observation, 99Instances2Go . I didn't consider that as an issue before.

    I usually make about 50~300 dots per record, and it didn't impact much of the performance.

    Still, there will be players who draw it slowly thus creating a lot more dots. I suppose I will optimize it to lower dot counts.

    Thanks again.

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