Hi all, I have been playing with making a scripting system for RPG style dialog.
basicly I use a text file and determine the purpose of a line by its starting character
from inside the program, every time a selection is made, the file is closed and reopened so that any changes to the text file will be added into the mix.
this doesn't happen however, it keeps reading the original version of the txt file until the program is reloaded and then it updates.
here is the code
`If debug is set to 1 then the choice target will be printed to screen
debug = 0
dim choice$(100)
gosub screen
do
`get user input and select apropriate routine.
repeat
print
ink rgb(255,255,0)
input "select an option: ",choicer
until choicer >0 and choicer <choice
gosub screen
loop
end
screen:
choice = 1
cls
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
`close file and reopen to refresh data in case of file change.
`This is not working as expected at the moment
close file 1
open to read 1,"media\script.txt"
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
`find either the first routine or the target routine
`depending on whether the program is on its first run or not
if choice$(choicer) = ""
repeat
read string 1,script_name$
until left$(script_name$,1) = "["
else
repeat
read string 1,script_name$
until first token$(script_name$,"[") = choice$(choicer)
endif
`start accessing data.
`firstly is text detected through beginning and ending with (
repeat
read string 1,open$
if left$(open$,1) = "("
ink rgb(255,255,255)
output$ = first token$(open$,"(")
print output$
endif
`next the options are detected through beginning and ending with {
if left$(open$,1) = "{"
output$ = first token$(open$,"{")
ink rgb(0,255,0)
print output$
`at this point the intended target of the option is detected trough beginning and ending with [
skip$ = first token$(open$, "[")
choice$ = next TOKEN$("[")
`save name of target routine into an array, later accessed via variable matching order of choice display
choice$(choice) = choice$
if debug = 1
ink rgb(255,0,0)
print choice$
endif
choice = choice + 1
//print choice$
endif
`detect the end of the routine section - i write the name on the end too just for clarity from either end.
until left$(open$,2) = "[\"
return
and here is the text file it is reading
[intro[
(this is some test text(
(This is a second line of text testing(
((
{1:choose this number for option 1{[number1[
{2:choose this number for option 2{[number2[
[\intro[\
[number1[
(this is number 1 option branch(
((
{1:back{[intro[
{2:move on to a second generation sub-branch{[teir3[
[\number1[\
[number2[
(this is number 2 option branch(
((
{1:back{[intro[
[\number2[
[teir3[
(Teir 3 has more text in it than the other teirs(
(It really doesnt matter how many lines are added(
(It will keep on reading until it hits the option select section(
(this is the last line of text so the next one will load the options(
((
{1:back to the start{[intro[
{2:back to tier 1{[number1[
{3:skip to teir 2{[number2[
[\teir3[
I know your all programmers here but just for the sake of clarity
each character is used as brackets
[ = routine header
[\ = close routine
( = text line
{ = user option followed by name of routine enclosed in [
(project is also attached to post for sake of ease)
can anyone see a reason why the file would not update?
when I alter the txt file, save it and then select a new option which closes and opens the file again, the text has not updated.
Not the end of the world but I would like it to update in real time.
any insight would be greatly appreciated.
kezzla