Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Logic help - comparing 2 UDT arrays sometimes fails

Author
Message
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 17th Dec 2013 18:19
Hi everyone, we found an intermittent error in our game that I'm having a difficult time reproducing. I've isolated the code where it happens and I see what the error is, but I cannot determine why it is happening.
I ran about 500 iterations of the test this morning and it passes every time. At this point I really need a second pair of eyes to look over my logic and tell me what I could be potentially doing wrong.

Here is the code:



Here is the error log confirming the test data that I use above (which passes), but as can be seen in the error log, it actually failed.


We can see that for some reason only the first element in playerHand[] gets marked with the switch flag, while every element in tempHand[] gets marked with the switch flag.
It is like the comparison of the letter$ element is comparing empty strings, or somehow passing, but even then it doesn't make much sense because the array element for playerHand[].switchFlag would also have to be 0 for each tempHand[] element to get flagged...
It's just really odd and I can't see what is up.

All suggestions welcome.

Thank you!

Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 17th Dec 2013 19:59
I've added some extra things to this now to try and help...
I'm now initializing all of the switchFlags to zero before we start the comparison. If the comparison fails I retry up to 10 times.
I also split up the conditional in the comparison just in case AppGameKit is improperly handling the order of operations or something odd...

Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 17th Dec 2013 21:33 Edited at: 17th Dec 2013 21:41
init the .switchFlag was a good idea.

some odd syntax i see is this, but i don't believe it is your problem.
but try exclude first.

type tile_type
letter$ as string
y# as float
x# as float
endtype

should be this
type tile_type
letter$
y#
x#
endtype

or this
type tile_type
letter as string
y as float
x as float
endtype

AGK 108 B19 : Windows 8.1 Pro 64 Bit : AMD Radeon HD 6670
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 17th Dec 2013 21:58 Edited at: 17th Dec 2013 22:00
I think the loop exits need looking at. You have some nested loops, so the exit from the inner loop does NOT exit the outer scope. Then, later:


It looks as though all the switchflag fields in tempHand are previously set to 1, so letterIndexToAdd will remain at zero.

In the double loops I would set a sentinel - pseudocode:


Mind you, I may be talking complete reindeer poo because I haven't used Basic for over 30 years!

-- Jim - When is there going to be a release?
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 18th Dec 2013 17:14
Thanks guys.
@Jim - the first double for-next is only supposed to exit the inner most loop. It takes each tile in the player's hand and then compares it with the tiles in the new hand. If there is a match, both of the switchFlags are set so that it doesn't look at that tile in the new hand again. If I exited both loops when the inner loop found a match it would only find one match, whereas it is looking to match all but one.

After that there are two separate loops that look to find which tile did not get a match.

I ran about 5,000 tests after doing some restructuring and this succeeded each time. The only thing I can think of is that for some very strange reason tempHand[i].switchFlag was set to 1 before this function started. Which doesn't make a lick of sense because this is where tempHand is initiated and the only place switchFlag is used. So... I just made sure that they were indeed set to 0 in both tempHand and playerHand before we start this algorithm.

@Markus
That's the variable naming convention I use. It works great. Yes it is probably unnecessary to add $ / # AND "as string/float", but I like to be as explicit as possible in my coding. If there's some actual bug with declaring a type like that then it'd be good to know, but I've not had any issues elsewhere.

So, the app is out there, I've got extra error checking and if this fails for some reason after 10 tries (wherein I clear the UDT arrays each time) then it throws an error with the game and it closes/reboots with a warning to the user.

Thanks for the help guys.

Login to post a reply

Server time is: 2024-11-24 23:33:17
Your offset time is: 2024-11-24 23:33:17