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 / How do I save Arrays to external .txt files, and load them in when program used @ a different time?

Author
Message
JonoPike
21
Years of Service
User Offline
Joined: 5th Dec 2002
Location:
Posted: 9th Jun 2003 01:43
I'm using darkBASIC 1.13 (not DBPro, but this is the only DarkBASIC forum I could find).

Anyway, I have made an array:
CharStats$="CharaName$,CharaColour#,Level#,RedStat#,OrangeStat#,YellowStat#,GreenStat#,BlueStat#,PurpleStat#"

What I want to do is be able to save this array into a .txt file in the same directory the program is in. However, also a check so that if an array with that number already exists in the file, then an array with the next number is tried, until a new array is created where no data already exists.

Also, I want to know how to make a screen that displays each array (as in a 'display all pre-made characters'). How is this done?

Thanks a helluva lot for your help =D.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 9th Jun 2003 22:53
Start with

SAVE ARRAY()
LOAD ARRAY()

Thanks in advance.
All the Best,
StevieVee
=C=
21
Years of Service
User Offline
Joined: 8th May 2003
Location: United Kingdom
Posted: 10th Jun 2003 00:10
What you need to have in mind is that an array is defined in dimensions. Also each element of the array must be of the same type, i.e. Intiger or String etc.

so what you describe is an array probably like this:

MyCharacter(10) where 10 is the number of items you want to store, still we are talking about one dimension here.
so it might be like:

MyCharacter(1) = character_id (this points to another array e.g. Names$(character_id) = "John the Baptist")

MyCharacter(2) = Class_id (this points to array Classes$(class_id) = Prophet)

MyCharacter(3) = Level (this can be just a number say 10)

MyCharacter(4) = Experience (this again might be 10340)

MyCharacter(5) = GoldCoins (this again could be a number e.g. 120)

etc etc. Each item in this array is either an id where it can be crossed referenced with another array to make sense or a number which can be stored as is.

So in your code you might have

If myCharacter(4) > 10000 then KillMonster

or

print "A poor bloke sees you and says," + Name$(MyCharacter(1)) + " old boy! How are you!"

which on screen it will look like:

A poor bloke sees you and says, John the Baptist old boy! How are you!

---
So arrays, love them or hate them, they need a bit work, they are fab because you can save them and load them. I suggest you play around a bit with arrays, make a small programm that helps you create a few arrays that work together and then save them with meaningfull names, so that you have prefabricated data structures in your game.

-------------------------------
Pointy birds, Oh pointy pointy
Anoint my head, Anointy 'nointy
JonoPike
21
Years of Service
User Offline
Joined: 5th Dec 2002
Location:
Posted: 10th Jun 2003 00:54
Thanks a ton man!

Login to post a reply

Server time is: 2024-11-24 16:21:23
Your offset time is: 2024-11-24 16:21:23