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 / Matrix1Util_22 (DATAFILES) tutorials?

Author
Message
luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 19th Mar 2010 23:13
Hi everyone,
i need tutorial and some help on datafiles managing.In my curent project i need to save data in files and be able to load it later, because i`m making level editor for a game.It`s most serious project i work on, and until now i never done this.I try to search forums for "files" and etc but nothing useful.I need to know how to structure the file properly.I have many things to store in there and they are all different, object data, sounds, textures and other...Currently i have some progress with simple tasks like reading positions for objects, but this is testing for now because i add the objects manually.I have many questions if there is a guide or tutorial somewhere please share with me.

Where there is a will, there is a way.
I often edit my posts, that`s who i am
ShaunRW
DBPro Developer
16
Years of Service
User Offline
Joined: 7th Jan 2008
Location: Brisbane, Australia
Posted: 20th Mar 2010 05:57
Hey luskos,
TDK's File Access Tutorial. This tutorial should explain how to read and write to files. It uses the DBPro file commands but it's pretty much the same concept as the datafile commands.

Hope it helps and Good luck with your level editor.

luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 21st Mar 2010 11:48 Edited at: 21st Mar 2010 11:50
Thank you for this tutorial it`s very good start for me.However i have some trouble with reading some data from datafile.My code did not read what i write in the variable, need to find what cause this.When i make my integer variable eqauls "2" and write it then execute code to read it, it reads some 5 digits number...Very strange.I need to make some index variables in my file(i`m not sure this is the word, index?)read them first assign the data to wherever they are needed and accordingly to them the next data is read.Something like i save how many objects i have in the integer, then comes the data for the objects, position and etc.I want to use my integer for my routine.If i have for example 500 objects, then data is read 500 times in my routine then i know there is no more data about the objects to read and move to next routine that is loading something else.What i managed now is read the file without index, it start reading and read untill end is reached.

Where there is a will, there is a way.
I often edit my posts, that`s who i am
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 21st Mar 2010 13:47 Edited at: 21st Mar 2010 13:50
Code and example datafile to read?

I suspect that you are simply typing the numbers into a text editor, and reading back using the DATAFILE INTEGER function, which is never going to work. In that form, the numbers are actually strings, so you'd need to read them using DATAFILE STRING$, and then convert them to numbers using the INT function.

BTW, ShaunRW is entirely correct - the datafile plug-in was designed to be a match to the way that the DBPro file commands work - it should be easy to map TDK's tutorials to the datafile commands

luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 21st Mar 2010 14:24 Edited at: 21st Mar 2010 16:35
No i didn`t touch text editor.Reading and writing was made in my application, but i overwrite the code that make this happend.IDK what was wrong.I test this only, again and it worked.I think that maybe there was problem in reading routine, maybe it was reading data that represent float or string and once assigned to integer variable given ressult was not what i expected.If i have same problem again will post code, because right now i`m working on save, open stuff.

EDIT: I make experiment and it happend the same as before when i made it write float and try to read it as integer, so bassicly it was my mistake.

Where there is a will, there is a way.
I often edit my posts, that`s who i am
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 21st Mar 2010 21:32
Ah, that's easily done if you're not careful.

You might be interested in looking at the new commands in the last release for SAVE ARRAY TO DATAFILE and LOAD ARRAY FROM DATAFILE - You should use these commands anywhere that you are read/writing data from both basic and UDT arrays to avoid this kind of problem.

luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 22nd Mar 2010 14:22 Edited at: 22nd Mar 2010 14:53
Thank you about sharing this with me, it was just what i`m looking for now.Because it`s best to first write my index variables in the file and then the objects data, but objects data is done first and the index can be done only last, because for example one of the index variables contains how many objects i have to load/read, i need to use it in finite loop routine, so i can assign it as end-value.That`s the way i imagine`s best fit to know when to stop reading routine when i`m sure there is no more object data and move to next routine loading something else.

Also i`m considering to write to multiple files, every with it purpose and then pack them as one.Reverse the process when read them.

I`ll sure look at SAVE ARRAY TO DATAFILE and LOAD ARRAY FROM DATAFILE
because, i`ll need UDT for sure.And i allready know that saving UDT in array and loading it back can be tricky, from what i read in forums.

EDIT:I try to do something like this, which is not working because of...?



Where there is a will, there is a way.
I often edit my posts, that`s who i am
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 22nd Mar 2010 16:10
Don't open the file and close it for each array. Just open it once, write all of your arrays, then close it. Remember that OPEN DATAFILE FOR WRITE clears the file completely.

luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 22nd Mar 2010 20:00
This was just sample code that generate runtime error.It`s not actual code and because it`s just that i close the file.Is there something wrong in it?That`s why i post it here.I didn`t try with UDT array.It`s pointless if it gives error with ordinary array.

Where there is a will, there is a way.
I often edit my posts, that`s who i am
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 23rd Mar 2010 23:24
It works perfectly:


So, when did you last download my plug-ins? These are newly added commands, and if your 'runtime error' is actually a compile-time error of some sort then that would explain it.

luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 24th Mar 2010 13:05
The error:

I posted "CrashOn" from example you provided and it`s not working for me.
Matrix1 files:
Creation date: 03 March 2010
Modified date: 02 March 2010
I believe this is the last update.
If i launch DBPro from "Launcher.exe" it recognize your plug-in, but "editorU73.exe" can`t.Maybe there is something i did wrong?

Where there is a will, there is a way.
I often edit my posts, that`s who i am
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 24th Mar 2010 19:39
Download the redistributable zip file from the Matrix1Utils page and unpack the content into your c:\Windows\system32 directory.

The reason it works from the original editor is that Lee included a copy of these file in the compiler directory, and the original editor runs your program from there. The new editor does things differently.

luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 25th Mar 2010 20:08
Sorry for my late answer but i have problems with my ISP.
What i need to unpack in c:\Windows\system32?

I make fresh install of dbpro (the free one) unpacked your plugins in main folder of dbpro and it worked.Your example and mine too.I don`t know what is causing random errors in my code where other people run it fine.And it happens only with few commands.

Where there is a will, there is a way.
I often edit my posts, that`s who i am
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 26th Mar 2010 21:35
See the very last link on the very first post on the Matrix1Utils thread.

luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 27th Mar 2010 21:19
is this the link :
VC++ redistributables : http://forumfiles.thegamecreators.com/?i=959271
I allready have them.
I have some troubles with the new editor, sometimes when i compile it runs my last compiled code, not the actual code.Is this a bug?Should i post in bug section or there is solution for this?

Where there is a will, there is a way.
I often edit my posts, that`s who i am

Login to post a reply

Server time is: 2024-09-28 16:23:34
Your offset time is: 2024-09-28 16:23:34