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 / How do I make a top 10 high score table using arrays?

Author
Message
Programmer2000
14
Years of Service
User Offline
Joined: 19th May 2010
Playing:
Posted: 24th May 2010 07:48
I tried to do what was talked about in this tutorial: http://forum.thegamecreators.com/?m=forum_view&t=96084&b=7.

But every time I try to enter the table, it will end the program. Where do I place the commands to create arrays and how do I make the table work so one of the ten high scores will be replaced with a larger value?

The way I had it set up for a test allowed you to press the 1 key to increase the score. I wanted to test a #1 high score that would beat all of the presets in the table.

Here's the code (64 lines; may be confusing):



If anyone could help me on this, it would be greatly appreciated! Thanks!
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 24th May 2010 19:31
I started to just write a couple of subroutines to give you what you needed, but I ended up writing a lot more than I planned.

Anyway, you can increase the score by 2000 by pressing '1'. The current score is shown at the top of the screen. If you want to simulate a 'game over', just press 'A' to update the high scores. Press 'S' to save the file. On startup, it looks for the High Score file and loads it. If it doesn't see it, it loads the default top ten into the arrays.




I tried to put in comments as needed. I hope this is helpful.

LB
Lucas Tiridath
AGK Developer
16
Years of Service
User Offline
Joined: 28th Sep 2008
Location: Kings Langley, UK
Posted: 24th May 2010 19:33 Edited at: 24th May 2010 19:36
Hi. Right I've had a look at your code and from what your trying to achieve, there seem to be two errors in your code. Firstly, your program closes because you are trying to access cell 10 in the HighScore array despite having declared the elements as 0-9. Thus by changing your for loops to:



the first issue is solved.

Secondly, there is the issue that having got the input of the name for the new highscore, you have got the assignment the wrong way around so you don't get the new name but by changing line 50 to:



The name will appear at the top of your list.

Now obviously, there are a number of other problems such as the fact that having got a new highscore, you don't then move everything else down so you actually lose the highest score off the file. However as you are creating this as an example of file handling, I'm guessing that isn't a problem.

The good news is, the errors you got were nothing to do with the file handling. That worked just fine. I've given you your complete code listing with the two corrections I mentioned below:



Perhaps try to use less gosubs in future... They are nearly as bad as gotos...

Anyhow I hope this is helpful.

EDIT: You beat me to it LBFN. Anyhow your example is much nicer than mine so go with that.
luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 24th May 2010 19:34
http://forum.thegamecreators.com/?m=forum_view&t=169546&b=6
You can check this out.You need to download and install 2 plugins but it`s worth.

Where there is a will, there is a way.
I often edit my posts, that`s who i am
Programmer2000
14
Years of Service
User Offline
Joined: 19th May 2010
Playing:
Posted: 24th May 2010 23:57 Edited at: 25th May 2010 04:27
Thanks for the code, LBFN! Lucas, I appreciate your corrections and you posting my revised code.

Luskos, I looked at the article and I'll try out that method. Thanks.


EDIT: Actually, LSBN, I just tried out the code and it won't open on my computer. It will appear for a second and then end program. Any suggestions? I tried removing the SYNCs and Line 4, but that didn't work either. Any idea how to fix it?
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 25th May 2010 06:35
Quote: "EDIT: Actually, LSBN, I just tried out the code and it won't open on my computer. It will appear for a second and then end program. Any suggestions? I tried removing the SYNCs and Line 4, but that didn't work either. Any idea how to fix it? "


The sync's shouldn't have anything to do with it appearing and then going away quickly (I guess I am too used to programming using sync manually). You will need line 4, it sets the values for the ScrWid and ScrHgt variables, which are used in the program.

The code is designed to exit if the SPACEBAR is pressed. If your spacebar is sticking, that could be the problem. Also, are you sure you copied all of the code? Sometimes you can miss some of it.

If those aren't it, you could try inserting a delay in the code to show that it has reached a certain point. Like this:



You insert this code right after the loading / setting up of the high score table and run the program. If that's okay, then you delete it and move on to the main loop and rem everything out but one gosub call. Keep doing this for each subroutine until you find out which subroutine is giving you the problem.
Programmer2000
14
Years of Service
User Offline
Joined: 19th May 2010
Playing:
Posted: 25th May 2010 07:50
My mistake...your name is LBFN. I apologize for mistyping it; I didn't check above that time.

I pasted that code to the end of every subroutine (right before RETURN) and even at the beginning of subroutine SetupHighScores.

The program is opened, then closed right away. I don't know why that's happening. I attached a video of the complete code and what happens when I try to run the program.

Attachments

Login to view attachments
luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 25th May 2010 13:36
While it apear do you see anything or just black screen?

If this is the case try saving it as project close dbpro and when you start it close the newly opened untitled.dba document open your project and compile it.I allways close the untitled.dba document created because any code i load wont run because dbpro try to compile from the empty one.Even when i copy paste in it, it continue to do that because it load it from the tmp or bak file.I`m pretty sure it`s tmp.

Where there is a will, there is a way.
I often edit my posts, that`s who i am
Programmer2000
14
Years of Service
User Offline
Joined: 19th May 2010
Playing:
Posted: 25th May 2010 14:45
It's just a black screen, but saving the source as a project file and then re-opening it didn't seem to work.

That's a good pointer, though, luskos. I'll keep that in mind.
luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 25th May 2010 21:29
Your nick is buged dude!Or the thread or the forum itself.Out in the Newcomers corner it doesn`t show your last post as last but mine.
By the way which version of dbpro you are using?Update to last one, it may be the issue.Sometimes it is really.Obsolete versions won`t run the code properly, even not producing errors sometimes.

Where there is a will, there is a way.
I often edit my posts, that`s who i am
Programmer2000
14
Years of Service
User Offline
Joined: 19th May 2010
Playing:
Posted: 26th May 2010 00:35 Edited at: 26th May 2010 00:36
It's just because I'm a new member. They have to approve my posts first, so that must be why the forum is doing that.

Anyway, I have the latest version - 1.074 or 7.4. I just cleared temporary files and it still doesn't seem to work. Thanks to LFBN's code, I determined that it goes to subroutine SetupHighScores and ends during the restoring of the data.

Here's where I narrowed down the problem. It ends right after the Repeat-Until Mouse Click code:



EDIT: This is the first post that didn't have to be checked. My nickname should appear on the Newcomer's Corner now.
Programmer2000
14
Years of Service
User Offline
Joined: 19th May 2010
Playing:
Posted: 26th May 2010 02:10
Luskos, I downloaded the BMP Font Editor and Matrix1 plugins and I'm going to try them out and let you know how that high score table works for me once I have some free time.
luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 26th May 2010 10:11 Edited at: 26th May 2010 10:12
Ok, mate i hope it suit you best.Actually you can exclude the plugins but you need to port the snippet in plain db code.I can do it when i have free time for this and update the thread.

Where there is a will, there is a way.
I often edit my posts, that`s who i am
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 26th May 2010 16:40
Quote: "Here's where I narrowed down the problem. It ends right after the Repeat-Until Mouse Click code:"


Do you have the following code in the program?
Programmer2000
14
Years of Service
User Offline
Joined: 19th May 2010
Playing:
Posted: 27th May 2010 00:49
Yes, it's at the end of the code you gave me. Should I move that code higher in the program? Maybe it didn't read the data yet.
luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 27th May 2010 10:48
And you tryied my code snippet?You can check it really faster, download 2 plugins, install them and run the code.It have comments so you don`t get lost in the code!

Where there is a will, there is a way.
I often edit my posts, that`s who i am
Programmer2000
14
Years of Service
User Offline
Joined: 19th May 2010
Playing:
Posted: 27th May 2010 11:11
Thanks, I tried it. After I changed the directories, it just loaded a blank screen. The only Matrix1 plugin I didn't install was part 7 (I think it was the one with logarithms). I think maybe it just has a problem with arrays...? Is there a plugin I can use to make an array using a different command, by any chance?
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 27th May 2010 12:38
Quote: "Yes, it's at the end of the code you gave me. Should I move that code higher in the program? Maybe it didn't read the data yet. "


Moving it higher in the code will not solve the problem. Have you tried remming out the 'gosub SetupHighScores' command to see if it will run? It will have all 0's in the high score table, but if this subroutine is indeed the problem, it should run okay.

I'm running out of ideas for why it won't work on your computer. I have run it several times with no problem. I have double-checked the code and see nothing that would cause it to do what is happening to you. Apparently, others have run the code and it works okay.
luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 27th May 2010 19:32
Do the code worked for you?What directories you changed?The only thing that requires to be placed somewhere is the font image which must be in the same folder where you compile the code.

Where there is a will, there is a way.
I often edit my posts, that`s who i am
Programmer2000
14
Years of Service
User Offline
Joined: 19th May 2010
Playing:
Posted: 28th May 2010 01:58
@LBFN I REMmed out the GOSUB line and even the subroutine itself. It must be a problem with my computer. I'll check the disk for errors.

@luskos I set the path of the font image to the same folder the source code is in, in case it tries to default to the TEMP folder. So I changed it to just "font.bmp". Now it seems to have a problem with the BMP Font Plugin. When I try to run the code, an error pops up saying "Runtime Error 504 - Cannot grab image due to an illegal area at line 7 (the line which reads, "make bmp font 999,font").

My computer runs on Windows Vista, by the way. Would you happen to know if the BMP Font Plugin is compatible with Vista?
Sasuke
18
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 28th May 2010 02:24
Quote: "@LBFN I REMmed out the GOSUB line and even the subroutine itself. It must be a problem with my computer. I'll check the disk for errors."


What code is this cause I'd like to have a look at it.

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Programmer2000
14
Years of Service
User Offline
Joined: 19th May 2010
Playing:
Posted: 28th May 2010 09:34
Here you go, Sasuke. This should be the original code that LBFN posted for me to use.

Sasuke
18
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 28th May 2010 14:36
Cheers, seems to work fine for me I'm afraid. This is really strange, I wonder what the issue could be. The only thing I can think of is copying and pasting the code to the IDE corrupted it. Though usually it wouldn't run at all and you'd get a alphanumerical error. So that's out. Have you tried other code snippets and see if they've worked?

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 29th May 2010 18:28
I rewrited the code snippet for you, now you can choose from using dbpro native text,d3d cloggy function or bmp plugin font!Just read the comments where you need to unrem them, it`s currently working with cloggy`s plugin.

Cheers!


Where there is a will, there is a way.
I often edit my posts, that`s who i am
Programmer2000
14
Years of Service
User Offline
Joined: 19th May 2010
Playing:
Posted: 30th May 2010 12:50
Thanks for the codes!

I'll try them out when I have more time and let you know if they work for me.
luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 30th May 2010 15:20
I think there was something wrong in the last post try this instead:


Where there is a will, there is a way.
I often edit my posts, that`s who i am
Programmer2000
14
Years of Service
User Offline
Joined: 19th May 2010
Playing:
Posted: 2nd Jun 2010 09:55
Thanks for all the codes and help, everyone!

I just fixed the errors on the disk and reinstalled DBPro and the update. All of your codes work fine now.

Thanks again!

Login to post a reply

Server time is: 2024-11-24 15:31:58
Your offset time is: 2024-11-24 15:31:58