Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion Goto page 1, 2  Next
groundzero2010
Novice


Joined: 30 Sep 2004
Posts: 47
Location: Arkansas

PostPosted: Tue Feb 27, 2018 3:59 am   

Increment Variable DB Item
 
I have some triggers that auto populate my spells into a bunch of different variables going by the spell name.

Spell variable Examples stored in /bott/TempVars/SpellVars/ folder:
@armor
@strength
@shield

Looking at the armor spell variable: /bott/TempVars/SpellVars/@armor

Armor variable stores these keys:

@armor.spelllevel
@armor.levelreceived
@armor.maxspelllevel
@armor.difference
@armor.increased

With these values (respectively):
6
4
10
4
0


When the MUD prints out..
Code:
Your knowledge of armor increases!

I want the @armor.increased item to increment by 1, which would change the 0 above to a 1 and increment until I reset back to 0 in a different trigger.

I trigger off of...
Code:
Your knowledge of (%*)increases!


I've tried a few things with no luck.

In the below code, I've captured the spell name into the variable 'lastIncreasedSpell' for use and future use. The rest isn't working like I'd expected. Any help would be appreciated as I'm running out of things to try.

Code:

#var /bott/bot/TempVars/lastIncreasedSpell %1


#add /bott/bot/TempVars/SpellVars/@lastIncreasedSpell increased %eval (@lastIncreasedSpell.increased)+1

;#ADDKEY /bott/bot/TempVars/SpellVars/%1 {increased} (%db(  %1, increased)+1)
;#ADD /bott/bot/TempVars/SpellVars/%1 {increased} (%db(  %1, increased)+1)


Once I can get this item to increment to 5 the spell will be ready for practice. Once practiced I'll have to reset it back to 0 to start the process over again.
I hope this makes sense, as I've had a hard time trying to explain it.
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4691
Location: Pensacola, FL, USA

PostPosted: Tue Feb 27, 2018 4:50 am   
 
in this case try
$val=(%db(@armor, increased)+1)
#ADDKEY armor increased $val

You have to rely on the scope to pick the right variable with the #ADDKEY command... though unless you have more than one @armor variable, there is no need to specify classes anyway.
_________________
Discord: Shalimarwildcat
Reply with quote
groundzero2010
Novice


Joined: 30 Sep 2004
Posts: 47
Location: Arkansas

PostPosted: Tue Feb 27, 2018 5:08 am   
 
I'm needing to pick up the variable @armor from the triggered text 'Your knowledge of (%*)increases!' since this will trigger on different spells.
Following your lead would I use it like so? I don't feel like this would specify the %1 as @armor


Code:

$val=(%db(%1, increased)+1)
#ADDKEY %1 increased $val
Reply with quote
groundzero2010
Novice


Joined: 30 Sep 2004
Posts: 47
Location: Arkansas

PostPosted: Tue Feb 27, 2018 5:17 am   
 
Tested yours and it works perfectly when specifying @armor just as you typed, but I need it to dynamically change the spell name. Mine doesn't work as it creates a new @armor at the base class level instead of modifying the existing @armor.increased value.
Reply with quote
Chiara
Site Admin


Joined: 29 Sep 2000
Posts: 389
Location: USA

PostPosted: Tue Feb 27, 2018 6:23 pm   
 
Zugg fixed something in the server that adjusted the clock and Shalimar can't post again until it gets to be after when the computer thought he last posted, which is unfortunately tomorrow. We're really sorry about that.
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4691
Location: Pensacola, FL, USA

PostPosted: Tue Feb 27, 2018 8:04 pm   
 
If any of the classes along the way are disabled, then it can't see them via scope and it will create a new variable.
Alternately, you could copy the entire variable into a local variable and then assign that via a #VAR command with all the class stuff.

P.S. remove the % from your trigger pattern, (*) is a better 'anything' capture, or if it is only ever one word, then use (%w) to be more precise.

#TR {Your knowledge of (%w) increases!} {
$val=(%db(%concat("@", %1), increased)+1)
#ADDKEY %1 increased $val
}
_________________
Discord: Shalimarwildcat
Reply with quote
groundzero2010
Novice


Joined: 30 Sep 2004
Posts: 47
Location: Arkansas

PostPosted: Tue Feb 27, 2018 8:25 pm   
 
Thanks for the reply! Let me process your post and see if I understand what's going on! I'll check back with the results.
Reply with quote
groundzero2010
Novice


Joined: 30 Sep 2004
Posts: 47
Location: Arkansas

PostPosted: Tue Feb 27, 2018 8:49 pm   
 
Thanks for the tip. I'll go through and change all my (%*) to (*)

Tried adding this to the script as you suggested. None of my classes are disabled so all triggers and variables should work.
Code:

$val=(%db(%concat("@", %1), increased)+1)
#ADDKEY %1 increased $val

This isn't functioning as expected. This is creating a variable at the base level class with a record increase 1

Your knowledge of armor increases!
Creates a new variable
@armor increase 1
and doesn't increment if it triggers a second time. It stays at 1
I'm not sure why it doesn't utilize the existing @armor variable that is in a different class
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4691
Location: Pensacola, FL, USA

PostPosted: Tue Feb 27, 2018 10:32 pm   
 
It should be using the existing one unless it has the British spelling of armour.
I dont see why it would not be referencing the variable either...
Try:

$val=(%db(%eval(%concat("@", %1)), increased)+1)
_________________
Discord: Shalimarwildcat
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4691
Location: Pensacola, FL, USA

PostPosted: Tue Feb 27, 2018 10:43 pm   
 
$val=(%db(@{%1}, increased)+1)
_________________
Discord: Shalimarwildcat
Reply with quote
groundzero2010
Novice


Joined: 30 Sep 2004
Posts: 47
Location: Arkansas

PostPosted: Tue Feb 27, 2018 10:48 pm   
 
Let me try
Reply with quote
groundzero2010
Novice


Joined: 30 Sep 2004
Posts: 47
Location: Arkansas

PostPosted: Tue Feb 27, 2018 10:53 pm   
 
That last statement is incrementing, but creating a new @armor variable.
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4691
Location: Pensacola, FL, USA

PostPosted: Wed Feb 28, 2018 1:06 am   
 
So something is preventing the original variable from being seen by the firing trigger.
Perhaps move the original so it can be found easier?
Just by the naming of your classes, this clearly isn't a temporary variable. (Truly temporary things should be in $localVars.)

If not, something like this might force it to be saved in the proper place...
But if we can't reference it in the first place, we should end up with the non-incrementing issue again.

$temp=@{%1}
#ADDKEY $temp increased %eval(%db($temp, increased)+1)
#VAR %1 $temp _nodef {class|stuff|spelled|out}
_________________
Discord: Shalimarwildcat
Reply with quote
groundzero2010
Novice


Joined: 30 Sep 2004
Posts: 47
Location: Arkansas

PostPosted: Wed Feb 28, 2018 9:47 pm   
 
Testing if I can post again....
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4691
Location: Pensacola, FL, USA

PostPosted: Thu Mar 01, 2018 5:43 am   
 
Yea, the forum clock got fixed, bad timing, but at least the post times look accurate now.
I really think the issue here is a disabled setting, whether its one of your classes or the original @armor variable itself.

The only other way for them to not have scope on each other is if the original variable was in a separate window object from the firing trigger
Or if the original variable is a separate package entirely that was not active in the window object the trigger is located in.
Neither of which seems likely (those are more advanced topics IMHO), but I don't know for sure.
_________________
Discord: Shalimarwildcat
Reply with quote
groundzero2010
Novice


Joined: 30 Sep 2004
Posts: 47
Location: Arkansas

PostPosted: Thu Mar 01, 2018 1:31 pm   
 
Just curious, did you happen to run these suggestions through CMud yourself?

I'm going to create a new player session and try the absolute bare necessities and see if it has something to do with any of the other scripts I have in my current session. I appreciate your repeated help!
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4691
Location: Pensacola, FL, USA

PostPosted: Thu Mar 01, 2018 2:29 pm   
 
Which suggestions exactly?
I'm just troubleshooting here.
I have had scoping issues in the past as well.
_________________
Discord: Shalimarwildcat
Reply with quote
groundzero2010
Novice


Joined: 30 Sep 2004
Posts: 47
Location: Arkansas

PostPosted: Thu Mar 01, 2018 2:40 pm   
 
Any of them really. Just curious how you help others troubleshoot.
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4691
Location: Pensacola, FL, USA

PostPosted: Thu Mar 01, 2018 3:00 pm   
 
It's mostly an accumulation of better practices.
I started off on this forum by asking questions, learning the intricacies of the various functions and commands.
As I grew more familiar with it, I found myself asking less, and answering more.

The #SAY command is one of the most powerful debugging tools, if only for letting you see the current value of a given variable, to ensure that it is what you are expecting.
Most issues are a result of a variable definition gone wrong, (bad pattern, string manipulation, or scoping), or general zScript syntax.
_________________
Discord: Shalimarwildcat
Reply with quote
groundzero2010
Novice


Joined: 30 Sep 2004
Posts: 47
Location: Arkansas

PostPosted: Thu Mar 01, 2018 3:16 pm   
 
I use #SAY and #SHOW quite often for testing and triggering.
Reply with quote
groundzero2010
Novice


Joined: 30 Sep 2004
Posts: 47
Location: Arkansas

PostPosted: Fri Mar 09, 2018 5:53 pm   
 
So I ran a separate test and came up with something that works but can't for the life of me get it to incorporate into my existing trigger that handles a little more data. Here is my two working triggers.

Code:
<trigger priority="19690" id="1969">
  <pattern>(%w)%sMagic Level:%s(%d)%sLevel:%s(%d)</pattern>
  <value>#CW green
#addkey /temp/bot/%1 increased %eval(0)
#addkey /temp/bot/%1 spllev %2
#addkey /temp/bot/%1 level %3</value>
</trigger>


Code:
<trigger priority="19810" id="1981">
  <pattern>You know more about (%w)!</pattern>
  <value>#CW green
$val=(%db(@{%1}, increased)+1)
#addkey /temp/bot/%1 increased $val</value>
</trigger>


The first trigger executes on text like fireball Magic Level: 15 Level: 5
The second executes on You know more about fireball!

The first trigger creates a variable called fireball with key/value pairs increased/0, spllev/15, level/5
The second trigger takes the value saved in increased and adds 1 each time the trigger fires.

This works well and all within the same variable.

Getting this to work with my existing stuff I'm not having luck with which I may just post that code in a separate post. I did notice that if I added the increased key at the bottom of the trigger it wasn't incrementing correctly. Instead of adding 1 to the value, it would end up with a value like 0 1 after the first trigger and 0 1 1 after the second and so on. It seems like it is saving it as a text string instead of an integer but not sure.
Reply with quote
groundzero2010
Novice


Joined: 30 Sep 2004
Posts: 47
Location: Arkansas

PostPosted: Fri Mar 09, 2018 6:13 pm   
 
These are my two triggers I can't seem to get working properly.

Code:
<trigger priority="2690" id="430">
  <pattern>^(%w)%sSpell Level:%s(%d)%sLevel:%s(%d)%s(%*)</pattern>
  <value>#CW cyan
#var /bott/bot/TempVars/spell %1
#var /bott/bot/TempVars/readyToPrac %4
#addkey /bott/bot/TempVars/SpellVars/%1 increased %eval(0)
#addkey /bott/bot/TempVars/SpellVars/%1 splev %2
#addkey /bott/bot/TempVars/SpellVars/%1 levrec %3

</value>
 
</trigger>


Code:
<trigger priority="2620" id="1831">
  <pattern>Your knowledge of (*)increases!</pattern>
  <value>$val=(%db(@{%1}, increased)+1)
#addkey /bott/bot/TempVars/SpellVars/%1 increased $val
#CW blue

#add nex 1
#SA
#IF (%null( @{spelllist.@{nex}})) {
nex = 1
#SA Now Practicing Spell: %item(@spelllist,@nex)} {
#SA Now Practicing Spell: %item(@spelllist,@nex)}</value>
</trigger>


I moved the addkey increased in the first trigger to the top of the addkey stack but still getting two variables in the same folder. One has all three key values (increased, splev, levrec) and the second variable has the key (increased).
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4691
Location: Pensacola, FL, USA

PostPosted: Fri Mar 09, 2018 8:07 pm   
 
In the first one...
(%*) should be (*) or (%w)
Also, if it is using a multi-word item name, white space might be causing issues, try something like this to get around it:

$name=%replace(%1, " ", "_")

Try using #DELKEY to get rid of increased, rather than setting it to 0. You are right, it is treating the data as a string...

It is possible you may have corrupted your package.
Does the Issue persist if you get rid of the original variable and allow it to recreate itself?
_________________
Discord: Shalimarwildcat
Reply with quote
groundzero2010
Novice


Joined: 30 Sep 2004
Posts: 47
Location: Arkansas

PostPosted: Fri Mar 09, 2018 8:27 pm   
 
I'll try your suggestion. What I'm doing currently is I have three triggers one trigger is based on one word spells, second trig is based on two word spells, 3 for 3 word spells. Capturing them and combining the words together without any white space.

enchant armor would be enchantarmor

Using your suggestion I'm guessing would help bring those 3 trigs into one. Love it!
Reply with quote
groundzero2010
Novice


Joined: 30 Sep 2004
Posts: 47
Location: Arkansas

PostPosted: Fri Mar 09, 2018 8:27 pm   
 
Attempted using your suggestion you mentioned last week (shown below) I may have my syntax incorrect as I'm not real sure what the $temp _nodef portion is doing. The result of this is it's creating an entirely new variable at the base level (not in the class /bott/bot/TempVars/SpellVars) but retaining all the information saved (increased, splev, levrec) and actually incrementing increased correctly.
Code:
<trigger priority="2620" id="1831">
  <pattern>Your knowledge of (*)increases!</pattern>
  <value>$temp=@{%1}
#ADDKEY $temp increased %eval(%db($temp, increased)+1)
#VAR %1 $temp _nodef {/bott/bot/TempVars/SpellVars}
#CW blue

#add nex 1
#SA
#IF (%null( @{spelllist.@{nex}})) {
nex = 1
#SA Now Practicing Spell: %item(@spelllist,@nex)} {
#SA Now Practicing Spell: %item(@spelllist,@nex)}

</value>
 
</trigger>
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
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

© 2009 Zugg Software. Hosted by Wolfpaw.net