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.

Newcomers DBPro Corner / a few random questions on items that are sticklers for me

Author
Message
erebusman
12
Years of Service
User Offline
Joined: 23rd Jul 2011
Location: Sacramento, CA
Posted: 19th May 2012 07:15
Hello...

Trying to work out my last few stickler items on a program I'm working on so here are a few questions if anyone has some insight to share I'd be appreciative

1: On the "No More Moves" screen I display a graphic that says "Press any key to continue" and in code I put the 'wait key' command. If the users presses any keyboard key the game goes to the high score screen.

However if the user presses the mouse - it does not progress.

How do I tell it to scan for either a mouse click OR a key press and then continue to the next screen?

2: When read/writing my high score it works perfectly within any one game. It often works perfectly through more than one game. But eventually for unknown reasons the high scores will become 'corrupt' if you will and show improper values.

The minimum score you can make in my game is 60 but in my current highscores.dat file I hvae scores of 2240,980, 54, 49, 50, 48 .

Everything past the 980 is an impossible score.

The code to write the file is here:




I'm writing the score in a string value according to the suggestion in TDK's tutorials so I can see what its actually putting down in this instance quite helpful. But still doesn't tell me what I'm doing wrong or why it only some times gives crazy results.

3. This last one is very difficult and honestly I may not be able to fix it. The problem is during game play while game logic is executing the player can not click ; and this is surely because of the way I programmed the game logic and display logic are very tightly intertwined. In other words - it is intended that you can not click before the previous move is done.

However when the game is DONE drawing the last move you can NOT click on anything for about 3/4 of a second afterwards.

For players that are quick this becomes a source of many perceptive 'missed' moves.

I *CAN* display an hour glass that lets the player known that its not time to move yet however when I do that .. the game gives the perception of 'playing very slowly' because the hour glass stays on a fair bit while game logic is running and moves are being drawn out.

The game play is your basic "Match 3" game so there really is no need to have the player doing another move while the current one is playing out so I'm not concerned that it be liked bejeweled 3 where you can actually start clicking while other gems are still dropping and combining. But I do want to try to fix the fact that you cant click while the game appears to be done with all its work.

One hint that *might* help is that the game appears to take 25% of my CPU no matter what I do to try to optimize. I'm concerned maybe this is due to me making some common mistake that over taxes the CPU and this could be tied into the game taking a little longer to permit the next click than it should? What are some common mistakes people do that over-tax the CPU?




Thanks in advance for any assistance!
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 19th May 2012 08:40 Edited at: 19th May 2012 14:54
1.


2. I would write it like this, but it looks okay to me:


Don't see anything open and obvious in the file saving code. Are you sure the values of HighScore(N) are always correct? Maybe you could have it print the text of the high scores just before it writes them to the file to see.

3. Sounds like you need to make your game logic much more efficient. With a match-3 puzzle game, the computer should move faster than the player could click. 3/4 of a second seems like a really long time.
EDIT: As for waiting for it to complete the level, you could speed up the process when it is finalizing the level, so the user can see it finish, but at a faster rate. You could add to this a graphic that basically informs them the level is done, how many bonus points they have earned, or something to that effect.


Overtaxing CPU: Making it do repetitive things that it doesn't need to do, making unnecessary screen redraws, for / next loop nesting, making the computer calculate things repeatedly that could be stored in variables

So many games to code.......so little time.

MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 19th May 2012 13:39
Jumping in...

nonZero
12
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 19th May 2012 20:47
Quote: "How do I tell it to scan for either a mouse click OR a key press and then continue to the next screen?"


My 2 Cents worth:


erebusman
12
Years of Service
User Offline
Joined: 23rd Jul 2011
Location: Sacramento, CA
Posted: 19th May 2012 21:10 Edited at: 20th May 2012 00:21
Thanks LBFN

1 : This did the trick , appreciated.

2: I am pretty sure the values are correct because this is how I test



I changed it to write as a string so I could also copy the highscore.dat out each day to make sure the values in it were the right values before the next day.

My thought is *maybe* something about making a new build the next day is triggering a problem in the file? Because on any one day I don't think I have yet caught it going bad that particular day.

3: You said maybe this :
---------------
Overtaxing CPU: Making it do repetitive things that it doesn't need to do, making unnecessary screen redraws, for / next loop nesting, making the computer calculate things repeatedly that could be stored in variables
---------------

So I do this quite a bit for the game logic because the array that holds the game gem values is a 2 dimensional array so I do something like this (note I trimmed a lot out to make it more easily read but shows the nested loops)



I do this type of situation in 4 different subroutines for each pass through game logic.

I don't know if thats considered excessive or not since its my first program?

Thanks for the responses much appreciated.
erebusman
12
Years of Service
User Offline
Joined: 23rd Jul 2011
Location: Sacramento, CA
Posted: 19th May 2012 21:31
@nonzero

I like the way you expressed that. Its interesting to see how you can more efficiently say the same thing if your thinking the right way, thanks for chipping in!
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 19th May 2012 22:01
Yeah, I never thought about adding results together before.

erebusman
12
Years of Service
User Offline
Joined: 23rd Jul 2011
Location: Sacramento, CA
Posted: 20th May 2012 00:22
Further testing is showing the corrupted high score is happening more than I thought.

I induced a end game status to happen more quickly so more of my tests end in a 'ended game' so I could watch the high score and its happened 3x in the last hour.
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 20th May 2012 01:35
I'm not at my comp and won't be until tomorrow. You could try dimensioning HighScore() as a word array and write / read them as words.

So many games to code.......so little time.

erebusman
12
Years of Service
User Offline
Joined: 23rd Jul 2011
Location: Sacramento, CA
Posted: 20th May 2012 02:07
I'm fairly sure I found it, just need to test further to make sure now.

So here's what happened.

I wrote the highscore file access to use the regular encrypted non-text file format because I didn't want people editing their high scores.

But then I had this problem.

So I used TDK's tutorials to write it as strings.

What I did was change 2 of 3 area's that i was writing the files out.

1: In the end of game screen.
2: From the Main Menu > High Scores
3: When you exit the game normally

The 3rd area is the one I did NOT change



So now I think that is the problem and I think the "write byte" is the real problem. My guess is a byte isn't long enough?

So I changed the above to be a string and hope its fixed now will test further through the day.

Out of curiosity if anyone knows how many characters the byte was supposed to hold? I thought it was 256 characters but I must be wrong?

Thanks!
erebusman
12
Years of Service
User Offline
Joined: 23rd Jul 2011
Location: Sacramento, CA
Posted: 20th May 2012 02:34
Well on top of the above I also just noticed there was 0 to 10 in the first two loops and 1 to 10 in the third loop.

I know that if you dont read/write the same number of items that can cause a problem too so that might have been it!

Testing further
erebusman
12
Years of Service
User Offline
Joined: 23rd Jul 2011
Location: Sacramento, CA
Posted: 20th May 2012 06:08
Well definitely still not fixed.

None of the above items were it.

So trying to really nail down WHEN it happens; as near as I can tell the scrambling occurs in this circumstance:

- you are playing a game
- the game ends
- you are passed to the high score screen
- at this point the score may become scrambled
- it appears to occur when the player has scored some number above 2000 ; mainly because I have not seen the scrambled score occur at less than 1000 score range yet

- totally unclear if it is necessary or not to quit and restart the game but that did occur in the scenario below

I played 11 games in a row without quitting and got these scores




Then I quit the game came back in and played 1 more and got a score of 3480 and got this on the high score screen




still investigating
erebusman
12
Years of Service
User Offline
Joined: 23rd Jul 2011
Location: Sacramento, CA
Posted: 20th May 2012 06:44
I was able to reproduce the above a bit quicker.


- Played 1 game got a high score of 460
- Quit out
- Played another game
- played 1 more game of about 2000 and score scrambled
nonZero
12
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 20th May 2012 08:21 Edited at: 20th May 2012 20:33
Quote: "Out of curiosity if anyone knows how many characters the byte was supposed to hold? I thought it was 256 characters but I must be wrong?"


A byte is a single character. There are 256 possible numeric values (incl 0). Unsigned range is 0 to 256, signed is -127 to 128.

(Within a byte, exists 8bits (where 8bit consoles derive their names). These bits are binary denoting the value of the byte).

In other words, you were writing a single value. If the value exceeds 255, it wraps. Example 257 = 2.

[EDIT]
Quote: "Unsigned range is 0 to 256,"
- Yeah, that's supposed to be 255, I made I typo coz I'd just typed "256" lol
...And I don't believe it:
Quote: "Example 257 = 2."

No, it should be 257 = 1. I must've been tired last night...
[/EDIT]

erebusman
12
Years of Service
User Offline
Joined: 23rd Jul 2011
Location: Sacramento, CA
Posted: 20th May 2012 18:37
So I played 13 games with no problem last night until I scored a higher score of 9720 at which point the problem happened again.

This is the highscore.dat before the problem



This is the problem right after scoring the 9720


So I injected good numbers before the 9720 like so


Launched the game and the problem came back immediately.

So now I have a dataset to work with to introduce the problem immediately to test faster turn arounds for the fix.
erebusman
12
Years of Service
User Offline
Joined: 23rd Jul 2011
Location: Sacramento, CA
Posted: 20th May 2012 18:57
@nonzero : wow thats quite odd a single character .. so thats confusing because when it 'corrupts' it puts 2 digits not a single character.

Since I'm writing as a string now that shouldn't be a problem as far as I'm aware. but obviously I haven't fixed it yet so something is still out there!

Thanks for the response thats very helpful.
nonZero
12
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 20th May 2012 20:30
Quote: "wow thats quite odd a single character .. so thats confusing because when it 'corrupts' it puts 2 digits not a single character."

Perhaps I phrased that badly I meant it was a single literal character. A byte can be up to 3 numeric character, eg:



Quote: "Since I'm writing as a string now that shouldn't be a problem as far as I'm aware. but obviously I haven't fixed it yet so something is still out there!"


Here is a brief example of your code with some of mine. Basically, It should work - saving that is. Make sure you have root write permissions before running the program:

My advice is that you post the latest version of your code in full (so we can see where you are) if you are still having problems as I expect there is something in the code causing this corruption. Quite often we forget to clear a variable, etc.

erebusman
12
Years of Service
User Offline
Joined: 23rd Jul 2011
Location: Sacramento, CA
Posted: 20th May 2012 20:48
Changed the read/write code to not use a loop and variable in case I had something wrong with that:



Interestingly enough I was able to reproduce my bug within 3 games.

I think this helps narrow down that its not specifically the save/load process but perhaps something else.
erebusman
12
Years of Service
User Offline
Joined: 23rd Jul 2011
Location: Sacramento, CA
Posted: 20th May 2012 21:21 Edited at: 20th May 2012 21:27
@nonzero ; thanks I'll look that over

A) regarding the 'byte' 3 numeric characters. That makes 100% sense now; my testing seemed to find that 3 digit numbers never had the problem but when it reached the 4th digit it happened a lot.

Still need to figure out why its happening since I removed that and storing it as a string instead though.

Next post comments:


I have not posted my full code for a couple of reasons

- Its 2800 lines at this point; in the past I have found sharing too much code at once results in few, or even no responses, or perhaps even complaints about formatting because its too overwhelming to read it all.

- While I'm not adverse to sharing entire subroutines or large portions of code; I do intend to go commercial with the product so I am somewhat reluctant to post the entire source code on a public internet forum. I know that limits some of my ability to receive proper feedback though.

- Also my product now includes 113 media files. Most of which I created myself but there are some files that I purchased and the license of which prohibits me from distributing unless they are packaged inside a binary file (so not as individual .wav file for instance) ; so the first thing many people want when they have the source code is the media so they can compile and test it.

Legally I can not do that so I need to be able to covey my concerns in code snippets rather than the entire source and all 100+ media files.

If I continue to not be able to solve it with the excellent advice that you and others have been giving I'll try to make a specialized trimmed, media-less version of my program (much like your example above) to reproduce the issue with for testing purposes.

Thank you.
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 20th May 2012 22:03
What did you dimension the HighScore() array as? A byte? If so, then that is the problem. Dimension it as a word or as an integer and it will work. If indeed you dimmed it as a byte, it can't hold a value larger than 255, so a score of 9720 will be messed up. A word is plenty big or an integer array will work fine.

So many games to code.......so little time.

erebusman
12
Years of Service
User Offline
Joined: 23rd Jul 2011
Location: Sacramento, CA
Posted: 20th May 2012 22:17
@LBFN

- Same thought occured to me so I wasn't sure if this would work but I did

DIM Highscore(10) as integer

Also I hold the highscore in a value called "CurrenScore" that gets passed to HighScore(10) at the end of any game so I also defined

CurrentScore as integer

At the beginning.

Now checking whatever else I pass it to that I may need to define as an integer.
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 20th May 2012 22:27
yes, that should work. If you haven't already done so, I would write one function (or subroutine) to save the data to file and one to load the data. Then when you need them, you call it from the code. This would give you one place to check for errors instead of three.

So many games to code.......so little time.

erebusman
12
Years of Service
User Offline
Joined: 23rd Jul 2011
Location: Sacramento, CA
Posted: 20th May 2012 22:59
Great idea, doing that now!

Quote: "yes, that should work. If you haven't already done so, I would write one function (or subroutine) to save the data to file and one to load the data. Then when you need them, you call it from the code. This would give you one place to check for errors instead of three."
erebusman
12
Years of Service
User Offline
Joined: 23rd Jul 2011
Location: Sacramento, CA
Posted: 20th May 2012 23:53
So just put the read and the save into two separate subroutines ; then actually took the code OUT so it was blank for a minute.

Then I searched my source code and found *another* area I was treating it as a word/byte

So I obviously removed that and pointed everything to the two blank subroutines until I could no longer find any code using the Find function.

Now I have all read & save's two these subroutines and have tested 20 games with no errors yet.

Its looking promising. *crossing fingers*
erebusman
12
Years of Service
User Offline
Joined: 23rd Jul 2011
Location: Sacramento, CA
Posted: 21st May 2012 00:24
25 games later no problems.

Tentatively checking this off as the byte/word problem.

Thanks for all the tips guys.
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 21st May 2012 01:00
That's good to hear. Good luck with it.

So many games to code.......so little time.

Login to post a reply

Server time is: 2024-05-17 03:22:54
Your offset time is: 2024-05-17 03:22:54