TI99 Environment

# POS

Syntax

integer-variable = POS(string1,string2,position)

Description

The POS function returns the position of the first occurrence of string2 in a string1. The search begins at the position specified by position. If no match is found, the function returns a value of zero. This function is the TI99 equivalent of INSTR.

Example Code

    ` ROCK, PAPER, SCISSORS
     RANDOMIZE HITIMER()
     GAMEOVER$ = "N" : PLAYERWINS = 0 : COMPUTERWINS = 0 : CRPS$="RPS"
     DIM ARPS$(3)
     ARPS$(1)="ROCK"
     ARPS$(2)="PAPER"
     ARPS$(3)="SCISSORS"
     REPEAT
        CALL_CLEAR()
        WIN = -1
        DISPLAY_AT(4,1,"ROCK, PAPER, SCISSORS",0)
        DISPLAY_AT(6,1,"R=ROCK, P=PAPER, S=SCISSORS",0)
        PLAYER$=""
        WHILE PLAYER$ = ""
          PLAYER$ = FAST UPPER$(FAST LEFT$(ACCEPT_AT(8,1,"","TYPE R,P, OR S:",0),1))
          PCHOICE = POS(CRPS$,PLAYER$,1)
          IF PCHOICE = 0 THEN PLAYER$ = ""
        ENDWHILE
        CALL_CLEAR()
        PCHOICE$ = ARPS$(PCHOICE)
        COMPUTER$ = MID$(CRPS$,RND(2)+ 1,1)
        CCHOICE$ = ARPS$(POS(CRPS$,COMPUTER$,1))
        DISPLAY_AT(4,1,"YOU CHOSE:" + PCHOICE$,0)
        DISPLAY_AT(6,1,"COMPUTER CHOSE:" + CCHOICE$,0)
        IF PLAYER$ = "R" AND COMPUTER$ = "S" THEN WIN = 1
        IF PLAYER$ = "P" AND COMPUTER$ = "R" THEN WIN = 1
        IF PLAYER$ = "S" AND COMPUTER$ = "P" THEN WIN = 1
        IF PLAYER$ = "R" AND COMPUTER$ = "P" THEN WIN = 0
        IF PLAYER$ = "P" AND COMPUTER$ = "S" THEN WIN = 0
        IF PLAYER$ = "S" AND COMPUTER$ = "R" THEN WIN = 0
        IF WIN = 1
          DISPLAY_AT(10,1,PCHOICE$+ " BEATS " + CCHOICE$,0)
          DISPLAY_AT(11,1,"YOU WIN",0)
          INC PLAYERWINS
        ENDIF
        IF WIN = 0
          DISPLAY_AT(10,1,CCHOICE$+ " BEATS " + PCHOICE$,0)
          DISPLAY_AT(11,1,"COMPUTER WINS",0)
          INC COMPUTERWINS
        ENDIF
        IF WIN = -1
          DISPLAY_AT(10,1,"IT'S A TIE",0)
        ENDIF
        DISPLAY_AT(14,1,"SCORE:",0)
        DISPLAY_AT(15,1,"YOU:" + STR$(PLAYERWINS),0)
        DISPLAY_AT(16,1,"COMPUTER:" + STR$(COMPUTERWINS),0)
        DISPLAY_AT(18,1,"ONE MORE? (Y/N)",0)
        ONEMORE$ = TIWAITYN()
        IF ONEMORE$ = "N" THEN GAMEOVER$ = "Y"
     UNTIL GAMEOVER$ = "Y"

Go back to ...

TI99E Commands Menu
Main Menu

Copyright © Carlos Santiago Lebron - TI99 Environment 2020