Dim varlist.s(100,100)
OpenConsole()
OpenFile(1,"script.txt")
lncnt=0
Repeat
lncnt=lncnt+1
line.s=ReadString()
commandpos=FindString(line.s," ",1)
command.s=Trim(Left(line.s,commandpos))
tmp=Len(line.s)-commandpos
commandtodo.s=Right(line.s,tmp)
;*************
Select command.s
Case ""
Case "print"
PrintN(commandtodo.s)
Case ";"
Case "let"
;This creates values with no sense. will look at it!
varpos=FindString(line.s,"=",1)
varname.s=Left(line.s,varpos)
vartmp=Len(line.s)-varpos
varval.s=Right(line.s,varpos)
Debug varval.s
Debug varname.s
Case "pause"
Delay(Val(commandtodo.s))
Case "clearconsole"
ClearConsole()
Default
PrintN("Error in line "+Str(lncnt))
Delay(1000)
Goto enderr
EndSelect
;*************
Until Eof(1)
enderr:
And make a file named "script.txt" in the exe's directory.
Thank you so much for your help. I'm getting closer to having basic variables working with your 'let' statements. This is excellent and I'm really starting to love PureBasic.
Here is a fixed version so that the right values come out after a 'let' statement. This example is great I am going to try to add to this also. I noticed that comments MUST have a space after the ';' because of the way it looks for commands. I am going to see if I can improve the command interpreter first then add more commands.
Yes, in fact, all code needs to have a space or some kind of character behind it to function properly. Any idea on a fix? Perhaps a space character could be added if no other characters are detected.
Right now, I've adapted my interpreter to thefool's code, because it's much more clean.
I wonder how difficult it would be for Fred to implement a scripting feature where the Scripting language would be PureBasic? Seems like he would be able to leverage some of the code (parser, etc.) he has already written? I have little knowledge in this area but it's a thought.
It would be fantastic to be able to give our users the ability to write PureBasic scripts that could call API functions our main applications provided and thus allow some custom application behavior.
As an example, RealBasic has a scripting control that allows the dynamic execution of scripts written in RealBasic at runtime.
USCode wrote:I wonder how difficult it would be for Fred to implement a scripting feature where the Scripting language would be PureBasic? Seems like he would be able to leverage some of the code (parser, etc.) he has already written? I have little knowledge in this area but it's a thought.
It would be fantastic to be able to give our users the ability to write PureBasic scripts that could call API functions our main applications provided and thus allow some custom application behavior.
As an example, RealBasic has a scripting control that allows the dynamic execution of scripts written in RealBasic at runtime.