1. Parser and question
- Posted by Ferlin <ferlin at SANDW.NET> Dec 28, 1998
- 448 views
Hawke, Just wanted to say THANKS for EUServer, I was working on a Parser for an Text Adventure Game, I had worked a long time on this parser, but the code was getting KLUDGED. I took the approach used with EUserver's cmdlist.ew & basiccmd.ew, loved the approach here. I was able to Re-Write the Parser to some extent in very little time, and adding additional commands is a breeze. So, that was a long way to go to say Thanks and keep up the good work. A question for ALL, This is probably a question that has been asked millions of times, and if so Sorry for asking again, and it may cause my DUH side to show a little, but the problem I seem to be having is figuring out HOW to convert a sequence to an integer? Example. global integer Score Score = 0 . . . procedure AddToScore(sequence Amt) Score = Score + Amt end procedure . . . Person inputs a command > addtoscore 10 program uses Ch = gets(0) program tries to do AddToScore(Ch[2]) what happens here is obvious Euphoria returns an type check failure of course, this makes since since you are trying to add something non numeric to a numeric variable so to speak. + + + Rev. Ferlin Scarborough - Centreville, Alabama - USA
2. Re: Parser and question
- Posted by Ad Rienks <kwibus at DOLFIJN.NL> Dec 29, 1998
- 456 views
Ferlin, 1. When you get a sequence using gets(0), you'll have to parse of the last character of this sequence: Ch = Ch[1..length(Ch)-1] 2. To convert a sequence to an atom, use value(). This returns a sequence, if the first element is GET_SUCCESS, (a 0), then the second element is a valid atom. | Gratis e-mail en meer: http://www.dolfijn.nl/ | Een product van Ilse: http://www.ilse.nl/
3. Re: Parser and question
- Posted by Hawke' <mdeland at GEOCITIES.COM> Dec 28, 1998
- 458 views
Ferlin wrote: > Hawke, > Just wanted to say THANKS for EUServer, I was working > on a Parser for an Text Adventure Game, I had worked a long time > on this parser, but the code was getting KLUDGED. I took the > approach used with EUserver's cmdlist.ew & basiccmd.ew, loved the > approach here. I was able to Re-Write the Parser to some extent > in very little time, and adding additional commands is a breeze. > So, that was a long way to go to say Thanks and keep up the good > work. *blush* thankee! > A question for ALL, > This is probably a question that has been asked millions of > times, and if so Sorry for asking again, and it may cause my DUH side > to show a little, but the problem I seem to be having is figuring out > HOW to convert a sequence to an integer? Example. > global integer Score > Score = 0 > procedure AddToScore(sequence Amt) > Score = Score + Amt > end procedure > Person inputs a command > addtoscore 10 > program uses Ch = gets(0) > program tries to do AddToScore(Ch[2]) the parameter you are passing TO Addtoscore... namely, the ch[2], is NOT a valid number to attempt math upon. you would need to use value() first, upon ch[2], and THEN pass that to Addtoscore. Before you can do THAT tho, the procedure definition would need to be altered to: procedure Addtoscore(atom Amt) --or integer... the 'complete' solution might be: glob seq score score = 0 proc add2score(atom amt) score = score + amt end proc obj junk junk = gets(0) --error check junk[1] here... junk = junk[2] junk = value(junk) --AGAIN:error check junk[1] here... junk = junk[2] add2score(junk) all done :) the technical explanation of what you were doing, and why that was a wee fubar'd :), is: you were attempting to add a 'string' to an integer... that is fine, IF, you assign the result to a 'string'. "mary" + 10 is allowable, IF you assign that result to a seq or obj. hope this helps, and solves your dilemma... Note to all: I'm in the middle of moving, to another state, and as such, I won't be able to reply to emails sent for a while. Normally, I would just let my email buffer on my email server fill up until I could reply to them all. The problem is that my server for email only allows a 2 meg holding space. So, please, delay emails/questions/bug reports/etc... that you might send to me, until I "return". TIA! _/ _/ _/_/_/ _/ _/ _/ _/ _/_/_/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/_/_/ _/_/_/ _/ _/ _/_/ _/_/ _/ _/ _/ _/ _/_/_/ _/ _/ _/ _/ _/ _/ _/ _/_/_/ _/ _/ _/_/_/ ({<=----------------------------------------=>}) ({<=- http://members.xoom.com/Hawkes_Hovel> -=}) ({<=----------------------------------------=>})
4. Re: Parser and question
- Posted by Ferlin <ferlin at SANDW.NET> Dec 29, 1998
- 443 views
Thanks to ALL who contributed with the answer for the addtoscore question, after leaving work and going home, grabbing the Euphoria 2.0 manual and glancing through it, I had solved the problem in less than 5 minutes. Strange how different things look at 2:00am as compared to 7:00pm. Don't know how I overlooked value() the first time the other morning. I would also like to thank everyone that has contributed to the Euphoria Community, things have progressed quite nicely since Ver 1.04 ? I think that was my first one. Later all, + + + Rev. Ferlin Scarborough - Centreville, Alabama - USA