Need help in adding values in Array

0 favourites
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • I have 2 variables Correct and Incorrect which contain data how many times correct clicked and incorrect clicked as well.

    Now i want to record last 5 play's result and next play have to add and remove previous accordingly.

    I hope it make sense.

  • 'push' the latest click to X on a blank array, when the array width is 5, start to 'pop' one result from the array that removes the oldest as you 'push' the latest one to it.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I don't even know how to put both values in array.

  • I would do it like :

    Correct clicked - push 'correct' to back of X

    Incorrect clicked - push 'incorrect' to back of X

    So your array may look like this

    Correct

    Correct

    Incorrect

    Correct

    Incorrect

    Then when the width is 5, i.e. 5 results in the array, you can begin to pop the array at the same time which removes the top result as you add a new result. This is then a list of last 5 results.

    If this doesn't help then what you mentioned 'Now i want to record last 5 play's result and next play have to add and remove previous accordingly.' needs to be better explained.

  • Just like said.

  • i am not recording correct or incorrect

    I am recording how many times correct clicked and how many times incorrect clicked

    if i clicked correct total 8 times then save that value to array 8 and same with incorrect

    saving both total correct and total incorrect

  • and thanks for your kind help

  • Almost the same then, push correct variable to back of X and set array.width-1,1 to incorrect variable.

    This leaves you with

    correct | incorrect

    correct | incorrect etc

  • I didn't understand

    How to put value in x and y

    okay let me tell you what i am trying to store data

    on Correct set at xy (x selecting index number 0, y selecting index 0 and then value

    on Incorrect set at xy (x selecting index number 0, y selecting index 1 and then value

    is this right?

    now what i have to do when all 5 slots are full of values?

  • It's still not well explained, better you try to explain the game more. What 5 slots?

  • Sorry for my bad English (all 5 slots means arrays table 0,1,2,3,4)

    okay i am making kids games where a 3 character appears with three different color and a there is also a Sprite which showing color which kids will select.

    those character will come 5 time in screen means they have to select Correct color character 5 times.

    So i want to record how many time they choose correct and how many time they choose incorrect.

  • Not sure I'm fully understanding it but let's say it's 5 'levels' or characters and in each level you can pick correctly or incorrectly and then it moves onto the next question. Each question is represented by a row in the array so 0, 1, 2, 3, 4 are the questions and correct is at Y=0 and incorrect is at Y=1.

    You would have a question number variable which starts q=0.

    Then the logic is, whenever a player selects a colour, if correct add 1 to array.at(q,0), if incorrect add 1 to array.at(q,1)

    Then when the question is over you add 1 to q.

    So your array corresponds in this way

    question 1 | 0,0 | 0,1

    question 2 | 1,0 | 1,1

    question 3 | 2,0 | 2,1

    question 4 | 3,0 | 3,1

    question 5 | 4,0 | 4,1

  • still i am unable to find any solution

    I am able to store data but need some help

    my array size is x = 0,1,2,3,4 and y is = 0,1

    Storing "correct" in y0 and incorrect in y1

    i am able to store data in this and now i want to store first value of "correct" in x0y0 and first value of "incorrect" in x0y1 then i want to move this x0y0 to x1y0 & x0y1 to x1y1 and move the previous data to next cell. I mean always new data will be store in x0y0 & x0y1 and the older data will move accordingly.

    I hope now you understand.

  • Yeah that's fine, for this instead of pushing at the back as described above you push to the front. When you push to the front, the old data moves down and becomes 1,0 and 1,1 and the new data becomes 0,0 and 0,1. Does that help?

  • I don't know what is proper way to store data in x0y0 and x0y1 using push.

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