How would I match these things to set variables?

Posted by Rivius on Wed 29 Sep 2010 11:39 PM — 5 posts, 24,093 views.

#0
My prompt looks like this (the whole line):

3670h, 2460m, 2820e, 10p, 15882en, 10600w elrx-

But I'm most concerned with the final part of it that says
elrx-

Now this part shows me various balances and stats. For example e tells me about me equilibrium, l tells me if my left arm is on balance and r tells me if my right arm is on balance.

Also, that last part can have more things at the end of it, depending on things I do, like eating a "kafe bean" might turn this into

elrxk-


Now to the question. I want to keep track of when the e,l,r and x parts are gone. Any of them can be gone individually at any time. When it does I want to set a variable to 0. And then I want to set it to 1 when it comes back.

[to illustrate what I mean, let's say I equilibrium is gone, it would be lrx- until it comes back and then it is elrx again.]

How would I go about doing this?
Amended on Wed 29 Sep 2010 11:54 PM by Rivius
Netherlands #1
I am a bit short on time, and rather not spend the time chewing your entire problem out when a few weeks ago, I tackled the same problem for someone with a similar issue.

Have a look at this thread: http://www.gammon.com.au/forum/?id=10619&page=999

Alternatively, look around for the word 'prompt' on these forums. This issue comes past so often that it really is only a matter of applying the answers to fit your specific situation.
#2
Alright! Thanks for that. I used that knowledge and then found out I actually had a nice trigger already set up in my system that allows me to take advantage of that.


EDIT (with the below post's suggestions)
http://pastebin.com/PbwNZZNu

You can consider this problem solved, but do you think this can be simplified any?
Amended on Thu 30 Sep 2010 04:03 AM by Rivius
Netherlands #3
Not really without knowing the bigger context and such.

The only 'simplification' I can offer is to use booleans rather than integers for your flags. E.g. offbalance = true or nsent = false, and likewise checking for those values.

Truth and false (on/off, yes/no, etc) are ment for this kind of thing, and it makes your code easier to read. Likewise, because an if-statement is basically checking for the 'truth' in an expression, you can simply say if nsent then.
Australia Forum Administrator #4
Rivius said:


You can consider this problem solved, but do you think this can be simplified any?


Well here:


if (string.find("%7", "e")) and 
   (string.find("%7", "l")) and 
   (string.find("%7", "x")) and 
   (string.find("%7", "r"))
then 
offbalanc = false -- If all these match, you're not off balance.


Does the server randomize the order of the letters? If not, why not just test:


if "%7" == "elxr" then
  offbalanc = false


And Worstje is right:


if nsent==true then


... is just wordy.

Make it:


if nsent then