SOLVED - I am in need of an explanation on my ARRAY problem (PLEASE)

0 favourites
From the Asset Store
A simple platformer game with detailed explanation and source code
  • Thank you for time. Please help me understand my problem below.

    As you can see below is my condition saying Every XY elemenet if Array.At(curX,15) is in between values then set Array.at(curX,7) value to current value.

    EXPECTED RESULT: 3 is the current then value shouldn't change or also be three(3)

    ACTUAL RESULT:

    WHY??? WHY did it turn to 200?? Why did it get the value beside it or the value of CurX,6????

    Heres another one, same condition as above but this time if condition is correct then CURRENT VALUE PLUS(+) 12

    EXPECTED RESULT: 3 is the current then value should be twelve(12)

    ACTUAL RESULT:

    THE VALUE COPIED CurX,6 THEN ADDED 12?? WHY???

    I'm very sorry if i sound very furious because i really am. I won't be posting here if i havent tried any kind of alternative. My logic makes perfect sense but its not performing what is suppose to. PLEASE correct or explain to me what i am doing wrong

    Thank you in advance! :(

  • Is this a sub-event?

  • umarfarooq

    Yes, heres the full one, its function that will get called at start of layout:

  • Without knowing rest of the code, structure or what you actually want to implement here.

    On top of my head,

    1. For each XY element having a sub-event can sometimes cause un-expected loops. I used the word un-expected to explain that they may differ from what we have in our head.

    2. To debug this, take it out of this sub-event. Make a new event which gets triggered on click of a button and then press the button at the appropriate time in the game. Keep the debug window open and see the result. If you get correct result, this means a problem while using "Every XY..". If you still don't get correct result with a button, means check your Array values.

    / Umar

  • umarfarooq

    Thank you for your time and answer. But i have done what you mentioned and been trying to do any fix for 10 hours now but no luck.

    Can you you say that my condition / logic is correct?

    But still thank you for your assessment.

    I have just learned using arrays recently and i have always been afraid that i might get stuck and now here i am..

  • Can't say your condition / logic is correct because, 1) I don't know what you're trying to implement, 2) If it's the best way to implement that. Now knowing both can render a condition / logic correct or incorrect : )

    Regardless of above, what happened when you Disabled this and triggered using a Button? If you say you're getting the same result, there is something wrong with Condition.

  • Curvalue is the wrong thing to use, it will just use the end of the row so 200 in this case. The logic you're looking for is 'array set value at array.curx,7 to array.at(array.curx,15)'

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • umarfarooq

    Here's my full coding. Let me explain it, start of layout a csv is stored to the array (thanks rexrainbow) then it waits for 1 second to call a Players_defense_overall.

    Players_defense_overall calls 2 other functions that consist of FOR EACH XY elements as stated earlier in my post. You might question why there is a WAIT action between the functions its because i want it to:

    As you can see, the TOPG(defense) will SET Array.at(CurX,17) initial value first depending on what condition it checks out then the after 1 sec, function FPG(defense) (What is should be doing) will add depending on what condition it checks out into the CURRENT VALUE Array.at(CurX,17) but instead that, it doesnt do that.

    I hope my explanation is understandable. If you want i can also upload the capx if you have the time to look into it. Thank you!

  • your loop is running for each X element AND for each Y element. So if your array has 10 rows of data (X), and 16 columns (Y), then the loop will run 160 times.

    you probably only want yo run the loop once for each X element, so you should use:

    "Array - for each X element"

  • Please do what AllanR have proposed.

    Should work.

    Else I can take a look at .capx later

    Thanks

  • Thank you for your time to reply!

    "Curvalue is the wrong thing to use, it will just use the end of the row so 200 in this case."

    IS THIS REALLY TRUE?? I DIDNT KNOW THIS THANK YOU!!

    But what you suggested wont work for me. I dont want to change the value of Array.at(array.curx,15). Im using Array.at(array.curx,15) just to compare it to a number then add a value to a different Y index which is at - Array.at(ArraycurX,7).

    But still thank you for your input

  • I think you want to use

    Array - Set value at (Array.curx,7) to Array.at(Array.curx,7) + 12

    array.curvalue is not what you think it is...

  • I thought the problem was that you wanted to check a value at 15 is between 2 values, then change the value at 7 to the value at 15. That's what my logic does.

  • AllanR

    THIS SOLVED IT! THANK YOU SO MUCH!!!

    I have always been afraid to use array for a long time but recently i have learned and been using it and everything i used it on has been working up until now. This is now another knowledge added to me regarding arrays.

    I thought i had to use For each XY element because my understanding of that is if i only use FOR EACH X it wont read the Y index only the X index.

    Thank you all for you time to see my post! You have no idea how happy i am right now.. !!!

    umarfarooq AllanR

  • Are you sure changing for each XY to for each X resolves this? I wouldn't think so because you are using CurValue.

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