To use this code, you'll need this very awesome plugin.
Matrix1Util
The idea of the below code would be if the user wanted to make use of some kind of scripting. So you might store a number of optional character classes you read from the main program. However, the code can be used for any kind of 'save/load' operation. It's pretty simple.
`SaveLoad
`main.dba
//By Bryn Price (AKA Seppuku Arts)
`======================
//Create a UDT for the class you'll be using in your
//game code
type job
name as string
magic1 as string
magic2 as string
skill as string
weapon as string
armor as string
endtype
sync on
sync rate 60
//ClassManager.dat
//This is to set the number of classes you'll be creating
//You could have a 'classmanager.dat' and have the value stored there
nOfClasses as integer
nOfClasses = 3
//Declare the class type as an array for the number of classes
//we're going to use
dim class(nOfClasses) as job
//CLASS.DAT
//Declare the variables we'll be using with 'Class[n].dat'.
//These correspond with the User Defined Type
cName as string
cMagic1 as string
cMagic2 as string
cSkill as string
cWeapon as string
cArmor as string
//Check for each 'class'
for n = 1 to nOfClasses
//open the datafile called 'class[n].dat', this will be
//a data file for each 'class' and they will be numbered
open datafile to write 1, "class" + str$(n) + ".dat"
//FOR FILE 1 - Store these variables
if n = 1
cName = "Scholar"
cMagic1 = "Black Magic"
cMagic2 = "White Magic"
cSkill = "Stratagem"
cWeapon = "Staff"
cArmor = "Magic"
endif
//FOR FILE 2 = Store these variables
if n = 2
cName = "Blue Mage"
cMagic1 = "Blue Magic"
cMagic2 = "null"
cSkill = "Blue Mage"
cWeapon = "Sword"
cArmor = "Magic"
endif
//FOR FILE 3 = Store these variables
if n = 3
cName = "Dark Knight"
cMagic1 = "Black Magic"
cMagic2 = "Dark Magic"
cSkill = "Dark Knight"
cWeapon = "Scythe"
cArmor = "Heavy"
endif
//WRITE THE VARIABLES TO THE CURRENT DATAFILE
write datafile string 1, cName
write datafile string 1, cMagic1
write datafile string 1, cMagic2
write datafile string 1, cSkill
write datafile string 1, cWeapon
write datafile string 1, cArmor
//Don't forget to close the datafile once you've finished
close datafile 1
next n
//THIS IS FOR READING THE FILES
//Check for each class
for n = 1 to nOfClasses
//Open Class[n].dat for reading
open datafile to read 1, "class" + str$(n) + ".dat"
//Store the variables inside of the datafile
//back into our strings
cName = datafile string$(1)
cMagic1 = datafile string$(1)
cMagic2 = datafile string$(1)
cSkill = datafile string$(1)
cWeapon = datafile string$(1)
cArmor = datafile string$(1)
//Then record these strings into our UDTs
//(Makes them more manageable IMO)
class(n).name = cName
class(n).magic1 = cMagic1
class(n).magic2 = cMagic2
class(n).skill = cSkill
class(n).weapon = cWeapon
class(n).armor = cArmor
//And close the file
close datafile 1
next n
do
//For creating the gap
//between each line of text
gap = 15
h = 0
//Go through each of the classes
for n = 1 to nOfClasses
//And display their details with a gap in between each
text 0, h, "Class: " + class(n).name
inc h, gap
text 10, h, "Magic Type 1: " + class(n).magic1
inc h, gap
text 10, h, "Magic Type 2 : " + class(n).magic2
inc h, gap
text 10, h, "Skill Type: " + class(n).skill
inc h, gap
text 10, h, "Weapon Type: " + class(n).weapon
inc h, gap
text 10, h, "Armor Type : " + class(n).armor
inc h, gap*2
next n
sync
loop
As it's so simple, here's another piece of code. This will allow you to parse a string and pick out a specific character. Or in this case, use it 2 acquire 2 parts of a command, which you might use in a Text Adventure or even a Monkey Island like game.
This is just one way you might apply the above
string$ = "Go:East"
commandvalue$ = ""
newcommand$ = ""
//From 1 to the total number of characters in 'String$'
for z = 1 to len(string$)
//In English, what this is doing:
//for every character right of ':' assign them to a new variable called 'commandvalue$' (East)
if right$(string$, z) = ":" + right$(string$, z-1) then commandvalue$ = right$(string$, z-1)
//for every character left of ':' assign them to a new variable called 'newcommand$' (Go)
if left$(string$, z) = left$(string$, z-1) + ":" then newcommand$ = left$(string$,z-1)
next z
text 0, 320, "String$ is telling you to '" + newcommand$ + "'"
text 0, 335, "And its value is '" + commandvalue$ + "'"
Of course, this will only handle strings. What you could do, if you wanted to go for the scripting route and use number, is have a second variable to read. So you might have:
command = datafile string$(1)
commandValue = datafile float(1)