Ok, what i have is a string parser...
this is it:
Set Window On
` These two variables set the amount of items and their extent of effects for the array
no_of_items = 3
no_of_variables = 9
`This creates the array
Dim item_data$(no_of_items,no_of_variables)
_weapon_file_read("gamedata.txt",no_of_items,no_of_variables)
End
Function _weapon_file_read(file$,no_of_items,no_of_variables)
`Opens the file to be read from
Open To Read 1,file$
`gamedata.txt is in format:
`[CLASS]
`Class,Name,Cost,amount of Attack,amount of Dexterety,amount of Strength,amount of Life,amount of Mana,amount of Stamina
`This initializes the item number
item_number = 1
Sync On : Sync Rate 0
Do
`Reads an entire line of information from the specified file into the string variable
Read String 1,string$
`Parses to see if its a description tag, a comment tag, a blank line or item data...
If Left$(string$,1) = "[" Or Left$(string$,1) = "`" Or Left$(string$,1) = ""
Read String 1,string$
Else
item$ = string$
Endif
`This initializes the values for the For...Next loop
b = 1
d = 1
If item$ = string$
`Parses to find each part of the info of the item
For a = b To Len(item$)
If Mid$(item$,a) <> ","
item_data$(item_number,d) = item_data$(item_number,d) + Mid$(item$,a)
Else
b = a + 1
inc d
EndIf
Next a
`Prints the info to the screen to get rid of this just delete from line to line
`--------------------------------------------------------------------------------
If item_data$(item_number,2) <> ""
Print "The ";item_data$(item_number,1);" '";item_data$(item_number,2);"';"
Print "Costs ";Val(item_data$(item_number,3));" Gold Pieces;"
Print "Adds An Attack Value Of ";Val(item_data$(item_number,4));";"
Print "Adds A Dexterity Value Of ";Val(item_data$(item_number,5));";"
Print "Adds A Strenght Value Of ";Val(item_data$(item_number,6));";"
Print "Adds A Life Value Of ";Val(item_data$(item_number,7));";"
Print "Adds A Mana Value Of ";Val(item_data$(item_number,8));";"
Print "Adds A Stamina Value Of ";Val(item_data$(item_number,9));";"
Print
Endif
`--------------------------------------------------------------------------------
`Increments the item number so each value goes into a seperate part of the array...
inc item_number
Endif
If item_number > no_of_items Then Close File 1 : Exitfunction
Sync
Loop
EndFunction
And what i want to do it is change it to:
Set Window On
` These two variables set the amount of items and their extent of effects for the array
no_of_types = 4
no_of_items = 3
no_of_variables = 9
`This creates the array
Dim item_data$(no_of_types,no_of_items,no_of_variables)
_weapon_file_read("gamedata.txt",no_of_types,no_of_items,no_of_variables)
End
Function _weapon_file_read(file$,no_of_types,no_of_items,no_of_variables)
`Opens the file to be read from
Open To Read 1,file$
`gamedata.txt is in format:
`[CLASS]
`Class,Name,Cost,amount of Attack,amount of Dexterety,amount of Strength,amount of Life,amount of Mana,amount of Stamina
`This initializes the item number
item_number = 1
Sync On : Sync Rate 0
Do
`Reads an entire line of information from the specified file into the string variable
Read String 1,string$
`Parses to see if its a description tag, a comment tag, a blank line or item data...
If Left$(string$,1) = "[" Or Left$(string$,1) = "`" Or Left$(string$,1) = ""
Read String 1,string$
Else
item$ = string$
Endif
`This initializes the values for the For...Next loop
b = 1
d = 1
If item$ = string$
`Parses to find each part of the info of the item
For a = b To Len(item$)
If Mid$(item$,a) <> ","
item_data$(1,item_number,d) = item_data$(1,item_number,d) + Mid$(item$,a)
Else
b = a + 1
inc d
EndIf
Next a
`Prints the info to the screen to get rid of this just delete from line to line
`--------------------------------------------------------------------------------
If item_data$(1,item_number,2) <> ""
Print "The ";item_data$(1,item_number,1);" '";item_data$(1,item_number,2);"';"
Print "Costs ";Val(item_data$(1,item_number,3));" Gold Pieces;"
Print "Adds An Attack Value Of ";Val(item_data$(1,item_number,4));";"
Print "Adds A Dexterity Value Of ";Val(item_data$(1,item_number,5));";"
Print "Adds A Strenght Value Of ";Val(item_data$(1,item_number,6));";"
Print "Adds A Life Value Of ";Val(item_data$(1,item_number,7));";"
Print "Adds A Mana Value Of ";Val(item_data$(1,item_number,8));";"
Print "Adds A Stamina Value Of ";Val(item_data$(1,item_number,9));";"
Print
Endif
`--------------------------------------------------------------------------------
`Increments the item number so each value goes into a seperate part of the array...
inc item_number
Endif
If item_number > no_of_items Then Close File 1 : Exitfunction
Sync
Loop
EndFunction
Note that i have changed the dimensions of the array, that is the only difference so far.
Now, the reason i didnt this, is so i can change the value of no_of_types byt finding out the lenght of an array.
To explain the array which i need to find the length of;
I am giong to read the file "gamedata.txt" to find out how much information it holds, and then store that data in an array, then read the length of that array and use that to set the length of the array "item_data$(1,2,3)"
In code:
`Just initializing these variables
no_of_types = 0
no_of_items = 0
no_of_variables = 8
Open To Read 1,"gamedata.txt"
Read String 1,string$
`gamedata.txt is in format:
`[CLASS]
`Class,Name,Cost,amount of Attack,amount of Dexterety,amount of Strength,amount of Life,amount of Mana,amount of Stamina
`ENDFILE
Sync On : Sync Rate 0
While string$ <> "ENDFILE"
Select Left$(string$,1)
Case "["
Inc no_of_types
Read String 1,string$
Endcase
Case "`"
Read String 1,string$
Endcase
Case ""
Read String 1,string$
Endcase
Case Default
Inc no_of_items
Read String 1,string$
Endcase
Endselect
Endwhile
Print no_of_types
Print no_of_items
Dim item_data$(no_of_types,no_of_items,no_of_variables)
Sync
Knowladge Belongs To The People...