Page 2 of 2
Posted: Sun Mar 28, 2004 5:50 pm
by User Mike
Thanks very much TheFool.
BalrogSoft has been kind enough to point me towards learning variables, and has released ScriptVM for me and others to get ideas from.
Thanks for posting your source for your compiler. I've adapted a few things that'll help make my compiler(or rather interpreter), much more efficient.

Posted: Sun Mar 28, 2004 7:46 pm
by thefool
hi!
made a little modification on my program.:
here is the new one. try compile it to an exe:
Code: Select all
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.
Put this in the file;:
Code: Select all
print test
;This is a comment!
print Yes! It works..
let daniel=hejsa
print Done
pause 1000
clearconsole 1
print yehaa
pause 2000
Posted: Sun Mar 28, 2004 8:37 pm
by User Mike
@thefool
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.

Posted: Sun Mar 28, 2004 11:00 pm
by RJP Computing
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.
Code: Select all
Dim varlist.s( 100,100 )
OpenConsole()
OpenFile( 1, "script.txt" )
lncnt = 0
Repeat
lncnt = lncnt + 1
line.s = ReadString()
commandpos = FindString( line, " ", 1 )
command.s = Trim( Left( line, commandpos ) )
tmp = Len( line ) - commandpos
commandtodo.s = Right( line, tmp)
;*************
Select command.s
Case ""
Case "print"
PrintN( commandtodo )
Case ";"
Case "let"
varpos = FindString( line, "=", 1 )
varname.s = Trim( RemoveString( Left( line, varpos - 1 ), "let", 1 ) )
vartmp = Len( line ) - varpos
varval.s = Right( line, vartmp )
Debug "Variable '" + varname + "' will be assigned to '" + varval + "'"
Case "pause"
Delay( Val( commandtodo ) )
Case "clearconsole"
ClearConsole()
Default
PrintN( "Error in line " + Str( lncnt ) )
Delay( 1000 )
Goto enderr
EndSelect
;*************
Until Eof( 1 )
enderr:
Updated script so that comments work.
Code: Select all
print test
; This is a comment!
print Yes! It works..
let daniel=hejsa
print Done
pause 1000
clearconsole 1
print yehaa
pause 2000
Posted: Sun Mar 28, 2004 11:50 pm
by User Mike
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.

PureScript scripting functions
Posted: Mon Mar 29, 2004 2:36 am
by USCode
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.
Posted: Mon Mar 29, 2004 9:01 am
by thefool
Hi!
@rpj computing: Your new method to "LET" seems interesting. I will test it!
Im happy so many have shown interest in my little code. It was my very first try to make a script intepretter
Posted: Fri Nov 12, 2004 4:26 pm
by NewMan
how will you create a variable daniel and assign a value hejsa to it? or is there any other way of storing them?
Re: PureScript scripting functions
Posted: Thu Aug 04, 2005 10:03 pm
by Shannara
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.
I know this is very old, but I 2nd this!
Posted: Sat Aug 06, 2005 3:15 am
by User Mike
I third this

Posted: Tue Aug 30, 2005 4:32 pm
by Joakim Christiansen
I really want that!

Posted: Tue Aug 30, 2005 7:55 pm
by Joakim Christiansen
I was really inspired by this!
I'll try to make a simple scripting language for use in games.
This is my current work:
Code: Select all
Dim Variable.s(10000)
Global String.s
Global Command.s
Global Argument.s
Procedure cmd_Var()
Value1.s = Variable(Val(Argument))
Pos = FindString(Argument,"#",1)
If Pos > 0
Value2.s = Variable(Val(RemoveString(Argument,Left(Argument,Pos))))
Else
Value2.s = LTrim(StringField(Argument,3," "))
EndIf
Select StringField(Argument,2," ")
Case "=": Variable(Val(Argument)) = Value2
Case "+": Variable(Val(Argument)) = Str( Val(Value1) + Val(Value2) )
Case "-": Variable(Val(Argument)) = Str( Val(Value1) - Val(Value2) )
Case "*": Variable(Val(Argument)) = Str( Val(Value1) * Val(Value2) )
Case "/": Variable(Val(Argument)) = Str( Val(Value1) / Val(Value2) )
EndSelect
EndProcedure
OpenFile(0,"Script.txt")
While Eof(0) = #False
String = ReadString()
Command = StringField(String,1," ")
Argument = LTrim(RemoveString(String,Command))
Select(LCase(Command))
Case "var": cmd_Var()
Case "print"
If FindString(Argument,"#",1)
Print(Variable(Val(RemoveString(Argument,"#"))))
Else
Print(Argument)
EndIf
Case "printn"
If FindString(Argument,"#",1)
PrintN(Variable(Val(RemoveString(Argument,"#"))))
Else
PrintN(Argument)
EndIf
Case "waitkey"
While Inkey()=""
Delay(1)
Wend
Case "openconsole"
OpenConsole()
Case "clearconsole"
ClearConsole()
Case "closeconsole"
CloseConsole()
Case "delay"
Delay(Val(Argument))
EndSelect
Wend
CloseFile(0)
Script:
Code: Select all
OpenConsole
Var 0 = 5
Var 0 * 100
PrintN This is a little stupid script.
Print 5*100 =
Print #0
PrintN
PrintN And it works! :D
WaitKey