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 / BIG arrays (or an alternative?)

Author
Message
devilman
23
Years of Service
User Offline
Joined: 1st Jun 2003
Location: United Kingdom
Posted: 19th Jun 2003 22:06
I'm trying to recreate a simple LCD game as my first challenge in DBPro. The game has two modes - one has 50 levels and the other has 1000.

The first 50 levels weren't too much of a problem. Each level starts with a number of different lights set to on plus there are a couple of other variables. The level data looks like this -

data 2,6,1,3,5,6,8,10,16,18,20,21,23,25,99,8
data 3,6,2,4,6,7,9,10,11,12,14,15,16,17,19,20,22,24,99,11
data 4,6,6,7,9,10,16,20,21,22,24,25,99,5

With the level data being of varying lengths I used the 99 to stop the for/next loop reading that line. All this data is read into an array at the start of the game so there's no hassle later.

Initially, I've just set up 25 levels and it takes about 10 seconds for the game to kick in, presumably while it's doing all the read & data statements. Not an ideal length of time but I can live with it.

Now, obviously I want to implement the other 1000 levels into the game. I've tried it the same way initially - lots of data statements and a loop to read them in. However, when I run it, it goes on seemingly forever! I set it going 30 minutes ago and it still hasn't started up (My PC isn't the fastest but a 1ghz Athlon isn't THAT bad).

So... is there a better way of doing this?? :-s
Mentor
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 19th Jun 2003 22:41 Edited at: 19th Jun 2003 22:44
it shouldn`t take that long, there may be an error in your code that is reading the data over and over, DB wouldn`t take an average of over 2 seconds per level to read the data you listed there, thats way too slow, a code error may be causeing it to read the data over and over, or you may just have a code error that made it crash, the more elegant way to do this is to load all your level data into a memblock and load it at runtime, or save the data to a file and then load that, much faster than reading data one bit at a time, just take your current data and make a memblock to hold it and then read it into the memblock as byte data and save it for future loading, or write a file containing the data to disk, or make the array and then save it to disk as an array and then you just have to load it, Cheers.

Mentor.

oh! just a thought...at your listed speed it should only take 6mins 40 secs for the levels to load (if they are a comparable size to the 25 you mentioned), so something sounds off.

devilman
23
Years of Service
User Offline
Joined: 1st Jun 2003
Location: United Kingdom
Posted: 19th Jun 2003 23:51
Thanks for that Mentor. I found part of the problem - I'd missed one '99' out of the data and that caused the program to hang. Since I corrected it though, it now takes 3½ minutes for the game to start up. :-s

This Memblock stuff might help by the sounds of it - the help doesn't explain it too well though.

ConsoleMAD - The best Retrogaming Website based in my street.
Bloodshot
23
Years of Service
User Offline
Joined: 7th Apr 2003
Location: United Kingdom
Posted: 20th Jun 2003 04:17 Edited at: 20th Jun 2003 04:21
Hi devilman, I've recently made some Code Examples for MEMBLOCK commands.
You can find them in these two threads:

"Newcomers Corner - Byte array does not work properly"

and

"DarkBASIC Pro Discussion - Saving the contents of an array"

If you need any extra help, just let us know.
devilman
23
Years of Service
User Offline
Joined: 1st Jun 2003
Location: United Kingdom
Posted: 20th Jun 2003 14:27
I tried using your second example and tweaked the first bit to look like this

BYTESIZE=1
XMAX=1000
YMAX=25

BLOCKNUMBER=1: Rem Must be greater than 0
Make MemBlock BLOCKNUMBER,(XMAX*YMAX)*BYTESIZE

to give me 1000 levels.

I then put all my data into a text file but when I run it with the READ command from the bottom part of your example, it runs very slowly again and my machine grinds to a halt.

I've a feeling I might end up putting lots of level1: type commands instead and using restore and read to only read when need be.

ConsoleMAD - The best Retrogaming Website based in my street.
Bloodshot
23
Years of Service
User Offline
Joined: 7th Apr 2003
Location: United Kingdom
Posted: 20th Jun 2003 17:52 Edited at: 20th Jun 2003 20:07
devilman, I've just now edited that post and added a couple of extra lines of code to the Code Snippet example to prevent an error occuring when writing the file:

Rem This will simply delete the test file if it already exists
If File Exist(FILENAME$)
Delete File FILENAME$
EndIf


Apparently you will get an error when using the "Open to Write" command if the file already exists. So, you would have received an error code if you ran my example code more than once.

I've also incorporated the read file command into the program and to skip the print commands slowing the process down.

Sorry for any inconvenience caused (if you ran the program more than once), please try it again.

You do know you only need to save your file as a ".txt" file if it IS a text file containing ASCII values? I used ".dat" in the example as I was simply storing values randomly between 0 and 255 - These wouldn't have made any sense if you browsed the file afterwards in Windows Notepad. You could create your own filename extensions. In your particular case you might have used "MyMapData.lvl"

This is the updated code: (Last Update 17:05 GMT - 20/06/2003)


I tried your array size (1000*25) and encountered no slow down problems when reading the actual file itself. Enable the FAST variable to 1, to skip the Print loop I have in there to speed up the process.
devilman
23
Years of Service
User Offline
Joined: 1st Jun 2003
Location: United Kingdom
Posted: 20th Jun 2003 18:43
Thanks for the help Bloodshot. I thought I'd just try your example as is without using my code and just upping the Xmax value to 1000 to see how it coped with a large number but it gives the error -

Runtime Error 5105 - Memblock position outside range at line 67

Any ideas?

ConsoleMAD - The best Retrogaming Website based in my street.
Bloodshot
23
Years of Service
User Offline
Joined: 7th Apr 2003
Location: United Kingdom
Posted: 20th Jun 2003 18:53 Edited at: 20th Jun 2003 20:21
Try the code one more time devilman, I've made two updates in the past five minutes - you may have the first one which doesn't check the size of the file and compare it to the size of the array before reading.

You would have got an error if you ran the program with one set of values and then changed those values on a second run (i.e. if you altered XMAX and/or YMAX (or even BYTESIZE)). (For example, the program would have attempted to load a 1000*25 byte size file into an array recently changed back to 4*4, if this check wasn't added.)

Here's the most recent example again, though I have gone back and updated all the other links since: (Last Update 17:05 GMT - 20/06/2003)
devilman
23
Years of Service
User Offline
Joined: 1st Jun 2003
Location: United Kingdom
Posted: 20th Jun 2003 21:10
Ah.. thanks for that - I was looking at the other version. Looks like all I need to do know is convert your code snippet to read the data in from an array, get the program to output the level into a file which I can then use within the game code.

Sounds good in theory.

ConsoleMAD - The best Retrogaming Website based in my street.
devilman
23
Years of Service
User Offline
Joined: 1st Jun 2003
Location: United Kingdom
Posted: 21st Jun 2003 21:36
Got it working nicely now - thank a lot for your help!

I can concentrate on getting the rest of the game finished now!

ConsoleMAD - The best Retrogaming Website based in my street.

Login to post a reply

Server time is: 2026-07-07 06:02:27
Your offset time is: 2026-07-07 06:02:27