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 / Saving Arrays using Matrix1Util

Author
Message
Talairina
18
Years of Service
User Offline
Joined: 9th Jan 2006
Location: United Kingdom
Posted: 27th Jun 2010 22:47 Edited at: 27th Jun 2010 23:33
I'm trying to save an Array using Matrix1Util dll's. I'm not even sure I'm doing this right as I couldn't find a lot of data on the use of SAVE ARRAY TO DATAFILE. I'm relatively new to working with arrays as all my previous DBP stuff has been incredibly simple but now I'd like to work with files and thought this would be a god start.

Anyway, on to the problem. I have my code laid out as below.
Note: I'm aware SAVE ARRAY doesn't allow me to save the data as I want it, so I'm trying SAVE ARRAY TO DATAFILE.



Now once I launch my program it simply crashes out (a Windows style, want to report error one). I've tried adding some debug stuff in there such as;



Still just crashes without doing anything. So, where am I going wrong? Is simply not possible to write the type of data I'm trying to or am I using the command wrong?

On a side note is possible to do something like this



and then load that file in a way to get my data like so ready for use?

GIDustin
16
Years of Service
User Offline
Joined: 30th May 2008
Location:
Posted: 28th Jun 2010 02:40
Ran your code and the first time it crashed. It was looking for a "data" folder that I didnt have. So I made a "data" folder and then it ran just fine.

Not sure what to tell you there...

As for your second question, you can do whatever you want really, but loading a CSV file is going to take a few more commands than using the Matrix save array method.

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 28th Jun 2010 15:12
You should use the function version of the OPEN DATAFILE TO XXXX commands so that you can test more easily when the command fails:


Also, because they are datafiles, you can write array after array to the file - you are not limited to 1 array like the standard DBPro commands.

I would also suggest writing a simple program that will take your CSV file and write it to a datafile in array form too - that gives you an easy method of editing your data (using notepad, or even a spreadsheet program), but then 'compiles' that file into a fast loading method in your game.

Take a look at my SPLIT CSV STRING and associated commands:


Talairina
18
Years of Service
User Offline
Joined: 9th Jan 2006
Location: United Kingdom
Posted: 28th Jun 2010 20:14
Still crashing. I can't figure this out as to why. IanM could you also try running the code to see how it reacts for you?

I'm wondering if it's even related to the code at all or something to do with write permissions problems within my windows environment.

I like the sound of the CSV idea, that sounds perfect for what I want. Is there a tutorial or some code segments of CSV usage I could read through to see how to use the commands?
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 29th Jun 2010 01:52
It works perfectly fine as long as there's a data directory present that the monsters.dat can be created in.

You can add a MAKE DIRECTORY command to ensure that the directory exists (it doesn't appear to fail if the directory already exists either, so it's safe):


I've also attached a working example of a csv->saved array program. I created the csv file using an openoffice spreadsheet.

Attachments

Login to view attachments
Talairina
18
Years of Service
User Offline
Joined: 9th Jan 2006
Location: United Kingdom
Posted: 30th Jun 2010 15:37
That code works perfectly and has helped me narrow down what's causing the crash. Thanks for the example IanM, now I understand more on how using csv's work and how bloody handy they are.



That is what is causing it. Commented out the code works brilliantly, naturally not saving the array of cause but the data within it is still usable. Uncommented the program crashes out.

I can't figure out why that happens. It creates the file just fine with the code below.



Yet it seems to have the problem of writing to the file.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 1st Jul 2010 15:00
Well, I guess it's time you posted your latest code ... in fact, do as I did - clean up your project folder (remove any temporary files) zip it up, then either post it here or send it to me via email and I'll see if it's your code/directory structure causing the problem.

Talairina
18
Years of Service
User Offline
Joined: 9th Jan 2006
Location: United Kingdom
Posted: 21st Jul 2010 21:29
Sorry to drag this up 20 days later but I thought I should let you know that it was the Directory. Although I'm not sure what caused it. (Even a reinstall of the program in a different location wouldn't fix it) a format and reinstall of the OS and software did.

Now I just need to figure out a way to have the code read the array from the datafile instead of the .cvs after it was saved. This way I can code in a check to see if the .cvs file is there, and if it is, write its contents to the datafile and load the datafile, else just load the datafile. This would allow me to update the contents when ever I need to but release the game without the modifiable .cvs files so player's simply cant change the stats of various things.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 21st Jul 2010 22:21
Quote: "a format and reinstall of the OS and software did"

Vista? I've had that problem myself in the past and had to create a 'true' admin account to fix it.

Anyway, my advice is to do something similar to what I've done - have your main program load the array, and have a separate program that 'compiles' the CSV into the array format.

You can then, if you wish, provide the CSV files and the 'compiler' to your users if you want to allow them to mod the data.

Talairina
18
Years of Service
User Offline
Joined: 9th Jan 2006
Location: United Kingdom
Posted: 24th Jul 2010 14:32
Quote: "
Vista? I've had that problem myself in the past and had to create a 'true' admin account to fix it.

Anyway, my advice is to do something similar to what I've done - have your main program load the array, and have a separate program that 'compiles' the CSV into the array format.

You can then, if you wish, provide the CSV files and the 'compiler' to your users if you want to allow them to mod the data.
"


OS: XP Sp3

The 'modding tools' was the plan =) Your example's really helped me figure this out, thank you so much IanM. I now have my 'Mod Tool' program for converting the csv files in to dat for use with the main game itself. Thank you so much =)

Login to post a reply

Server time is: 2024-11-24 14:07:18
Your offset time is: 2024-11-24 14:07:18