Struggling with my app and I have questions...

0 favourites
  • 8 posts
From the Asset Store
Royal Panda Casino
$40 USD
60% off
Create your own casino app and import it to Google Play and the App Store.
  • I thought a Flashcard app would be a fairly simple way to learn Construct 2, but I'm sort of struggling at the moment. I spend about half my time "coding" and the other half reading forum posts and looking at tutorials, but despite my research some things are just not clicking yet...

    1. If I create a function to manipulate an array, what is the execution flow? For example, let's say I have a 10 line program. Line 5 is a function call. The function is manipulating an array using "for each". Does the "for each" loop finish WITHIN the function before returning to the main program? Or does it process the loop once, increment the LoopIndex, return to the main program until it hits the Function again, at which point it process the loop, increments the LoopIndex again, etc.

    2. I try to put all my code in Groups. When one Group is finished I deactivate it and activate the next group. But what happens when I sort an array? Can I perform the sort and then immediately de-activate the group? How do I know when an array has finished sorting? Are these events asynchronous like Local Storage?

    3. Is there a way to tell how long other array and dictionary manipulation takes? I wound up writing some code like this to ensure stuff has time to finish:

    [GROUP]

    • initialize counter = 0
    • if counter = 0 reverse array
    • if counter = 15 sort array
    • if counter = 30 update array
    • if counter = 40 deactivate group
    • counter = counter + 1

    Is that necessary? Is there a better way to do it?

    Here's what I'm trying to do with my Flashcard App. If anyone has suggestions please let me know!

    DICTIONARY

    id: score

    ARRAY

    score, french phrase, english phrase, id

    I use AJAX to load data.json into my array. Then I use Local Storage to create my Dictionary object. After that I reverse the y axis of my array so the "id" is in the first column. Then I can sort the array by id. This makes it easy to update the array using the values in the dictionary object. (Everyone using the app needs to have their own "score" for each word.)

    After every card I basically do the opposite of the above to save back to Local Storage.

    It's mostly working but I'm getting weird values in weird places and none of it makes any sense. Perhaps I'm trying to sort an array before it has finished reversing, for example. Not sure.

  • A for loop is synchronous. Just because Local Storage is async, don't think anything else is. Your counter mechanism shouldn't be necessary. Post a CAPX for specific help.

  • Not sure if I'm doing this right, but here's a link to my .capx file:

    http://jmcdesign.orgfree.com/Flashcards.capx

    This is my *first* Construct 2 program... so go easy on me.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I cleaned up a few things but the main problem I saw was that you were starting two async operations at once, but expecting them to occur in order. Check localstorage after you've got the AJAX data, since the Dictionary group isn't turned on until then. You also don't need the extra Get step as the data is already there on an "exists".

    I've tried to remember to disable anything I changed so you can see the before and after. It wasn't clear what else might not be working. You'll need to explain specific examples.

  • Wow, thank you blackhornet! I really appreciate your help!

    I haven't had a chance to look at your updates, but your response made me remember why I was prompted to write my post.

    It was my assumption that the Sort and Reverse commands for arrays would finish execution before falling through to the next line of my program. But I was running into problems when I Reversed the Y axis, and then immediately Sorted by X. My theory was that the Reverse hadn't finished before I started the Sort. When I put the delays in between (Wait didn't work), everything seemed okay.

    I think I read that some Events need a "tick" to complete. Is that the case here? Would "Wait 0" work?

  • Thanks to blackhornet's help I have dramatically simplifed my app (and it's much faster now, too)! But I've got one more bug to fix and I'm completely stumped.

    I'm trying to update my dictionary using a value in my array and it's just not working.

    Here's my code. (I've verified that location 0,3 = "0"):

    Dictionary: Set key Array.at(0,3) to 300[/code:4k9r7w3i] 
    [i]NOTE: I've tried using: str(Array.At(0,3)) but that doesn't help.  [/i]
    
    And yet THIS works:
    [code:4k9r7w3i]Dictionary: Set key str(0) to 300[/code:4k9r7w3i]
    What am I doing wrong?
  • Maybe try "Add key". "Set key" won't do anything if the key hasn't been added first. Use str(Array.At(0,3)) also.

  • UPDATE (and a few final questions): I finally tracked down my array/dictionary issue above. Due to an export error from Excel there was a leading space in front of all my IDs. SUE (stupid user error).

    Okay, a few more questions: For my Flashcard app to be truly useful to the other people in my French class *THEY* need to be able to enter their own words and phrases. Sounds like that might be pretty tricky, since I'm already using Local Storage to track "scores". I'm also concerned about someone losing all their entries if they ever have to clear their web cache. (That would happen, right?)

    Is there any [easy] way for me to do this? There are only a few people in the class so I'd be willing to upload their vocabulary .json files to my server. In my flashcard program is there a way for me to bring up a directory of filenames? (Then they could simply choose their own vocabulary word and use that.)

    Special thanks to blackhornet for his help, so far. It's much appreciated!

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