|
HollyC Novice
Joined: 10 Apr 2003 Posts: 45 Location: USA
|
Posted: Sun Dec 19, 2004 3:42 am
Reducing value of a variable? |
I know that you can increase the value of a variable with the #ADD command; for example, #ADD Testnum 1 would increase its value by 1.
How do you DECREASE the variable's value? The #MATH command (for example, #MATH Testnum (@Testnum -1)) does not work. I'd like some flexibility in the Testnum variable, as to be able to either increase or decrease its value. How do you decrease it?
Holly
(EDIT: #ADD Testnum -1 is NOT working. The variable's value is REMAINING THE SAME after I input an alias that triggers #ADD Testnum -1. I thought I had the answer but I don't. So I'm still looking for how to decrease the value of a variable.) |
|
_________________ |
|
|
|
megamog75 Enchanter
Joined: 20 Nov 2002 Posts: 627 Location: USA
|
Posted: Sun Dec 19, 2004 5:09 am |
I tested this:
#var testnum 10
#alias as {#add testnum -1}
it worked just fine.
You could also try:
#alias as {#var %abs(@testnum-1)}
where one could be a %1 or @somenum |
|
_________________ megamog75
I will do this.Nothing in my life matters except this.No moment in my life exists except this moment.I am born in this moment, and if I fail, I will die in this moment. Raistlin Majere |
|
|
|
HollyC Novice
Joined: 10 Apr 2003 Posts: 45 Location: USA
|
Posted: Sun Dec 19, 2004 5:50 pm Re: Reducing value of a variable |
I agonized over this for hours on end before I finally got it to work. Here, I'll explain in more detail.
This is yet another Achaea-related thing, but I left out what I thought were non-critical details that might lead people to think game-specific knowledge of Achaea was required. I wanted to program my curing system to keep track of the number of afflictions so that it would use a specific cure called the tree tattoo when the number got to be greater than 4. That is, when the number is 5 or higher, it will try to do the tree.
So I had the following added to my system:
#VAR afflictions {}
#VAR testnum {0}
#ALIAS afflict {#addkey afflictions %1 1;#IF (@testnum) < 0 {@testnum = 0};#add testnum 1}
#ALIAS unafflict {#if (@Afflictions.unknown = 1) {#delkey Afflictions unknown};#delkey Afflictions %1;#ADD testnum -1;#IF (@testnum < 0) {@testnum = 0}}
Then, while in Offline mode, I would copy and paste messages given when afflictions are received, which are supposed to trigger the afflict alias (that is, the afflict alias is the value of the trigger -- afflict stupidity, afflict asthma, etc.). I would type #SHOW @testnum after each such message and it would increase from 1, to 2, to 3, etc.
For example:
You feel your passage through time slow. (the message given when you receive the aeon affliction-- this is a trigger with 'afflict aeon' as the value.)
#show @testnum (it returned a 1)
Hmmm. Why must everything be so difficult to figure out? (stupidity message -- this is a trigger with 'afflict stupidity' as the value.)
#show @testnum (it returned a 2)
Pain is something only the weak feel! (recklessness message -- this is a trigger with 'afflict recklessness' as the value.)
#show @testnum (it returned a 3)
Then I would start pasting in cure messages, that you receive when you use specific cures. Each of these cure messages is a trigger with the unafflict alias as its value -- unafflict stupidity, unafflict asthma, etc. But each time I put in a cure messages, and would then type #SHOW @testnum, the value of testnum stayed at 3, no matter what I did. For hours and hours I agonized over this, twisting and squirming and fiddling with the code this way and that, and no matter what I did, EVERY time, the #SHOW @testnum would NOT show the value of the variable as decreasing.
For example (with the value of @testnum still at 3):
The curse of the aeon wears off and you return to the normal timestream. (message for aeon cured -- this is a trigger with 'unafflict aeon' as the value.)
#show @testnum (it stayed at 3 instead of going to 2)
You don't feel like such a complete idiot anymore. (message for stupidity cured -- this is a trigger with 'unafflict stupidity' as the value.)
#show @testnum (again it still returned 3 instead of 2)
Prudence rules your psyche once again. (message for recklessness cured -- this is a trigger with 'unafflict recklessness' as the value.)
#show @testnum (it STILL returned 3)
Finally, I tried a last, desperate idea before taking my whole computer and dunking it in a vat of molten wax and turning it into a scented candle.
I thought that maybe the fact that I was offline had something to do with it. So instead of typing an affliction message (that had the afflict alias as a trigger value, I simply typed the alias itself-- afflict stupidity, afflict asthma, etc. Each time the value of testnum would increase by 1 accordingly. When the value of testnum was 3, I then typed unafflict stupidity, and that was it. The #show @testnum command FINALLY returned a value of 2. I typed unafflict asthma, and it went down from 2 to 1.
The only guess I can come up with, is that the trigger messages that set off the afflict alias, work while offline, but the trigger messages that set off the unafflict alias ONLY work while connected, playing the game and actually receiving the afflictions. Otherwise, they don't trigger the unafflict alias.
I don't know why that is, but finally the code was working.
Holly |
|
_________________
Last edited by HollyC on Sun Dec 19, 2004 5:54 pm; edited 2 times in total |
|
|
|
HollyC Novice
Joined: 10 Apr 2003 Posts: 45 Location: USA
|
Posted: Sun Dec 19, 2004 5:50 pm Re: Reducing value of a variable |
EDIT: Sorry, my browser double-posted the reply. I can't seem to remove the extra reply so I edited it down to this.
Holly |
|
_________________ |
|
|
|
Hibio Beginner
Joined: 19 Mar 2004 Posts: 22
|
Posted: Mon Dec 27, 2004 11:19 pm |
#math test_var {@test_var - 1}
works fine for me |
|
|
|
Kiasyn Apprentice
Joined: 05 Dec 2004 Posts: 196 Location: New Zealand
|
Posted: Wed Dec 29, 2004 6:45 am Re: Reducing value of a variable |
HollyC wrote: |
#ALIAS afflict {#addkey afflictions %1 1;#IF (@testnum) < 0 {@testnum = 0};#add testnum 1}
#ALIAS unafflict {#if (@Afflictions.unknown = 1) {#delkey Afflictions unknown};#delkey Afflictions %1;#ADD testnum -1;#IF (@testnum < 0) {@testnum = 0}}
|
I believe @testnum = 0 should be testnum = 0... no @... might be wrong heh |
|
|
|
Hibio Beginner
Joined: 19 Mar 2004 Posts: 22
|
Posted: Wed Dec 29, 2004 9:21 am |
Quote: |
#ALIAS afflict {#addkey afflictions %1 1;#IF (@testnum) < 0 {@testnum = 0};#add testnum 1} |
The #if part seems to be the error. How can you have if TRUE then have a comparison < right after?
#ALIAS afflict {#addkey afflictions %1 1;#IF (@testnum < 0) {@testnum = 0};#add testnum 1} |
|
|
|
Falan Wanderer
Joined: 17 Aug 2004 Posts: 98 Location: OK, USA
|
Posted: Wed Dec 29, 2004 10:30 am |
#ALIAS afflict {
#addkey afflictions %1 1
#IF (@testnum < 0) {testnum = 0}
#add testnum 1
}
Used Pretty Print
Syntax Colourizer |
|
_________________ zMUD 7.05a |
|
|
|
Larkin Wizard
Joined: 25 Mar 2003 Posts: 1113 Location: USA
|
Posted: Mon Jan 03, 2005 3:49 pm |
Kiasyn hit on the source of the problem, I'm certain. If you use the syntax "@var = value" you will indirectly create a new variable with the name equal to the current value of @var.
#VAR MyVar {blah}
@MyVar = hiya
#SHOW @MyVar
#SHOW @blah
This should display "blah" and then "hiya" because the assignment created a new variable instead of assigning your value to your existing variable. This syntax can be useful, but it's often an unwanted side effect of a typo. |
|
|
|
|
|