Get and Use Player Input - KVonGit/zil-stuff GitHub Wiki

"Name the Dog main file"

<VERSION XZIP>
<CONSTANT RELEASEID 1>
<CONSTANT GAME-BANNER "Name the Dog">

<ROUTINE GO ()
  <COPYBUF ,BLANK-NAME-BUF ,DOG-NAME-BUF ,DOG-NAME-SIZE>
  <SETG MODE ,VERBOSE>
  <CRLF><CRLF>
  <V-VERSION>
  <CRLF><CRLF>
  <MOVE ,PLAYER <SETG HERE ,PARK>>
  <V-LOOK>
  <MAIN-LOOP>
>

;"----------------- UNCOMMENT TO ENABLE DEBUGGING COMMANDS --------------------"
;<COMPILATION-FLAG DEBUGGING-VERBS T>
;<COMPILATION-FLAG DEBUG T>

;<SETG EXTRA-FLAGS (NALLBIT)>

<INSERT-FILE "parser">

<SET REDEFINE T>

<ROOM PARK
  (DESC "Lonely Park")
  (IN ROOMS)
  (FDESC "You are in a mostly empty park.")
  (FLAGS LIGHTBIT)
>

<OBJECT DOG
  (DESC "Dog")
  (SDESC "Nameless")
  (ACTION DOG-R)
  (IN PARK)
  (SYNONYM DOG)
  (FLAGS PERSONBIT)
>

<ROUTINE DOG-R ()
  <COND
    (<VERB? EXAMINE>
      <COND
        (<==? <GETP ,DOG ,P?SDESC> "Nameless">
          <TELL "He needs a name." CR>
        )
        (T
          <PRINTBUF ,DOG-NAME-BUF><TELL " loves his new name!" CR>
        )
      >
    )
  >
>

;"### EVERYTHING AFTER THIS LINE IS EITHER FROM NAME.ZIL OR GOOGLE GEMINI ###"

<ROUTINE BUFFERS-ARE-SAME? (BUF STR "AUX" (I 2) (LEN <GETB .BUF 1>))
  <COND (<N=? .LEN <GETB .STR 1>> <RFALSE>)>
  <REPEAT ()
    <COND (<IGRTR? .I <+ .LEN 1>> <RETURN T>)>
    <COND (<N=? <GETB .BUF .I> <NTH .STR <- .I 1>>>
        <RFALSE>)>
    <SET I <+ .I 1>>
    >
>
<CONSTANT NAMEBUF-SIZE 20>
<GLOBAL NAMEBUF <ITABLE NONE 20>>
<CONSTANT DOG-NAME-SIZE 20>
<GLOBAL DOG-NAME-BUF <>>
<GLOBAL BLANK-NAME-BUF <TABLE !\N !\A !\M !\E !\L !\E !\S !\S>>

<SYNTAX NAME OBJECT = V-NAME-OBJECT>

<ROUTINE V-NAME-OBJECT ()
  <TELL "[ENTER A NAME FOR THE DOG. (HE IS A BOY DOG.)]" CR CR ">">
  <READLINE>
  <COPYBUF ,READBUF ,DOG-NAME-BUF ,DOG-NAME-SIZE>
  <PUTP ,DOG ,P?SDESC <CAPITALIZE-FIRST-LETTER ,DOG-NAME-BUF>>
  <TELL "You named the dog \""><PRINTBUF ,DOG-NAME-BUF><TELL "\"." CR>
>

<ROUTINE COPYBUF (SRC DEST MAX)
    <REPEAT ((I 0) (LEN <+ <GETB .SRC 0> 1>))
        <PUTB .DEST .I <GETB .SRC .I>>
        <SET I <+ .I 1>>
        <COND (<EQUAL? .I .MAX .LEN> <RETURN>)>
    >
>

<ROUTINE PRINTBUF (BUF "AUX" (I 2) (LEN <GETB .BUF 1>))
  <REPEAT ()
    <PRINTC <GETB .BUF .I>>
    <COND
      (<L? .I <+ .LEN 1>>
        <SET I <+ .I 1>>
      )
      (ELSE
        <RETURN>
      )
    >
  >
>

<ROUTINE CAPITALIZE-FIRST-LETTER (BUF "AUX" (FC <GETB .BUF 2>))
  ;"Capitalizes the first letter of a buffer if it's a lowercase letter."
  <COND (<AND <G=? .FC !\a> <L=? .FC !\z>>
    <PUTB .BUF 2 <- .FC 32>>
  )>
  <RTRUE>
>
⚠️ **GitHub.com Fallback** ⚠️