I'm losing my cards, please help...

0 favourites
  • 5 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • Hello,

    I have been pulling my hair out on this one because I cannot get the logic right (obviously). <img src="smileys/smiley5.gif" border="0" align="middle" />

    What happens is my cards are dealt (into 4 piles) and then player 1's hand is resorted into A, K, Q, J, 10, 9, 8, 7, 6, 5, 4, 3, 2. The problem is while the sort works the cards in my deck are randomly dropping out. I can stop the resorting and all the cards remain (but out of order) so I know it can only by this line of code that is the problem.

    Here is the link.


    The line in question is 81 and I have striped it bare to avoid confusion and eliminate any other possibility of it being something else.

    Any assistance in shedding some light on my error would be appreciated.



  • In an empty array all the values are 0. If your random number is 0 it won't be used because it already exists in the array so you don't have any card where CARD_ID_ORIGINAL = 0.

    And you should 'set value at n to Random_Number', not 'set value at n-1' otherwise the first value will be at -1 and you end up with a duplicate.

  • Thanks for the help ramones.

    I've been stuck on this for a couple of weeks and I have tried many, many variations on the array. So far I cannot get it working properly. When I have it set up logically like your suggestions the program freezes.

    var Random_Number = 0;

    var n = 0;

    While (n < 52) {

    Set Random_Number to floor(Random(1,52);


    if (myCardNumber does not contain Random_Number) {

    Set value at n to Random_Number;

    Create object Cards;

    Set CARD_ID_ORIGINAL to Random_Number;


    Add 1 to n;

    Everything else is left the same.

    Do you have any suggestions to why this isn't working?



  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Zero is already in the array (it's all zeroes at the start) so you can only add 51 values (1-51). It keeps looping trying to add 52 values which isn't possible = infinite loop = freeze.

    You could set all array values to -1 first.

    (or you could use values 1-52 instead of 0-51)

    <img src="https://dl.dropbox.com/u/8367729/construct/pics/cardarray.png" border="0" />

  • Thank you so much! I did try the 'CurX to 0' previously but changing it to '-1' was something I would never think to do and it fixed everything up!!!

    You have made me very happy. :D

    Thanks again!


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