This library isn't a bunch of functions that you put in a script (a text file) which are just loaded in, it's more a tool to help you make those.
Here are the functions (I stole Diggsey's maths parser, muahaha... Thanks
)
`*Functions - Script*
`--------------------
`Setup Scripting Language
function setupZScript()
global zs_comCount as integer
global zs_longString as string
global zs_nLongString as string
endfunction
`Read code from file
function readScript(codeDir$)
lines=getFileLines(codeDir$)
open to read 1,codeDir$
for l=1 to lines
read string 1,temp$
if left$(removeChar(temp$," "),2)<>"//"
zs_longString=zs_longString+temp$
endif
next l
for t=1 to len(zs_longString)
temp$=mid$(zs_longString,t)
if temp$="(" or temp$=")" then onC=1-onC
if onC=0
zs_nLongString=zs_nLongString+removeChar(temp$,chr$(34))
endif
next t
zs_comCount=getTokens(zs_nLongString,";")
onC=0
close file 1
dim zs_command(zs_comCount) as tzsCommand
endfunction
`Get Code Data
function getScriptData()
for c=1 to zs_comCount
zs_command(c).comline=strSect(getToken(zs_nLongString,";",c),1,len(getToken(zs_nLongString,";",c))-1)+"()"
zs_command(c).param=strSect(getToken(zs_longString,";",c),len(zs_command(c).comline),len(getToken(zs_longString,";",c))-1)
for l=1 to len(zs_command(c).param)
temp$=mid$(zs_command(c).param,l)
if temp$=chr$(34) then onC=1-onC
if onC=1
if temp$<>","
nParam$=nParam$+removeChar(temp$,",")
endif
else
nParam$=nParam$+temp$
endif
zs_command(c).pCount=getTokens(nParam$,",")
zs_command(c).temp=nParam$
next l
nParam$=""
dim zs_param(zs_comCount,100) as tzsParam
for p=1 to zs_command(c).pCount
if left$(getToken(zs_command(c).temp,",",p),1)=chr$(34) and right$(getToken(zs_command(c).temp,",",p),1)=chr$(34)
zs_param(c,p).ptype=2
zs_param(c,p).param=getToken(zs_command(c).temp,",",p)
zs_param(c,p).aparam=getToken(zs_command(c).param,",",p)
else
zs_param(c,p).ptype=1
zs_param(c,p).param=str$(equation(getToken("("+zs_command(c).temp+")",",",p)))
endif
next p
next c
endfunction
`Get Command Data
function getCommandCount()
local ct as integer
ct=zs_comCount
endfunction ct
function getCommandLine(l)
local ln as string
ln=zs_command(l).comline
endfunction ln
function getAllParameters(l)
local pr as string
pr=zs_command(l).param
endfunction pr
function getParameter(l,p)
local pr as string
pr=zs_param(l,p).param
endfunction pr
function getParameterCount(l)
local ct as integer
ct=zs_command(l).pCount
endfunction ct
function getParameterType(l,p)
local t as integer
t=zs_param(l,p).ptype
endfunction t
function reGenerateCommand(l)
local com as string
com=removeChar(getCommandLine(l),")")
for p=1 to getParameterCount(l)
com=com+getParameter(l,p)+","
next p
com=left$(com,len(com)-1)+")"
endfunction com
`Functions - String
function getTokens(st$,sp$)
if left$(st$,1)<>sp$ then nst$=sp$+st$
if right$(st$,1)<>sp$ then nst$=nst$+sp$
repeat
inc counter
cur$=mid$(nst$,counter)
if cur$=sp$ then inc splits
until counter>len(nst$)
tokens=splits-1
endfunction tokens
function getToken(st$,sp$,num)
if left$(st$,1)<>sp$ then nst$=sp$+st$
if right$(st$,1)<>sp$ then nst$=nst$+sp$
repeat
inc counter
cur$=mid$(nst$,counter)
if cur$=sp$ then inc splits
until splits=num or counter>len(st$)
repeat
inc counter
cur$=mid$(nst$,counter)
if cur$<>sp$ then token$=token$+cur$
until cur$=sp$ or counter>len(st$)
endfunction token$
function removeChar(st$,ch$)
for l=1 to len(st$)
cur$=mid$(st$,l)
if cur$<>ch$ then mes$=mes$+cur$
next l
endfunction mes$
function strSect(st$,a,b)
local n as string
for l=a to b
n=n+mid$(st$,l)
next l
endfunction n
`Functions - File
function getFileLines(file$)
local lines as integer
open to read 1,file$
repeat
read string 1,null$
inc lines
until file end(1)
close file 1
endfunction lines
`Functions - Math Parsing
function equation(equat$)
for d = 1 to len(equat$)
char$ = mid$(equat$,d)
if char$ = "+"
tot# = dosum(tot#,equat$,d,sumtype)
equat$ = right$(equat$,len(equat$)-d)
d = 0
sumtype = 1
endif
if char$ = "-"
tot# = dosum(tot#,equat$,d,sumtype)
equat$ = right$(equat$,len(equat$)-d)
d = 0
sumtype = 2
endif
if char$ = "*"
tot# = dosum(tot#,equat$,d,sumtype)
equat$ = right$(equat$,len(equat$)-d)
d = 0
sumtype = 3
endif
if char$ = "/"
tot# = dosum(tot#,equat$,d,sumtype)
equat$ = right$(equat$,len(equat$)-d)
d = 0
sumtype = 4
endif
if char$ = "^"
tot# = dosum(tot#,equat$,d,sumtype)
equat$ = right$(equat$,len(equat$)-d)
d = 0
sumtype = 5
endif
if char$ = "("
equat$ = right$(equat$,len(equat$)-d)
if sumtype = 0
tot# = equation(equat$)
else
if sumtype = 1
tot# = tot#+equation(equat$)
else
if sumtype = 2
tot# = tot#-equation(equat$)
else
if sumtype = 3
tot# = tot#*equation(equat$)
else
if sumtype = 4
tot# = tot#/equation(equat$)
else
tot# = tot#^equation(equat$)
endif
endif
endif
endif
endif
sumtype = 0
count = 1
while count <> 0
dec d
nchar$ = left$(equat$,1)
equat$ = right$(equat$,len(equat$)-1)
if nchar$ = "(" then inc count
if nchar$ = ")" then dec count
endwhile
endif
if char$ = ")"
tot# = dosum(tot#,equat$,d,sumtype)
equat$ = right$(equat$,len(equat$)-d)
sumtype = 0
d = 0
exitfunction tot#
endif
next d
endfunction tot#
function dosum(tot#,equat$,d,sumtype)
if sumtype = 0
tot# = tot#+val(left$(equat$,d-1))
else
if sumtype = 1
tot# = tot#+val(left$(equat$,d-1))
else
if sumtype = 2
tot# = tot#-val(left$(equat$,d-1))
else
if sumtype = 3
tot# = tot#*val(left$(equat$,d-1))
else
if sumtype = 4
tot# = tot#/val(left$(equat$,d-1))
else
tot# = tot#^val(left$(equat$,d-1))
endif
endif
endif
endif
endif
endfunction tot#
`Types - Command Data
type tzsCommand
comline as string
param as string
pCount as integer
temp as string
endtype
type tzsParam
ptype as integer
param as string
aparam as string
endtype
So, what you have to do it, you start up the library by calling
startZScript(), then read a script file, by doing
readScript(ScriptName$). You then create the script data, by doing
getScriptData().
Now you're script is ready. You can open up your script file in notepad, or whatever you want, and start writing stuff, like this:
print("Hello World!");
makeBox(1,10,20,50*2);
The commands obviously dont do anything, but you can read them very easily in DBPro. These are the functions to call to get command data:
return integer = getCommandCount()
- Gets number of commands in script file
return string = getCommandLine(command)
- Gets the name of a command, expluding parameters
return string = getAllParameters(command)
- Will return all parameters in one string
return string = getParameter(command,parameter)
- Returns the string for a parameter. If the parameter is a calculation, it will return the calculated number as a string
return integer = getParameterCount(command)
- Gives the number of parameters in a command
return integer = getParameterType(command, parameter)
- Return 1 or 2. If 1, then parameter is a number. If 2, then parameter is a string
return string = reGenerateCommand(command)
- Generates a string that looks like the normal command, but not split up, and with all calculations done.
Ok. So that's good... now what do you do with it? Well, you can use it anyway you like. You can build your own programming language. You could use it for loading player data, map data, or anything. You could make small plugins for your apps, i.e. after it's release, be able to add different types of objects, etc. etc.
Basically, you might find it usefull, might not. I think I will