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.

DarkBASIC Professional Discussion / Reading file data...

Author
Message
Gadget
16
Years of Service
User Offline
Joined: 18th Jun 2010
Location:
Posted: 3rd Jul 2010 02:45
Hello,

I am playing with making a map maker using the unfinished tutorial in the 2D forums. The concept that he starts with is making an array the size of the map and then each point on the map is assigned a spot in the array. Makes sense. But I can not figure out how to read the numbers from a file and then load them into the array.



This is my code thus far but it only prints the number 48 or 49 repeatedly, not a 1 or 0. So what am I doing wrong in my code please? Thanks a ton.

Gadget
Sepnon
16
Years of Service
User Offline
Joined: 7th Feb 2010
Location: Brazil
Posted: 3rd Jul 2010 03:40
Change this:


To this:


Wrong command
Gadget
16
Years of Service
User Offline
Joined: 18th Jun 2010
Location:
Posted: 3rd Jul 2010 07:00
Thanks,

I think that is reading from the file but the number coming out is not the data info or either a 1 or a 0. It is a longer number. Any idea why? Thanks again.

Gadget
nitrohaze
23
Years of Service
User Offline
Joined: 21st Apr 2003
Location:
Posted: 3rd Jul 2010 15:56
Hello Gadget,

Would you be able to attach your text file mapdata.txt

I will then have a look at it for you.

Kindest Regards
Gadget
16
Years of Service
User Offline
Joined: 18th Jun 2010
Location:
Posted: 3rd Jul 2010 20:18
It is just a simple file that says data 1,0,0,1 but here it is.

Also does anyone know how to make an image snap to a grid?

Thanks again.

Gadget
Sepnon
16
Years of Service
User Offline
Joined: 7th Feb 2010
Location: Brazil
Posted: 3rd Jul 2010 21:20 Edited at: 3rd Jul 2010 22:18
hmm thats the problem
I suggest you getting some tutorials about file commands.

try doing this:

open a 'new project', and compile this:



Now go to your C drive and use that mapdata.txt and see if that works
If you compiled that code above, open the txt file and see whats inside. Thats why it didnt work.. your code is reading the first 4 bytes and assuming its a integer, in your case, the letter "d" from "data"
Yep.. those datas are not meant to be there
In the notepad, we can only write data as 'strings' (((i think))), so if you want to write integers you'll need to do it this way


[edit, note: ]
"read string" ==> gets data as string
"read file" ==> gets data as integer
[/edit :p]

ps: bad english?
Gadget
16
Years of Service
User Offline
Joined: 18th Jun 2010
Location:
Posted: 3rd Jul 2010 23:38
Ah ok, that makes sense then. I searc@he'd for some info on using files but didn't see anything on it. Thanks for the help.

Gadget
Gadget
16
Years of Service
User Offline
Joined: 18th Jun 2010
Location:
Posted: 4th Jul 2010 04:23
Ok that script works to create the file I need but when I open the file there are just 4 characters in it and no numbers. However, my script is able to read it and produce the desired image. Here is a copy of the file.

Also another odd thing is that I have to delete the file for this script to generate a new one, that is very odd imo. But I'm sure that the final script would nee much more than what you gave me so when I get to that point in my game I will look into more. Thanks again.

Gadget
Sepnon
16
Years of Service
User Offline
Joined: 7th Feb 2010
Location: Brazil
Posted: 4th Jul 2010 04:43
Yep.. the integer 1 is not equal to the string '1'
there's an integer 1 in that file.. notepad will not show it correctly, because it shows strings
try writing strings and open the file with notepad

and about deleting the file, look the help files.
"Open to Write": The file must not exist or the command will fail.
Gadget
16
Years of Service
User Offline
Joined: 18th Jun 2010
Location:
Posted: 4th Jul 2010 05:53
Ah, ok. that makes sense. Thanks for the help.
Dia
21
Years of Service
User Offline
Joined: 16th Jan 2005
Location:
Posted: 4th Jul 2010 06:07
Of note, pretty sure that unless you specify 'write string' then the data written to the file is encrypted, so unless you can type encrypted data into the .txt file yourself then when you use the 'read' command it will assume that it is looking for encrypted data and 'unencrypt' it (even if it is cleartext in the file)

check out TDK's tutorial on file access. HEAPS of handy info about reading and writing to and from files. just do a forum search for it

This is not the Sig you are looking for....
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 4th Jul 2010 08:21
If you use any other data types other than strings it'll look funny if you try to look at it with a text editor but it's not encrypted unless you make an encryption/decryption routine.

Dia
21
Years of Service
User Offline
Joined: 16th Jan 2005
Location:
Posted: 4th Jul 2010 12:28
sorry, was just reading "Some of DB's save data commands create encrypted files which can't be opened for examination - despite any advantages they may have"

This is not the Sig you are looking for....

Login to post a reply

Server time is: 2026-07-25 08:12:30
Your offset time is: 2026-07-25 08:12:30