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

Get help using Construct 2

Post » Thu Dec 06, 2012 11:28 am

Hello,

I have been pulling my hair out on this one because I cannot get the logic right (obviously).

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.
http://dl.dropbox.com/u/31121080/TestCardDeal.capx

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.

Thanks
Brett
B
5
Posts: 19
Reputation: 513

Post » Thu Dec 06, 2012 4:32 pm

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.
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,000

Post » Thu Dec 06, 2012 10:41 pm

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;
Set CARD_DECK_POSITION to n;
Add 1 to n;

Everything else is left the same.

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

Thanks
Brett
B
5
Posts: 19
Reputation: 513

Post » Fri Dec 07, 2012 12:46 am

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)

B
54
S
28
G
18
Posts: 1,520
Reputation: 25,000

Post » Fri Dec 07, 2012 1:00 am

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!
Brett
B
5
Posts: 19
Reputation: 513


Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go, jul, nicklowkcmagic and 19 guests