News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

help with parsing strings

Started by clover, August 15, 2012, 05:04:07 PM

Previous topic - Next topic

clover

how can i type something and have playbasic do it. for example if you run this code and type circle it will draw a circle

PlayBASIC Code: [Select]
  #include "input"
myinput=newinput(0,300,"")
do
cls
input(myinput)
mystring$=getinputtext(myinput)
if instring(mystring$,"circle",0,1)
circle x,y,20,1
endif
sync
loop



but how can i get pb to draw a circle at any position i type in

kevin

#1
  You'd have to pick through the string 'parsing' it.  So when you find the 'Circle' characters in a string, you'd then look at the characters following that word.  Split those characters apart and 'convert' the string fragments into numeric equivalents.    

 The best way is to tokenize the code string fragment into a numeric form and evaluate from that.


  Simple Formula Evaluation / Compilers (login required)

  Tokenize String - Simple String Lexer

clover

thanks kevin that's exactly what i needed to know

kevin


clover

i want to type what i want the program to do while it's runing

kevin


for a debugger, a game mechanic.. what ?