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 / Loading information from a text file

Author
Message
Woarther
14
Years of Service
User Offline
Joined: 21st Feb 2010
Location: Sweden
Posted: 10th Mar 2010 19:50
I've been trying to fix this for over 2 hours, and it's starting to annoy me. What I want it to do is to paste my 32x32 image on a specific location, depending on information from a text file.

It does what it should, but it ignores some "pastes"

Here's a screenshot of my problem:



My asc.map looks like this:


This is my code(The load from text file is more or less copied from a tutorial called "Tutorial 6 - Huge Dungeons"):


Thanks in advance!
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 10th Mar 2010 22:22
The lines are terminated by the byte sequence #0a 0d. Therefore, whenever passing the end of a line you will read those bytes, which doesn't correspond to "F". Since you only read 5 by 2 bytes from the file you will thus miss out on two.

You can use read string to read a full ascii line from a file, or you can make your code just skip by those specific bytes. Or any other that you don't care for, for that matter.

Woarther
14
Years of Service
User Offline
Joined: 21st Feb 2010
Location: Sweden
Posted: 11th Mar 2010 15:50
Thanks for the quick reply!

It gave me a new question though; How do I make my code skip the bytes you mentioned?
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 11th Mar 2010 16:12
You could load all of the data into a string array dimensioned with Dim ArrayName$(5,3). This would load all of the F's in your 5x3 grid example above.

But, using Read String, it would see your map as three lines so it would load 'FFFFF' three times. Just use a For Next loop to run through the 5 F's putting them into the array then loading the next 5.

Your second loop could then do as it currently does but access the array you've loaded all the F's into.

You would probably be better off in this case though, using an integer array when you create the map and use Save Array. The array would be loaded back in with Load Array and you would loop through it pasting the image as you are already doing.

And by the way - take the Load Image out from inside the loop - you only need to load it once - not every time you paste it.

TDK

Woarther
14
Years of Service
User Offline
Joined: 21st Feb 2010
Location: Sweden
Posted: 11th Mar 2010 17:41
I didn't understand much of what you said(probably because I'm fairly new to programming)

[/quote]But, using Read String, it would see your map as three lines so it would load 'FFFFF' three times. Just use a For Next loop to run through the 5 F's putting them into the array then loading the next 5.
Quote: "

How would I do that? Could you provide me with an example?

[quote]You would probably be better off in this case though, using an integer array when you create the map and use Save Array. The array would be loaded back in with Load Array and you would loop through it pasting the image as you are already doing."


I looked up the 'save array' command in the DBPro editor, and I can't figure out why that would fix the problem. Can you explain this more throughoutly?

Thanks!
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 12th Mar 2010 02:50 Edited at: 12th Mar 2010 02:54
You would first have to write a small program to feed the required values into the array. At the moment, when you read in the character 'F' you paste a specific image. Instead of an F, let's make it a number 1.

Note: Typing this straight into the forum - not DBPro so it may contain errors. Should point you in the right direction though.



That creates and saves an array containing 3 rows of 5 1's. You could add to the program giving you the ability to select and paint the tiles, then save the array containing different patterns of numbers. This would be your level editor.

The other program would load the array in and create the level using the data in the array. Something like:



You could have lots of different tile types - however many images you load in is how many different numbers you can have in the array.

TDK

Luxor_Lar
14
Years of Service
User Offline
Joined: 7th Mar 2010
Location:
Posted: 26th Mar 2010 01:15
What is DarkBasic Pro code to import a MilkShape exported .x? The filename is Cylinder.x.

Login to post a reply

Server time is: 2024-09-28 14:18:39
Your offset time is: 2024-09-28 14:18:39