Here is a little or big script system I made.
The script system allows you too create commands and write scripts in files to parse to help you layout your game and run your game.
Creating a command is simple all you have to do is go to a function called parse_string() which parses a string. In there you are going to put a case/endcase statement between the select/endselect statement if you dont know what those are look in the help file or an existing project with mutliple commands already. For the data of the case statement put the command you will like to make. Once you have done that you will be able to get the parameters that have been taken out of the string in an array called psentences(). You can use those parameters to do what you want. Here is an example
eg.
case "text"
text val(psentences(0)),val(psentences(1)),psentences(2)
endcase
In a script file it will look like this text 0,0,Hello this is a test
Final notes on creating commands- in the case data it can only be one word. The psentences array is a string so you have to use the val() command to make it a value and sometimes the int() command if you need an integer for arrays and such.
I have also created a flag system. The flag system will allow you to run certain parts of your script at certain times. To make a flag in the script since I already made the command for you. You have to use a command called newflag (in the commands list with download). Then it will store commands for later use. To activate a flag when you want you have to use activateflag (also in commands list). You can only set the activation times the engine has or if you make your own using flagcheck. To create the flag in the engine you have to use a function thats called check_flag_data() and put check_flag_data(flagcheck$) in so you can use flagcheck. You can see an example of this within the project for download.
There is also a variable system in place to create your own variables. Variables will have to be created using the var command. You will be able to use a varible in any parameter since it changes a varible name into a varible value before it looks up commands.
Just keeps getting better and better right. I also have a lot of different functions you can use besides the parse_string and parse_file. You can store string words/parameters or just get the one you want with the list of function names in the project download.
store_words()
store_parameters()
get_word(string$,word)
get_parameter(string$,word)
A final note to use this make sure you Intiate the script system using Intiate_scriptsystem()
Try it out with this project and the commands list. See if you can make your own commands.
Script System-
```````````````
`types`````````
```````````````
`vartable
type tvartable
name$ as string
value$ as string
endtype
`activation flag table
type tactivateflag
flagnumber$ as string
activatetime$ as string
endtype
type timgtable
imgnum as integer
paste as byte
xpos as word
ypos as word
endtype
type tobjtable
objnum as word
endtype
function Intiate_scriptsystem()
`````````````````
`arrays``````````
`````````````````
`vartable
dim vartable(-1) as tvartable
`flagtable
dim flagtable(-1) as string
`activeflag table
dim activateflag(-1) as tactivateflag
`image table
dim imgtable(-1) as timgtable
`object table
dim objtable(-1) as tobjtable
`flag data flag
dim flag(0) as byte
dim flagcheck(0) as string
`script directory
dim scriptdir(0) as string
endfunction
`This will parse a file
function parse_file(filename$ as string,temp_file as byte)
`declare everything
temp_string$ as string
`load the file
if file exist(filename$)=1 then open to read temp_file,filename$
`parse file
repeat
read string temp_file,temp_string$
parse_string(temp_string$)
until file end(temp_file)=1
close file temp_file
endfunction
function parse_string(string$ as string)
`see if it is a remark or blank
if left$(string$,2)="" or left$(string$,2)="//" or string$="" then exitfunction
`declare
value$ as string
newstring$ as string
i as integer
temp_dir as string
`set the directory
temp_dir=get dir$()
set dir od(0)
`remove command from new string
newstring$=right$(string$,len(string$)-len(get_word(string$,1))-1)
`store all the words by parameters
store_parameters(newstring$)
`see if there is a varible
check_vartable()
`see if there inputting flag data
if flag(0)=1
if string$="}" then flag(0)=0
input_flagdata(string$)
exitfunction
endif
`select the command
select lower$(get_word(string$,1))
````````````````````````````
`Commands```````````````````
````````````````````````````
`````````````````````````
` General `
`````````````````````````
case "var"
for i=0 to array count(vartable())
`check to see if it is a return value command
if left$(psentences(1),1)="_"
newstring$=""
for x=1 to array count(psentences())-2
newstring$=newstring$+","+psentences(x)
next x
endif
if vartable(i).name$=psentences(0)
vartable(i).value$=psentences(1)
exitfunction
endif
next i
array insert at bottom vartable()
if left$(psentences(0),1)=" "
vartable(array count(vartable())).name$=psentences(0)
else
vartable(array count(vartable())).name$=psentences(0)
endif
if left$(psentences(1),1)=" "
vartable(array count(vartable())).value$=psentences(0)
else
vartable(array count(vartable())).value$=psentences(1)
endif
endcase
case "newflag"
flag(0)=1
array insert at bottom flagtable()
flagtable(array count(flagtable()))=psentences(0)
endcase
case "activateflag"
`make room in table
array insert at bottom activateflag()
`store the flag number
activateflag(array count(activateflag())).flagnumber$=psentences(0)
`store the activation time
activateflag(array count(activateflag())).activatetime$=psentences(1)
endcase
case "flagcheck"
flagcheck(0)=psentences(0)
endcase
case "scriptdir"
scriptdir(0)=psentences(0)
endcase
case "setdisplaymode"
set display mode int(val(psentences(0))),int(val(psentences(1))),int(val(psentences(2)))
endcase
case "syncon"
sync on
endcase
case "syncrate"
sync rate int(val(psentences(0)))
endcase
case "sync"
sync
endcase
case "cls"
cls
endcase
case "end"
end
endcase
case "text"
text int(val(psentences(0))),int(val(psentences(1))),psentences(2)
endcase
endselect
`reset directory
set dir temp_dir
endfunction
function store_parameters(string$ as string)
`if the array exist then delete it
if array index valid(psentences())=1 then undim psentences()
`make an array
dim psentences(words(string$)-1) as string
`store all the words in the array
for i=1 to parameters(string$)
`store the word starting from 0
psentences(i-1)=get_parameter(string$,i)
next i
endfunction
function get_parameter(string$ as string,w as byte)
`declare everything
i as byte
_w as byte
`start from the first character in the string
i=1
`first fix the string by removing a space if it is near another space or comma so it wont messup the function
for i=0 to len(string$)
`see if the old char is a space or a comma and the new char is a space or comma
if char$="," or char$=" "
if mid$(string$,i)=" " or mid$(string$,i)="," then string$=left$(string$,i-1)+right$(string$,len(string$)-i)
endif
`store it
char$=mid$(string$,i)
next i
`add an extra space to the begining so it wont chop off the first part of the word
string$=","+string$
`go to the part of the string they want
for i=1 to len(string$)
`if there is a space or comma tell the function
if mid$(string$,i)="," then inc _w
`see if that is the word they want if it is make a new string from it and get out of the loop
if w=_w then string$=right$(string$,len(string$)-i) : i=len(string$)
next i
`go through the word until it hits a space or comma or the end of the string
for i=1 to len(string$)
`check the character
if mid$(string$,i)="," then string$=left$(string$,i-1) : exitfunction string$
next i
endfunction string$
function store_words(string$ as string)
`if the array exist then delete it
if array index valid(psentences())=1 then undim psentences()
`make an array
dim psentences(words(string$)) as string
`store all the words in the array
for i=0 to words(string$)
`store the word
psentences(i)=get_word(string$,i)
next i
endfunction
function get_word(string$ as string,w as byte)
`declare everything
i as byte
_w as byte
`start from the first character in the string
i=1
`first fix the string by removing a space if it is near another space or comma so it wont messup the function
for i=0 to len(string$)
`see if the old char is a space or a comma and the new char is a space or comma
if char$="," or char$=" "
if mid$(string$,i)=" " or mid$(string$,i)="," then string$=left$(string$,i-1)+right$(string$,len(string$)-i)
endif
`store it
char$=mid$(string$,i)
next i
`add an extra space to the begining so it wont chop off the first part of the word
string$=" "+string$
`go to the part of the string they want
for i=1 to len(string$)
`if there is a space or comma tell the function
if mid$(string$,i)=" " or mid$(string$,i)="," then inc _w
`see if that is the word they want if it is make a new string from it and get out of the loop
if w=_w then string$=right$(string$,len(string$)-i) : i=len(string$)
next i
`go through the word until it hits a space or comma or the end of the string
for i=1 to len(string$)
`check the character
if mid$(string$,i)="," or mid$(string$,i)=" " then string$=left$(string$,i-1) : exitfunction string$
next i
endfunction string$
function parameters(string$ as string)
`declare everything
i as byte
w as byte
`start from the first character in the string
i=1
`first fix the string by removing a space if it is near another space or comma so it wont messup the function
for i=0 to len(string$)
`see if the old char is a space or a comma and the new char is a space or comma
if char$="," or char$=" "
if mid$(string$,i)=" " or mid$(string$,i)="," then string$=left$(string$,i-1)+right$(string$,len(string$)-i)
endif
`store it
char$=mid$(string$,i)
next i
`start it from the first word
w=1
`go through to find all the commas or spaces to find words
for i=1 to len(string$)
if mid$(string$,i)="," then inc w
next i
endfunction w
function words(string$ as string)
`declare everything
i as byte
w as byte
`start from the first character in the string
i=1
`first fix the string by removing a space if it is near another space or comma so it wont messup the function
for i=0 to len(string$)
`see if the old char is a space or a comma and the new char is a space or comma
if char$="," or char$=" "
if mid$(string$,i)=" " or mid$(string$,i)="," then string$=left$(string$,i-1)+right$(string$,len(string$)-i)
endif
`store it
char$=mid$(string$,i)
next i
`start it from the first word
w=1
`go through to find all the commas or spaces to find words
for i=1 to len(string$)
if mid$(string$,i)=" " or mid$(string$,i)="," then inc w
next i
endfunction w
function check_vartable()
`run a loop through all parameters
for i=0 to array count(psentences())
`see if the parameter is a varible
for z=0 to array count(vartable())
if vartable(z).name$=psentences(i) then psentences(i)=vartable(z).value$
next z
next i
endfunction
flag data -
function input_flagdata(string$ as string)
`add the command
array insert at bottom flagtable()
flagtable(array count(flagtable()))=string$
`end flag if called
if string$="}" then flag=0
endfunction
function check_flag_data(activationtime$)
for x=0 to array count(activateflag())
if activateflag(x).activatetime$=activationtime$
`find matching flag data
for y=0 to array count(flagtable())
if flagtable(y)=activateflag(x).flagnumber$ and temp_var=0 then temp_var=1
if temp_var=1
`parse the string
parse_string(flagtable(y))
`see if it is at the end
if flagtable(y)="}" then exitfunction
endif
next y
endif
next x
endfunction
function control_flags()
check_flag_data("scancode_"+str$(scancode()))
check_flag_data(flagcheck(0))
endfunction
Example-
sync on
sync rate 60
dim od(0) as string
od(0)=get dir$()
Intiate_scriptsystem()
do
parse_string("text 0,0,Hello World")
parse_string("text 0,20,Push W to close program")
parse_string("newflag 1")
parse_string("end")
parse_string("}")
parse_string("activateflag 1,scancode_17")
control_flags()
sync
loop
```````````````
`types`````````
```````````````
`vartable
type tvartable
name$ as string
value$ as string
endtype
`activation flag table
type tactivateflag
flagnumber$ as string
activatetime$ as string
endtype
type timgtable
imgnum as integer
paste as byte
xpos as word
ypos as word
endtype
type tobjtable
objnum as word
endtype
function Intiate_scriptsystem()
`````````````````
`arrays``````````
`````````````````
`vartable
dim vartable(-1) as tvartable
`flagtable
dim flagtable(-1) as string
`activeflag table
dim activateflag(-1) as tactivateflag
`image table
dim imgtable(-1) as timgtable
`object table
dim objtable(-1) as tobjtable
`flag data flag
dim flag(0) as byte
dim flagcheck(0) as string
`script directory
dim scriptdir(0) as string
endfunction
`This will parse a file
function parse_file(filename$ as string,temp_file as byte)
`declare everything
temp_string$ as string
`load the file
if file exist(filename$)=1 then open to read temp_file,filename$
`parse file
repeat
read string temp_file,temp_string$
parse_string(temp_string$)
until file end(temp_file)=1
close file temp_file
endfunction
function parse_string(string$ as string)
`see if it is a remark or blank
if left$(string$,2)="\" or left$(string$,2)="//" or string$="" then exitfunction
`declare
value$ as string
newstring$ as string
i as integer
temp_dir as string
`set the directory
temp_dir=get dir$()
set dir od(0)
`remove command from new string
newstring$=right$(string$,len(string$)-len(get_word(string$,1))-1)
`store all the words by parameters
store_parameters(newstring$)
`see if there is a varible
check_vartable()
`see if there inputting flag data
if flag(0)=1
if string$="}" then flag(0)=0
input_flagdata(string$)
exitfunction
endif
`select the command
select lower$(get_word(string$,1))
````````````````````````````
`Commands```````````````````
````````````````````````````
`````````````````````````
` General `
`````````````````````````
case "var"
for i=0 to array count(vartable())
`check to see if it is a return value command
if left$(psentences(1),1)="_"
newstring$=""
for x=1 to array count(psentences())-2
newstring$=newstring$+","+psentences(x)
next x
endif
if vartable(i).name$=psentences(0)
vartable(i).value$=psentences(1)
exitfunction
endif
next i
array insert at bottom vartable()
if left$(psentences(0),1)=" "
vartable(array count(vartable())).name$=psentences(0)
else
vartable(array count(vartable())).name$=psentences(0)
endif
if left$(psentences(1),1)=" "
vartable(array count(vartable())).value$=psentences(0)
else
vartable(array count(vartable())).value$=psentences(1)
endif
endcase
case "newflag"
flag(0)=1
array insert at bottom flagtable()
flagtable(array count(flagtable()))=psentences(0)
endcase
case "activateflag"
`make room in table
array insert at bottom activateflag()
`store the flag number
activateflag(array count(activateflag())).flagnumber$=psentences(0)
`store the activation time
activateflag(array count(activateflag())).activatetime$=psentences(1)
endcase
case "flagcheck"
flagcheck(0)=psentences(0)
endcase
case "scriptdir"
scriptdir(0)=psentences(0)
endcase
case "setdisplaymode"
set display mode int(val(psentences(0))),int(val(psentences(1))),int(val(psentences(2)))
endcase
case "syncon"
sync on
endcase
case "syncrate"
sync rate int(val(psentences(0)))
endcase
case "sync"
sync
endcase
case "cls"
cls
endcase
case "end"
end
endcase
case "text"
text int(val(psentences(0))),int(val(psentences(1))),psentences(2)
endcase
endselect
`reset directory
set dir temp_dir
endfunction
function store_parameters(string$ as string)
`if the array exist then delete it
if array index valid(psentences())=1 then undim psentences()
`make an array
dim psentences(words(string$)-1) as string
`store all the words in the array
for i=1 to parameters(string$)
`store the word starting from 0
psentences(i-1)=get_parameter(string$,i)
next i
endfunction
function get_parameter(string$ as string,w as byte)
`declare everything
i as byte
_w as byte
`start from the first character in the string
i=1
`first fix the string by removing a space if it is near another space or comma so it wont messup the function
for i=0 to len(string$)
`see if the old char is a space or a comma and the new char is a space or comma
if char$="," or char$=" "
if mid$(string$,i)=" " or mid$(string$,i)="," then string$=left$(string$,i-1)+right$(string$,len(string$)-i)
endif
`store it
char$=mid$(string$,i)
next i
`add an extra space to the begining so it wont chop off the first part of the word
string$=","+string$
`go to the part of the string they want
for i=1 to len(string$)
`if there is a space or comma tell the function
if mid$(string$,i)="," then inc _w
`see if that is the word they want if it is make a new string from it and get out of the loop
if w=_w then string$=right$(string$,len(string$)-i) : i=len(string$)
next i
`go through the word until it hits a space or comma or the end of the string
for i=1 to len(string$)
`check the character
if mid$(string$,i)="," then string$=left$(string$,i-1) : exitfunction string$
next i
endfunction string$
function store_words(string$ as string)
`if the array exist then delete it
if array index valid(psentences())=1 then undim psentences()
`make an array
dim psentences(words(string$)) as string
`store all the words in the array
for i=0 to words(string$)
`store the word
psentences(i)=get_word(string$,i)
next i
endfunction
function get_word(string$ as string,w as byte)
`declare everything
i as byte
_w as byte
`start from the first character in the string
i=1
`first fix the string by removing a space if it is near another space or comma so it wont messup the function
for i=0 to len(string$)
`see if the old char is a space or a comma and the new char is a space or comma
if char$="," or char$=" "
if mid$(string$,i)=" " or mid$(string$,i)="," then string$=left$(string$,i-1)+right$(string$,len(string$)-i)
endif
`store it
char$=mid$(string$,i)
next i
`add an extra space to the begining so it wont chop off the first part of the word
string$=" "+string$
`go to the part of the string they want
for i=1 to len(string$)
`if there is a space or comma tell the function
if mid$(string$,i)=" " or mid$(string$,i)="," then inc _w
`see if that is the word they want if it is make a new string from it and get out of the loop
if w=_w then string$=right$(string$,len(string$)-i) : i=len(string$)
next i
`go through the word until it hits a space or comma or the end of the string
for i=1 to len(string$)
`check the character
if mid$(string$,i)="," or mid$(string$,i)=" " then string$=left$(string$,i-1) : exitfunction string$
next i
endfunction string$
function parameters(string$ as string)
`declare everything
i as byte
w as byte
`start from the first character in the string
i=1
`first fix the string by removing a space if it is near another space or comma so it wont messup the function
for i=0 to len(string$)
`see if the old char is a space or a comma and the new char is a space or comma
if char$="," or char$=" "
if mid$(string$,i)=" " or mid$(string$,i)="," then string$=left$(string$,i-1)+right$(string$,len(string$)-i)
endif
`store it
char$=mid$(string$,i)
next i
`start it from the first word
w=1
`go through to find all the commas or spaces to find words
for i=1 to len(string$)
if mid$(string$,i)="," then inc w
next i
endfunction w
function words(string$ as string)
`declare everything
i as byte
w as byte
`start from the first character in the string
i=1
`first fix the string by removing a space if it is near another space or comma so it wont messup the function
for i=0 to len(string$)
`see if the old char is a space or a comma and the new char is a space or comma
if char$="," or char$=" "
if mid$(string$,i)=" " or mid$(string$,i)="," then string$=left$(string$,i-1)+right$(string$,len(string$)-i)
endif
`store it
char$=mid$(string$,i)
next i
`start it from the first word
w=1
`go through to find all the commas or spaces to find words
for i=1 to len(string$)
if mid$(string$,i)=" " or mid$(string$,i)="," then inc w
next i
endfunction w
function check_vartable()
`run a loop through all parameters
for i=0 to array count(psentences())
`see if the parameter is a varible
for z=0 to array count(vartable())
if vartable(z).name$=psentences(i) then psentences(i)=vartable(z).value$
next z
next i
endfunction
function input_flagdata(string$ as string)
`add the command
array insert at bottom flagtable()
flagtable(array count(flagtable()))=string$
`end flag if called
if string$="}" then flag=0
endfunction
function check_flag_data(activationtime$)
for x=0 to array count(activateflag())
if activateflag(x).activatetime$=activationtime$
`find matching flag data
for y=0 to array count(flagtable())
if flagtable(y)=activateflag(x).flagnumber$ and temp_var=0 then temp_var=1
if temp_var=1
`parse the string
parse_string(flagtable(y))
`see if it is at the end
if flagtable(y)="}" then exitfunction
endif
next y
endif
next x
endfunction
function control_flags()
check_flag_data("scancode_"+str$(scancode()))
check_flag_data(flagcheck(0))
endfunction
Working on Boxed for NVIDIA compo. Check it out