Stringlist?

by Aramel

Back to Mechanic's Corner.

Aramel2007-07-06 01:32:39
I was trying to make a basic curing system with nested #ifs, and it was rather prohibitively complicated. I've got a master trigger set to fire on prompt that triggers an alias called curecheck which goes something like

QUOTE
#t- 1
#if (@stunned=0 & @asleep=0) {
#if (@paralysis=1 & @impatience=0) {paracheck}
#if (@trapped=1) {trapcheck}
#if (@herbbal=1) {pipecheck}
#if (@herbbal=1 & @anorexia=0) {herbcheck}
#if (@potionbal=1 & @anorexia=0) {potioncheck}
#if (@salvebal=1 & @slickness=0) {salvecheck}
}
#if (@choke=0) {#wait 5000}
#t+ 1
It's not done yet, but the bits that are done work... herbcheck, salvecheck, etc are all aliases, with herbcheck being:

QUOTE
#if (@aeon=1 & @choke=0) {reishi} {#if @hypochondria=1 {wormwood} {#if @succumb=1 {succumbcure} {#if @addiction=1 {galingale} {#if @stupidity=1 {pennyroyal} {#if @slickness=1 {calamus} {#if @rigormortis=1 {marjoram} {#if @peace=1 {reishi} {#if @agoraphobia=1 {wormwood} {#if @manabarbs=1 {horehound} {#if @lovers=1 {galingale} {#if @brokenchest=1 {arnchest} {#if @epilepsy=1 {kombu} {#if @achromaticaura=1 {horehound} {#if @puncturedaura=1 {reishi} {#if @vertigo=1 {myrtle} {#if @paranoia=1 {pennyroyal} {#if @dementia=1 {pennyroyal} {#if @gluttony=1 {galingale} {#if @justice=1 {reishi} {#if @hallucinations=1 {pennyroyal} {#if @relapsing=1 {yarrow} {#if @clumsiness=1 {kombu} {#if @sevartery=1 {yarrow} {#if @slicedgut=1 {marjoram} {#if @puncturedchest=1 {marjoram} {#if @slicedforehead=1 {yarrow} {#if @severedear=1 {marjoram} {#if @fracturedarm=1 {arnarms} {#if @snappedrib=1 {arnchest} {#if @slicedchest=1 {marjoram} {#if @slicedthigh=1 {marjoram} {#if @brokennose=1 {arnhead} {#if @slicedbicep=1 {marjoram} {#if @gashedcheek=1 {marjoram} {#if @powerspikes=1 {horehound} {#if @lethargy=1 {yarrow} {#if @narcolepsy=1 {kafe} {#if @daydreaming=1 {kafe}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}


And the herb aliases (with calamus as an example)
QUOTE
outr calamus
#wait @choke
eat calamus
#wait @choke
#var herbbal 0.5
#alarm +0.8 {#if (@herbbal=0.5) {#var herbbal 1}}


All well and fine, even if very messy. But then there's the problem: prompt fires often, which means that if two prompts come along at about the same time, I eat the same herbs twice. And I'm not even touching delayed cures. I've tried using #t+ and #t- for the prompt trigger, which seem to work, but it slows the whole thing down and is just crazy.

I've heard it said that stringlist is better, but I can't wrap my head around it. Presumably I trigger the affliction message to go #var afflictions thing, but then what? How do I actually cure the stuff, and where does herbbalance and all that figure into this? And will it even help the eating-twice problem (because my net is slow)?
Sylphas2007-07-06 01:42:08
You add the afflictions to a list. When you fire you curing function, it iterates over this list and cures appropriately. It has the benefit of not checking for everything, only what you actually have (or think you have, depending on how good your system is). In theory, this should speed things up a great deal when you're not actually fighting, because it will make one check, see that you're fine, and be done, instead of going through a whole ton of nested ifs each prompt.
Sylphas2007-07-06 01:45:33
As an example, in pseudo-python:
CODE
if input = "paralysis trigger":
   afflictions = afflictions + "paralysis"

if input = "prompt":
   for a in afflictions:
      if a = "paralysis":
         paralysis
         code
         goes
         here
Aramel2007-07-06 01:52:42
QUOTE
When you fire you curing function, it iterates over this list and cures appropriately.


So... if I triggered it to put, say stupidity...


#additem afflictions 003_stupidity

And then trigger prompt to do:
%sort(@afflictions)
%item(@afflictions, 1)

(presuming that I aliased 003_stupidity to outr pennyroyal; eat pennyroyal)?

Hmm... or maybe I should just sort it by different balances-- all herb-cured stuff in one, salve-cured in another... but then again there's Choke, which would mess it up...

Argh.
Sylphas2007-07-06 01:57:16
They way I'd do it is to have a general check, and one per balance. You'd check for sleep, stun, aeon, etc, before you did anything, and cure appropriately. Then you'd hit up each balance and do a check for those, things like anorexia and asthma and such. If those are fine, iterate down the list.

Also, if you're going to sort it that way, it's more efficient to sort it when you become afflicted, instead of each time you check the list. I'm not sure how zMUD's sort function works, but it's going to be a lot more work than that one line of code makes it look.
Aramel2007-07-06 03:41:03
...for some reason I sometimes end up eating pennyroyal over and over and over, for no particular reason...

Gah. Maybe I should just stick to boolean and make a macro to check. :facepalm:
Theomar2007-07-06 09:35:06
Also, you should have two flags per balance: (using herb as an example) herb balance and ateherb balance.

Basically, when you attempt to eat an herb (or smoke a pipe), you set the ateherb balance to true (or false, depending on how you have it check; I check ateherb for true, because logically it makes sense). At the beginning of the herb balance affliction check, you check to make sure that main herb balance is true, and ateherb is false.

Also, with this addition you have to do two things: When you eat an herb (and have it cure), you remove both herb and ateherb balance. Also, you should make a timer to fire like 2 seconds after (the approx. length of herb balance recovery), and have it set ateherb to be it normal, off state.

This prevents you from eating multiple herbs. The same principle can be used on all of the balances.
Forren2007-07-06 11:56:07
QUOTE(Theomar @ Jul 6 2007, 05:35 AM) 423345
Also, you should have two flags per balance: (using herb as an example) herb balance and ateherb balance.

Basically, when you attempt to eat an herb (or smoke a pipe), you set the ateherb balance to true (or false, depending on how you have it check; I check ateherb for true, because logically it makes sense). At the beginning of the herb balance affliction check, you check to make sure that main herb balance is true, and ateherb is false.

Also, with this addition you have to do two things: When you eat an herb (and have it cure), you remove both herb and ateherb balance. Also, you should make a timer to fire like 2 seconds after (the approx. length of herb balance recovery), and have it set ateherb to be it normal, off state.

This prevents you from eating multiple herbs. The same principle can be used on all of the balances.


I don't use an ateherb, but what I do is set the herb balance temporarily to .5. I then have an alarm for a third of a second later to check if it's still .5. If it is, it resets the balance to 1. This way, stupidity won't throw off your system (as badly).
Sylphas2007-07-06 13:33:47
Helps with curing illusions too. If you haven't tried to eat something, and you see it happen anyway, has to be an illusion. Well, an illusion or your system bugging out on you, but you'd hopefully fix that before it matters.

EDIT: Bah, this is making me want to code a system again, something I've never actually bothered doing after my first one in Achaea got lost. I think I just like talking about them more than actually making them. sad.gif
Forren2007-07-06 14:58:31
QUOTE(Sylphas @ Jul 6 2007, 09:33 AM) 423382
Helps with curing illusions too. If you haven't tried to eat something, and you see it happen anyway, has to be an illusion. Well, an illusion or your system bugging out on you, but you'd hopefully fix that before it matters.

EDIT: Bah, this is making me want to code a system again, something I've never actually bothered doing after my first one in Achaea got lost. I think I just like talking about them more than actually making them. sad.gif


Yeah, I check that earlier - I store trying variables along with the last herb that I try. Different ways of doing the same thing, really.

And coding your own system really helps - hell, I've discovered strategies for other classes by finding weaknesses in curing algorithms, especially failsafes being called when they shouldn't be. I fix it in the system I'm building and make a note of how other systems on the market are vulnerable.