[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Help with stat roll matching

Help with stat roll matching

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Boen310   (17 posts)  [Biography] bio
Date Wed 09 Nov 2022 02:09 PM (UTC)

Amended on Wed 09 Nov 2022 11:15 PM (UTC) by Boen310

Message
Trying to create a stat roller where its matching on words and the value after(word)....here is the sample output

Your basic stats:
Strength: good Power: excellent
Dexterity: good Intelligence: very good
Agility: very good Wisdom: good
Constitution: very good Charisma: good

Luck: very good Unused: very good


Currently I am using this but am not having any luck

Trigger:
^/s*(Strength|Dexterity|Constitution|Wisdom|Agility)\s+\ (good|very good|excellent)

Send:
#switch (%2)
("good") {Goodcnt = @Goodcnt + 1}
("very good") {VGcnt = @VGcnt + 1}
("excellent") {EXCcnt = @EXCcnt + 1}
{}

Then second trigger:
^Do you want to reroll this char$

Sending:
#show @EXCcnt
#IF (@EXCcnt > 4) (#show @EXCcnt;#3#beep) {y}
EXCcnt = 0
VGcnt = 0
Goodcnt = 0


Any help would be apprecaited.
PS tried [code] [/code] as top output isn't mono spaced
[Go to top] top

Posted by AdInfinitum   (74 posts)  [Biography] bio
Date Reply #1 on Wed 09 Nov 2022 05:49 PM (UTC)

Amended on Wed 09 Nov 2022 05:50 PM (UTC) by AdInfinitum

Message
You aren't very clear on what isn't working, but I suspect it's the following.

The code you are using seems to be zscript, commonly used by zMUD/CMUD. In order to use it in MUSHclient, you'll need to emulate the same functions in a language that MUSHclient can utilize.

In Lua code, you could do something akin to:


if ("%2" == "good") then
   SetVariable("Goodcnt", GetVariable("Goodcnt") + 1)
elseif ("%2" == "very good") then
   SetVariable("VGcnt", GetVariable("VGcnt") + 1)
elseif ("%2" == "excellent") then
   SetVariable("EXCcnt", GetVariable("EXCcnt") + 1)
end


That would be your first trigger, send to script. For your second trigger, you would do:


if (GetVariable("EXCcnt") > 4) then
   Note(GetVariable("EXCcnt"))
   Sound("ding.wav") -- or whatever sound you want to play
   Send("y") -- Assuming you want to reroll if excellent count is greater than 4; perhaps you meant 'n' instead?
   SetVariable("Goodcnt", 0)
   SetVariable("VGcnt", 0)
   SetVariable("EXCcnt", 0)
end


Also, make sure that Regular Expression is ticked in each of your trigger boxes. The triggers you supplied are in regex form, and should be flagged as such.
[Go to top] top

Posted by Boen310   (17 posts)  [Biography] bio
Date Reply #2 on Wed 09 Nov 2022 11:25 PM (UTC)
Message
Thank you for the update to the code. Was what found for something and modified. I can't seem to get anything to trigger. Copied what you gave for both and sent first to Script and sent second to World and it never triggers

Output:

Your basic stats:
Strength:           excellent      Power:        very good
Dexterity:          very good      Intelligence: very good
Agility:            very good      Wisdom:       very good
Constitution:       very good      Charisma:     very good

Luck:       very good      Unused:     excellent


Trigger:


^/s*(Strength|Dexterity|Constitution|Wisdom|Agility)\s+\ (good|very good|excellent)
[Go to top] top

Posted by Nick Gammon   Australia  (23,016 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Thu 10 Nov 2022 03:05 AM (UTC)
Message
Template:what Please help us by showing:
  • A copy of the trigger, alias or timer you were using (see Copying XML)
  • The error message, if any, that you got

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by AdInfinitum   (74 posts)  [Biography] bio
Date Reply #4 on Thu 10 Nov 2022 03:23 AM (UTC)
Message
Boen310 said:

Thank you for the update to the code. Was what found for something and modified. I can't seem to get anything to trigger. Copied what you gave for both and sent first to Script and sent second to World and it never triggers

Output:

Your basic stats:
Strength:           excellent      Power:        very good
Dexterity:          very good      Intelligence: very good
Agility:            very good      Wisdom:       very good
Constitution:       very good      Charisma:     very good

Luck:       very good      Unused:     excellent


Trigger:


^/s*(Strength|Dexterity|Constitution|Wisdom|Agility)\s+\ (good|very good|excellent)



Your trigger is missing a colon, which seems to exist in your output. Additionally, there are two other errors with your trigger line. When you start a trigger line with a "^", it means to start looking at the start of the line and nowhere else. This means, at the very least, that "Wisdom" will never be captured. Additionally, your "/s" is supposed to be "\s". Your trigger line probably needs to be:

(Strength|Dexterity|Constitution|Wisdom|Agility):\s+\ (good|very good|excellent)


Once again, make sure that you have Regular Expression ticked, otherwise it will not work.

Also, BOTH triggers need to be Send to script if using the code.

If all this fails, please follow what Nick asked above. It really helps to have you display what your triggers are by providing the XML of it, and doubly so when you give us the error message if one is provided.
[Go to top] top

Posted by Boen310   (17 posts)  [Biography] bio
Date Reply #5 on Thu 10 Nov 2022 04:56 PM (UTC)

Amended on Thu 10 Nov 2022 04:57 PM (UTC) by Boen310

Message

Trigger1:

(Strength|Dexterity|Constitution|Wisdom|Agility):\s+\ (good|very good|excellent)

Send1:

if ("%2" == "good") then
   SetVariable("Goodcnt", GetVariable("Goodcnt") + 1)
elseif ("%2" == "very good") then
   SetVariable("VGcnt", GetVariable("VGcnt") + 1)
elseif ("%2" == "excellent") then
   SetVariable("EXCcnt", GetVariable("EXCcnt") + 1)
end

Trigger2:
Do you want to reroll this char

Send2:
if (GetVariable("EXCcnt") > 4) then
   Note(GetVariable("EXCcnt"))
   Sound("ding.wav")
   Send("n")
   SetVariable("Goodcnt", 0)
   SetVariable("VGcnt", 0)
   SetVariable("EXCcnt", 0)
end


Both to Script

Getting this error now:

Run-time error
World: Duris
Immediate execution
[string "Trigger: "]:2: attempt to perform arithmetic on a nil value
stack traceback:
        [string "Trigger: "]:2: in main chunk


The value of 2 here [string "Trigger: "]:2: changes between 1,2,4,6
[Go to top] top

Posted by AdInfinitum   (74 posts)  [Biography] bio
Date Reply #6 on Thu 10 Nov 2022 05:31 PM (UTC)
Message
I see what the issue is. You do not have Goodcnt, VGcnt, and EXCcnt set prior to running the script. To counter that, make the following change:


if ("%2" == "good") then
   SetVariable("Goodcnt", (GetVariable("Goodcnt") or 0) + 1)
elseif ("%2" == "very good") then
   SetVariable("VGcnt", (GetVariable("VGcnt") or 0) + 1)
elseif ("%2" == "excellent") then
   SetVariable("EXCcnt", (GetVariable("EXCcnt") or 0) + 1)
end


If the variable does not exist, it'll assume 0 and add 1 to it. Otherwise, it will take the variable's count and add 1 to it.

Hopefully this solves it all.
[Go to top] top

Posted by Boen310   (17 posts)  [Biography] bio
Date Reply #7 on Thu 10 Nov 2022 05:37 PM (UTC)
Message

Run-time error
World: Duris
Immediate execution
[string "Trigger: "]:1: attempt to compare number with string
stack traceback:
        [string "Trigger: "]:1: in main chunk


made changes and get this now.
[Go to top] top

Posted by AdInfinitum   (74 posts)  [Biography] bio
Date Reply #8 on Thu 10 Nov 2022 07:04 PM (UTC)
Message
This is what happens when you try to respond while at work. Despite being a number, variables are saved as type "string". The change for the second trigger needs to be:


if (GetVariable("EXCcnt") > 4) then


changed to:


if (tonumber(GetVariable("EXCcnt")) > 4) then


If there are more failures, please highlight the triggers in the GUI and click the 'Copy' button located near the bottom right of the button group. Then come here and 'paste' the actual XML.
[Go to top] top

Posted by Boen310   (17 posts)  [Biography] bio
Date Reply #9 on Thu 10 Nov 2022 07:36 PM (UTC)

Amended on Thu 10 Nov 2022 07:50 PM (UTC) by Boen310

Message
I turned on tracing if that is what you mean and this is the output from that. This is made after your latest change. It run this and does not continue to keep rolling.



Your basic stats:
Strength:           very good      Power:        very good
TRACE: Matched trigger "(Strength|Dexterity|Constitution|Wisdom|Agility):\s+\ (good|very good|excellent)"
Dexterity:          very good      Intelligence: good
TRACE: Matched trigger "(Strength|Dexterity|Constitution|Wisdom|Agility):\s+\ (good|very good|excellent)"
Agility:            very good      Wisdom:       very good
TRACE: Matched trigger "(Strength|Dexterity|Constitution|Wisdom|Agility):\s+\ (good|very good|excellent)"
Constitution:       very good      Charisma:     very good
TRACE: Matched trigger "(Strength|Dexterity|Constitution|Wisdom|Agility):\s+\ (good|very good|excellent)"

Luck:       very good      Unused:     very good


                Lame: 0-9 Poor:10-21 Below Avg:22-33 
                Avg:34-67 Above Avg:68-79 Good:80-85
                            Very good:86+:
 
Place your bonuses as you think will fit your playing style, as well as benefit 
TRACE: Matched trigger "Place your bonuses as you think will fit your playing style, as well as benefit"
7
n
your character.  Your stats will be further modified within the game by equipment 
and spells, and can be permanently modified as well.
Do you want to reroll this char (y/n) [y]:  

Accepting these stats.


If looking for something else please let me know as I did not see that option. Thank you for assisting.
[Go to top] top

Posted by Nick Gammon   Australia  (23,016 posts)  [Biography] bio   Forum Administrator
Date Reply #10 on Thu 10 Nov 2022 08:46 PM (UTC)
Message

I don’t see how your trigger will match both items on the same line (eg. Strength and Power).

You probably need to go about it differently:

  • When you see the line “Your basic stats:” activate (enable) another trigger

  • This second trigger matches “*" (ie, everything).

  • In the code, do a regular expression match (using Lua “string.match” function) for all the words (Strength, Power, Dexterity etc.).

  • If one matches note what value you got

  • When you see the line “Do you want to reroll this char” then respond accordingly and turn the trigger I mentioned above off.


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


9,910 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]