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 / read numbers from file to array

Author
Message
healthyaddiction
22
Years of Service
User Offline
Joined: 20th Sep 2002
Location:
Posted: 20th Aug 2009 17:40
I am trying to read numbers from a file and store them in an array as part of my tile based collision however the reading doesn't seem to be working properly. My text file has this stored in it:

and my code is like this:

This fills the array with odd numbers but I assumed that's just the ascii code or something so after searching the forums I tried:


This does give me 1's and 0's but totally in the wrong places. Can anyone spot anything obviously wrong?
Thanks

keep the addiction healthy
Softwizz
15
Years of Service
User Offline
Joined: 14th May 2009
Location: U.K.
Posted: 20th Aug 2009 18:40 Edited at: 20th Aug 2009 18:49
This works:


Adapted it from this thread:
http://forum.thegamecreators.com/?m=forum_view&t=104421&b=7

Proof of working:





Nothing to see here, move along please.

Attachments

Login to view attachments
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 20th Aug 2009 18:56
Yes, that works.
If you want to do it in a somewhat cleaner way though, the ascii codes for 0 - 9 are 48 - 57. So, you can basically read the file contents as bytes, then subtract 48 from each value, and there you go.

Softwizz
15
Years of Service
User Offline
Joined: 14th May 2009
Location: U.K.
Posted: 20th Aug 2009 19:47 Edited at: 20th Aug 2009 19:50
Here is a slight alteration that will make a coloured cube depending on the map value







Nothing to see here, move along please.

Attachments

Login to view attachments
healthyaddiction
22
Years of Service
User Offline
Joined: 20th Sep 2002
Location:
Posted: 21st Aug 2009 13:23
thanks for the help guys!

keep the addiction healthy

Login to post a reply

Server time is: 2024-11-25 02:26:01
Your offset time is: 2024-11-25 02:26:01