Shop OBEX P1 Docs P2 Docs Learn Events
store multiple characters in quotes — Parallax Forums

store multiple characters in quotes

kingbpkingbp Posts: 22
edited 2012-01-25 20:59 in General Discussion
Is it possible to store multiple chracters in quotes, I noticed that in pbasic you can store a single chracter in a quote like so turns = "S", but when i try to store multiple characters in quotes I get an error is their a way that I can do something like this turns = "LUL" without getting an error.

Comments

  • xanatosxanatos Posts: 1,120
    edited 2012-01-25 19:50
    Depends what you have your turns var set to. Byte will store one letter. Word, two. You're looking for a string var, or an array of bytes equal to your longest string... You can find all the details in the stamp manual.

    Dave
  • Mike GreenMike Green Posts: 23,101
    edited 2012-01-25 20:59
    You could store two characters in a word, but 3 characters takes 24 bits. There's no way you could directly do something like turns = "LUL". If turns happens to be a 3 byte array, you could do something like

    if (turns(0) = "L") and (turns(1) = "U") and (turns(2) = "L") then

    You could use DATA and READ statements to do something like this which would be called by GOSUB Search. It returns with i set to TableSize if the command isn't found or the index of the command (starting at zero) in the table if it's found.
    TableSize   CON   2
    CmdTable:  DATA  "LUL", "RUL"
    
    Search:  FOR i = 0 TO TableSize-1
       FOR j = 0 to 2
          READ CmdTable+i*3+j,temp
          if temp <> turns(j) THEN GOTO TryNext
       NEXT j
       RETURN
    TryNext: NEXT i
       i = TableSize
       RETURN
    
Sign In or Register to comment.