! TryNumber is the only routine which really does any character-level ! parsing, since that's normally left to the Z-machine. ! It takes word number "wordnum" and tries to parse it as an (unsigned) ! decimal number, returning ! ! -1000 if it is not a number ! the number if it has between 1 and 4 digits ! 10000 if it has 5 or more digits. ! ! (The danger of allowing 5 digits is that Z-machine integers are only ! 16 bits long, and anyway this isn't meant to be perfect.) ! ! Using NumberWord, it also catches "one" up to "twenty". ! ! Note that a game can provide a ParseNumber routine which takes priority, ! to enable parsing of odder numbers ("x45y12", say). ! ---------------------------------------------------------------------------- [ TryNumber wordnum i j c num len mul tot d digit; i=wn; wn=wordnum; j=NextWord(); wn=i; j=NumberWord(j); if (j>=1) return j; i=wordnum*4+1; j=parse->i; num=j+buffer; len=parse->(i-1); tot=ParseNumber(num, len); if (tot~=0) return tot; if (len>=4) mul=1000; if (len==3) mul=100; if (len==2) mul=10; if (len==1) mul=1; tot=0; c=0; len=len-1; for (c=0:c<=len:c++) { digit=num->c; if (digit=='0') { d=0; jump digok; } if (digit=='1') { d=1; jump digok; } if (digit=='2') { d=2; jump digok; } if (digit=='3') { d=3; jump digok; } if (digit=='4') { d=4; jump digok; } if (digit=='5') { d=5; jump digok; } if (digit=='6') { d=6; jump digok; } if (digit=='7') { d=7; jump digok; } if (digit=='8') { d=8; jump digok; } if (digit=='9') { d=9; jump digok; } return -1000; .digok; tot=tot+mul*d; mul=mul/10; } if (len>3) tot=10000; return tot; ];