Array Value count problem

0 favourites
  • 15 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • Hi,

    I've a problem counting through the array.

    My array is x=99, Y=1, z=1

    If an event triggers ingame it writes a number into the array.

    when the game ends I need to loop through the array an count the amount of X-fields which have a number. All not filled array fields are still 0 (empty?)

    So I've made:

    System -> For "" from 0 to array.width -1

    --> (subevent): System Array.At(Loopindex)>0

    --> (event): Add 1 to globalVar

    Result: It counts infintly :(

    I've also tried things like System Array.At(Loopindex)NOT= 0 or System Array.At(Loopindex)<100

    What is my thought error?

  • Depends on the event that triggers it. Sounds like the loop is running constantly when you only need to run it once.

  • thank you for responding!

    the trigger event is simple. If a globalVar "score" reaches f.e. 5, the game ends and the array loop should be triggered. that works, but it does not stop looping. How can i tell him to only loop once?

    I've tried "trigger once" but it doesn't work.

  • Maybe your trigger once is in the wrong place, it should be on the score = 5 condition. Let's see a screenshot of the event.

  • Hmm, If I place it like here at the "score=3" event, it doesn't count anything.

    If I disabled the "trigger once" it counts infinite :(

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • This is an example that will populate each cell of an array with a random number between 0 and 5

    and count the number of entry's that contains a number greater than 0.

  • I try to give you the whole event:

    First if the player does combine two objects with the same checksum, this event writes a number to the array. Here it's f.e. "2"

    Then I can control this in debug layout. I can see, that the event triggers the animation (on the yellow background) and has inserted the "2" into the array (you can see it at the ground in the debug layout) --> Data 2 = 2

    So the player plays until he reaches the needed score. To ease it, I reduced it to "3" (score=3)

    then the game should pause and the "win" Layer appears while all of the math is triggering in the background.

    But there's an error I can't identify.

    The counter are working properly. They count the time and usage of objects and write it into the "use..." globalVars. Then they multiply it and write it into a "result...." globalVar". So I can get the final result displayed with all the math done.

    But the damn array doesn't count weather the field is empty (0) or filled with a number from 1 to 99. So it doesn't work at all or counts infinite :(

  • This is an example that will populate each cell of an array with a random number between 0 and 5

    and count the number of entry's that contains a number greater than 0.

    Thank your for your response!

    I've tried this but it gaves me the same result. With "trigger once" it doesn't count. Without it counts infinite :(

  • I uploaded the c3p. maybe it's better to see it live.

    The "score" trigger event is in the group "Winning conditions".

    The event to fill the array with a number is under functions-->achievements--> on function achieve.

    The event for the Merge trigger (this is what triggers the achieve function) is under buttons-->Merge buttons.

    easyupload.io/oh1876

  • The trigger once is disabled...it works fine. I added some 1s to the array myself and then set score to 3 and it's fine.

  • Hmm, my trigger once is enabled now.

    But if I played until score=3 and have some number in the array, it still displays "0 achievements gefunden" in the final result

  • That's not the error you reported, you said it was counting up infinitely. Looks like you don't call the achievements function ever in the events. You have to call the function to set the values in the array, from what I can see they will always be 0. It displays 0 achievements because you actually have 0 achievements, check what the array is doing in debug menu.

  • Thanks so far.

    I'm sorry, my english isn't the best, so maybe I can't describe wats the problem...

    I've checked again and in debug layout i can see, that the achievement function does write into the array. Look at the "2".

  • God damn, i found the error :)

    Take a look at the picture where the error comes and "achievement gets no value.

    Here's the updated one.

    I just needed to do the array loop first, because otherwise the globalVar "useArchive" gets it's update AFTER the "resultfinal" Update. this causes why every math is calculation with 0.

    Thank you all for helping!

  • I have no idea what's going on but I'm glad it's resolved

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