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
skeen77
Novice


Joined: 25 Oct 2010
Posts: 31

PostPosted: Wed Nov 27, 2013 10:25 pm   

Using a variable to store credits on hand
 
Quote:
[ Con: 18 ] [ Kills: 1216 ] [ Credits: $ 5365 ]


This is an example of the line on the score sheet for the mud I'm playing on. I want to be able to store the current credits on hand, and then call on that value in a command to give X credits person. I've tried a few things, and it either results in it not properly calling on the variable, or sending a whole bunch of parse error messages on the score sheet.
Reply with quote
Daern
Sorcerer


Joined: 15 Apr 2011
Posts: 809

PostPosted: Wed Nov 27, 2013 11:03 pm   
 
Code:
#TRIGGER {^~[ Con: %d ~] ~[ Kills: %d ~] ~[ Credits: ~$ (%d) ~]$} {credits = %1}


That'll store the number of credits in a variable named credits, you can then reference it in other triggers/aliases/etc with @credits.
Reply with quote
skeen77
Novice


Joined: 25 Oct 2010
Posts: 31

PostPosted: Wed Nov 27, 2013 11:09 pm   
 
If I just forget about the con and kills section and do
Code:
#TRIGGER {[ Credits: ~$ (%d) ~]$} {credits = %1}
Would that work too?
Reply with quote
skeen77
Novice


Joined: 25 Oct 2010
Posts: 31

PostPosted: Wed Nov 27, 2013 11:28 pm   
 
using your trigger, I then tried to call on the variable (renamed sakecredits) (sake is char name). the line of code I have is
Code:
give @sakecredits credits krom
. I've tried $sakecredits, &sakecredits, and just sakecredits, but it's always returning a blank.
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Thu Nov 28, 2013 1:38 am   
 
I assume that when you changed the variable's name you also changed all references to that variable to whatever you namechanged to? Renaming the variable sakecredits does no good if the trigger is still using "credits = %1".

Beyond that, try putting a #PRINT command into the trigger to see if it's even firing. We don't know the context of your line, but it could be that the space between the $ and the numbers is optional based on the length of the number (ie, "Credits: $ 5000" versus "Credits: $10000").
_________________
EDIT: I didn't like my old signature
Reply with quote
skeen77
Novice


Joined: 25 Oct 2010
Posts: 31

PostPosted: Fri Nov 29, 2013 2:40 am   
 
MattLofton wrote:
I assume that when you changed the variable's name you also changed all references to that variable to whatever you namechanged to? Renaming the variable sakecredits does no good if the trigger is still using "credits = %1".

Beyond that, try putting a #PRINT command into the trigger to see if it's even firing. We don't know the context of your line, but it could be that the space between the $ and the numbers is optional based on the length of the number (ie, "Credits: $ 5000" versus "Credits: $10000").


Currently I have the following:

Code:
#TRIGGER {^~[ Con: %d ~] ~[ Kills: %d ~] ~[ Credits: ~$ (%d) ~]} {sakecredits = %1}


And the alias I'm trying to use it in is:

Code:
give @sakecredits credits krom


Using #PRINT @sakecredits is returning zilch.
Reply with quote
Daern
Sorcerer


Joined: 15 Apr 2011
Posts: 809

PostPosted: Fri Nov 29, 2013 3:03 am   
 
I just tested it and that pattern works perfectly on this line:
Quote:
[ Con: 18 ] [ Kills: 1216 ] [ Credits: $ 5365 ]


You're sure that's the entire line, start to finish? As Matt said, there's no spacing inconsistencies, etc?
Reply with quote
skeen77
Novice


Joined: 25 Oct 2010
Posts: 31

PostPosted: Fri Nov 29, 2013 4:05 am   
 
Actually yeah, there are spacing inconsistencies. It aligns the credit number to the right, so there can be variable spaces before the $..
Reply with quote
Daern
Sorcerer


Joined: 15 Apr 2011
Posts: 809

PostPosted: Fri Nov 29, 2013 6:28 pm   
 
Use %s in your pattern to match any number of spaces.
Reply with quote
skeen77
Novice


Joined: 25 Oct 2010
Posts: 31

PostPosted: Fri Nov 29, 2013 9:46 pm   
 
So like %s instead of %d?
Reply with quote
hogarius
Adept


Joined: 29 Jan 2003
Posts: 221
Location: islands.genesismuds.org

PostPosted: Fri Nov 29, 2013 10:04 pm   
 
Something like this:

#TRIGGER {^~[ Con: %d ~] ~[ Kills: %d ~] ~[ Credits: ~$%s(%d) ~]} {sakecredits = %1}

Note that the "%s" indicates 0 or more spaces between the literal-quoted dollar sign and the digits.

Here's some more information on trigger pattern wildcards:

http://forums.zuggsoft.com/modules/mx_kb/kb.php?page=3&mode=doc&k=2684
Reply with quote
skeen77
Novice


Joined: 25 Oct 2010
Posts: 31

PostPosted: Fri Nov 29, 2013 10:19 pm   
 
Here's a screenshot of the score screen itself. A lot of the spaces didn't translate right I guess.

http://i.imgur.com/6L93oz5.jpg
Reply with quote
hogarius
Adept


Joined: 29 Jan 2003
Posts: 221
Location: islands.genesismuds.org

PostPosted: Fri Nov 29, 2013 11:22 pm   
 
Ah. Not only do you have a various number of spaces between the $ sign and the digits, but you also have spaces between the word "Credits:" and the $ sign.

When copy-pasting text into this forum, you should use [ code ] and [ \code ] tags (remove the spaces) at the beginning and end of the text. If you don't use the code tags, the forum will delete extra spaces between words.

You should set the pattern of your trigger like this:

Code:
#TRIGGER {~[ Credits~:%s~$%s(%d) ~]} {sakecredits = %1}
Reply with quote
skeen77
Novice


Joined: 25 Oct 2010
Posts: 31

PostPosted: Sat Nov 30, 2013 1:53 am   
 
Sir, you are an officer and a gentleman. That worked, and now I'll study it so I full understand it. Thank you.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
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