|
symposes Novice
Joined: 26 Apr 2006 Posts: 34
|
Posted: Wed Apr 26, 2006 3:20 am
help with an if statement |
im having trouble with a set of if statements.
#if (@cccp > @cchea) {n2}
#if (@cccp > @cafat) {n2}
#if (@cccp > @castr) {n2}
#if (@cchea > @cafat) {n1}
#if (@cchea > @castr) {n1}
#if (@cchea > @cccp) {n1}
#if (@cafat > @cchea) {n3}
#if (@cafat > @castr) {n3}
#if (@cafat > @cccp) {n3}
#if (@castr > @cchea) {n4}
#if (@castr > @cafat) {n4}
#if (@castr > @cccp) {n4}
i need a way to break down these into as few if statements as possible, or atleast a way that within 1 alias i can have it fireoff only 1 of the n commands...
the way ihave it now does serve its perpose but its spammy as can be, with it being fired basicly every 6 seconds.
if the order needs to change, i would perfer it retain the firing of n1, n3, n4, and finaly n2. that is, if it does 1 first, and waits to the next time for the second, the n commands, are actually setting toggles, so if its constantly every time firing off say n3, but none of the others when its supposed to, then it doesnt do me any good.
At this point, it fires 9 / 12 of these if statements everytime the alias is activated.
What im trying to do, is have it watch 4 different variables, and when 1 of the 4 variables is higher then the others, it will fire the n command related to it.
assming each variable is a 0-9 scale that is...
im only running 7.20, but hopefully that shouldnt matter.
thank you for taking the time to read/help. |
|
|
|
Vitae Enchanter
Joined: 17 Jun 2005 Posts: 673 Location: New York
|
Posted: Wed Apr 26, 2006 2:16 pm |
i think nested #ifs might help.
Not sure. Do you actually WANT all of them firing? or only certain ones?
as in
#if ((@cccp > @cchea) AND (@cccp > @cafat)) {n2}
or
#if (@cchea > @cccp) {n1} {#if (@cafat > @cchea) {n3}} |
|
|
|
Arcane_of_Discworld Wanderer
Joined: 29 Jan 2002 Posts: 99 Location: UK
|
Posted: Wed Apr 26, 2006 3:05 pm |
From your initial post I assume that you only want one alias to be activated if the relevant variable is greater than the other three.
I would do as Vitae suggested and use 'AND' to group conditions, using your initial posts I have done so:
#if (@cchea > @cafat AND @cchea > @castr AND @cchea > @cccp) {n1} {}
#if (@cccp > @cchea AND @cccp > @cafat AND @cccp > @castr) {n2} {}
#if (@cafat > @cchea AND @cafat > @castr AND @cafat > @cccp) {n3} {}
#if (@castr > @cchea AND @castr > @cafat AND @castr > @cccp) {n4} {}
Only one of the above statements can be true at any one time, however if you also want to know when all variables are equal you can either add another chain of conditions stipulating equals conditions or by nesting the aforementioned ones such as:
.
Code: |
#IF (@cchea > @cafat AND @cchea > @castr AND @cchea > @cccp) {n1} {#IF (@cccp > @cchea AND @cccp > @cafat AND @cccp > @castr) {n2} {#IF (@cafat > @cchea AND @cafat > @castr AND @cafat > @cccp) {n3} {#IF (@castr > @cchea AND @castr > @cafat AND @castr > @cccp) {n4} {#ECHO All variables the same.}}}} |
In my experience it is much easier to build any conditionals that eventually need to be nested individually and then nest them afterwards |
|
|
|
symposes Novice
Joined: 26 Apr 2006 Posts: 34
|
Posted: Wed Apr 26, 2006 11:47 pm |
woot time to pla with them and see if it is doing what i think i want it doing, ill let you all know if this works out. thanks again.
and im not sure if i was clear, what it is, is that there are four values, that change during combat for this character on this mud.
instead of being able to just activate a quickie heal, like "cure light wounds' or eat something, or drink a potion, the way the character heals is by toggling a passive regening ability to 1 of the 4 pools,
it 'ticks' every 3 heartbeats, or 6 seconds.
so ive set up a trigger to count the rounds, and every third round, ie heartbeat, check the pools, decide which of the 4 is the lowest, and then it will assign the regen to that pool until the next check...
I know that what ive said, makes what ive posted halfway backwards, but i used some if statements, to change the amounts for the pools from percents to just a 0-9 scale, 0 being 100% or fully regened, and 9 being 10% or lower,
Im hoping that what im thinking of, and what you 2 have so kindly provided is what im thinking im trying to do.
:) |
|
|
|
symposes Novice
Joined: 26 Apr 2006 Posts: 34
|
Posted: Thu Apr 27, 2006 12:26 am |
hmm now to figure out how to drop a nested if into these, to check what the regen is already at, what the regen is set to is shown in the combat prompt, and ive already tagged it.
hmm adding the )and(blah != whatever)) did the checking for me wonderfully.
thanks everyone |
|
|
|
Arcane_of_Discworld Wanderer
Joined: 29 Jan 2002 Posts: 99 Location: UK
|
Posted: Thu Apr 27, 2006 3:46 am |
Tip: write all your conditionals individually and include else brackets as I did in the first example .. then it is a simple matter to cut the latter conditionals and paste them in between the 'else' brackets (one conditional at a time}
|
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|