Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ Auto Roller Trigger *I'm not a coder*

Auto Roller Trigger *I'm not a coder*

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


Posted by Slashdotcoma   (6 posts)  Bio
Date Tue 08 May 2018 09:31 AM (UTC)

Amended on Wed 09 May 2018 04:53 AM (UTC) by Nick Gammon

Message
Hi,

I've written a Auto Roller Trigger. From changing the script the (first) problem is the "match". Sometimes, for example Str may be "[Above Avg ]", so it's 2 words, not just one (eg "Str [Strong ]").

The input is:


Your abilities are:
  Str  [Average    ]  Int  [Clever    ]  Wis  [Above Avg   ]
  Dex  [Agile      ]  Con  [Below Avg ]  Cha  [Average     ]
Roll again?(y/n):


Can someone assist please? And yes, I do realise that it is a *very* crude trigger, I've pieced in together from other forum posts, by googling. I'm not sure of which language it is in, but I think lua :)


<triggers>
  <trigger
   enabled="y"
   ignore_case="y"
   lines_to_match="2"
   keep_evaluating="y"
   match="^  Str  [(...........)]  Int  [(..........)]  Wis  [(............)]\n  Dex  [(...........)]  Con  [(..........)]  Cha  [(............)]$"
   multi_line="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>Str = (%1)
Int = (%2)
Wis = (%3)
Dex = (%4)
Con = (%5)
Cha = (%6)

if Str = 'Powerful' or 
   Str = 'Strong' or 
   Str = 'Potent' or 
   Str = 'Muscular'
Then
   YStr = "Yes"
end -- if

If Int = 'Genius' or 
   Int = 'Gifted' or 
   Int = 'Brilliant'
Then
   YInt = "Yes"
end -- if

If Wis = 'Shrewd' or
   Wis = 'Crafty'
Then
   YWis = "Yes"
end -- if

If Dex = 'Agile' or
   Dex = 'Nimble' or
   Dex = 'Smooth' or
   Dex = 'Adroit'
Then
   YDex = "Yes"
end -- if

If Con = 'Sturdy' or
   Con = 'Hardy' or
   Con = 'Husky'
Then
   YCon = "Yes"
end -- if

If Cha = 'Gorgeous' or
   Cha = 'Stunning' or
   Cha = 'Charming'
Then
   YCha = "Yes"
end -- if

If YStr = 'Yes' and 
   YInt = 'Yes' and 
   YWis = 'Yes' and 
   YDex = 'Yes' and 
   YCon = 'Yes' and 
   YCha = 'Yes'
Then 
    Send = "n"
Else
    Send = "y"
end -- if
</send>
  </trigger>
</triggers>
Top

Posted by Fiendish   USA  (2,534 posts)  Bio   Global Moderator
Date Reply #1 on Tue 08 May 2018 11:55 PM (UTC)

Amended on Wed 09 May 2018 12:12 AM (UTC) by Fiendish

Message
1. Please use code tags for code, not quote tags.
2. What language is this supposed to be in?
3. You need to also show what the game's output is.
4. Never ever say "it errors" without disclosing the contents of the error message. What are we supposed to do? Use our psychic powers?

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Fiendish   USA  (2,534 posts)  Bio   Global Moderator
Date Reply #2 on Wed 09 May 2018 12:14 AM (UTC)
Message
5. What other threads did you use to piece this together?

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Slashdotcoma   (6 posts)  Bio
Date Reply #3 on Wed 09 May 2018 03:47 AM (UTC)
Message
Ok. I think I've don as you've requested.
Top

Posted by Fiendish   USA  (2,534 posts)  Bio   Global Moderator
Date Reply #4 on Thu 10 May 2018 01:05 AM (UTC)

Amended on Thu 10 May 2018 01:25 AM (UTC) by Fiendish

Message
Ok, good. Now let's look at this...

Quote:
From changing the script the (first) problem is the "match".

You're right that it's chronologically the first thing to consider, but it's not the most serious one. I suggest getting it to work at all and then we'll focus on making sure that it works every time that it's supposed to.

Lua, like pretty much every programming language, is case sensitive. That means you can't write "If" when you're supposed to write "if" and you can't write "Then" when you're supposed to write "then" and you can't write "Else" when you're supposed to write "else".

Lua also, like pretty much every programming language, differentiates between value assignment and checking for equality. Lua assigns value with one equal sign (=) and checks for equality with two equal signs (==).

The other major issues is the bit at the beginning where you say, for instance

Str = (%1)

Because you are treating these values as what we call strings (aka text and not numbers), you actually want those to be:

Str = "%1"


Without looking yet at most of the logic or reason behind what you're doing, the valid Lua syntax would be:

Str = "%1"
Int = "%2"
Wis = "%3"
Dex = "%4"
Con = "%5"
Cha = "%6"

if Str == "Powerful" or 
   Str == "Strong" or 
   Str == "Potent" or 
   Str == "Muscular"
then
   YStr = "Yes"
end

if Int == "Genius" or 
   Int == "Gifted" or 
   Int == "Brilliant"
then
   YInt = "Yes"
end

if Wis == "Shrewd" or
   Wis == "Crafty"
then
   YWis = "Yes"
end

if Dex == "Agile" or
   Dex == "Nimble" or
   Dex == "Smooth" or
   Dex == "Adroit"
then
   YDex = "Yes"
end

if Con == "Sturdy" or
   Con == "Hardy" or
   Con == "Husky"
then
   YCon = "Yes"
end

if Cha == "Gorgeous" or
   Cha == "Stunning" or
   Cha == "Charming"
then
   YCha = "Yes"
end

if YStr == "Yes" and 
   YInt == "Yes" and 
   YWis == "Yes" and 
   YDex == "Yes" and 
   YCon == "Yes" and 
   YCha == "Yes"
then 
    Send = "n"
else
    Send = "y"
end


I also removed the "-- if" comments because I don't find them particularly helpful and made your single and double quotation marks uniformly double because people tend to favor consistency, but the use of single wasn't really a problem.


Now looking at your trigger pattern and looking at your description of the output, I think actually that the multi-word thing you describe is not a problem at all as long as the space between the two square brackets stays the same. You will want to trim the blank space from the ends though by using the Trim() function. e.g.

Str = Trim("%1")


One forum-specific problem, though, is that your backslashes have been swallowed by the forum. You'll need to put \\\[ instead of \[ when posting comments here.

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Slashdotcoma   (6 posts)  Bio
Date Reply #5 on Thu 10 May 2018 04:15 AM (UTC)

Amended on Thu 10 May 2018 05:00 AM (UTC) by Slashdotcoma

Message
Hi,

I've gone through the code and mad the changes you've pointed out.

- Yes, the number of characters for Str, Int, Wis, are uniform (being 11,10, & 12 characters long).
- Thanks for pointing out to use uniform case.
- With where to use = vs. ==, this makes of sense, although I had thought it applied to ' vand " also.

I hope you able to see what i'm doing with the trigger, in so far as, for example, Str (Strength) can have many values, which are supplied by the mud as text. For the character type (cleric) I've selected, the 4 highest possible values are "Powerful", "Strong", "Potent" and "Muscular". From the reading I've done, trying roll for a character with the best possible stats, can be very time consuming. So, the point of this trigger is to roll for character stats, that will be pretty darn good, rather than perfect.

This is what I have so far. I'm a bit lost as to why it doesn't "trigger".


<triggers>
  <trigger
   enabled="y"
   ignore_case="y"
   lines_to_match="2"
   keep_evaluating="y"
   match="^  Str  \[(...........)\]  Int  \[(..........)\]  Wis  \[(............)\]\n  Dex  \[(...........)\]  Con  \[(..........)\]  Cha  \[(............)\]$"
   multi_line="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>Str = Trim("%1")
Int = Trim("%2")
Wis = Trim("%3")
Dex = Trim("%4")
Con = Trim("%5")
Cha = Trim("%6")

if Str == "Powerful" or 
   Str == "Strong" or 
   Str == "Potent" or 
   Str == "Muscular"
then
   YStr = "Yes"
end

if Int == "Genius" or 
   Int == "Gifted" or 
   Int == "Brilliant"
then
   YInt = "Yes"
end

if Wis == "Shrewd" or
   Wis == "Crafty"
then
   YWis = "Yes"
end

if Dex == "Agile" or
   Dex == "Nimble" or
   Dex == "Smooth" or
   Dex == "Adroit"
then
   YDex = "Yes"
end

if Con == "Sturdy" or
   Con == "Hardy" or
   Con == "Husky"
then
   YCon = "Yes"
end

if Cha == "Gorgeous" or
   Cha == "Stunning" or
   Cha == "Charming"
then
   YCha = "Yes"
end

if YStr == "Yes" and 
   YInt == "Yes" and 
   YWis == "Yes" and 
   YDex == "Yes" and 
   YCon == "Yes" and 
   YCha == "Yes"
then 
    Send = "n"
else
    Send = "y"
end
</send>
  </trigger>
</triggers>
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #6 on Thu 10 May 2018 09:39 AM (UTC)
Message
Fiendish said:

I also removed the "-- if" comments because I don't find them particularly helpful ...


Personally I use them a lot because when you see this:


    end
  end
end


It is more helpful to read:


    end  -- if still alive
  end  -- while loop
end  -- function foo


Particularly when you want to put something in the loop, but outside the test if you are still alive. Without the comments it is very very easy to put new code in the wrong place.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Slashdotcoma   (6 posts)  Bio
Date Reply #7 on Thu 10 May 2018 10:17 AM (UTC)
Message
Ni Nick,

Ok, multiple comments here...


-- text here


so.... -- is a comment tag?

therefore, and it does make sense, especially with "nested" if statements, to have a comment tag at the end of each end statement, like...


if Str == "Powerful" or 
   Str == "Strong" or 
   Str == "Potent" or 
   Str == "Muscular"
then
   YStr = "Yes"
end -- end Str if

if Int == "Genius" or 
   Int == "Gifted" or 
   Int == "Brilliant"
then
   YInt = "Yes"
end -- end Int if


Other than getting involved in forum politics, are you able to assist with my trigger please Nick? :D
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #8 on Thu 10 May 2018 09:31 PM (UTC)

Amended on Thu 10 May 2018 09:32 PM (UTC) by Nick Gammon

Message
Don't worry about forum politics - Fiendish and I understand each other. :)

Yes, the "--" symbol makes the rest of the line a comment (unless it is inside a string literal of course).

Quote:

This is what I have so far. I'm a bit lost as to why it doesn't "trigger".


You had two possible problems here, either the trigger didn't trigger (match), or it did trigger, however the code doesn't do what you wanted it to do.

I added the line:


print "** matched **"


... to the start of the code, and on your example trigger, it was printed. So the issue is in what the code does.

It could be helpful to add something to the end, where you print something like "Stats rejected" if you decide not to use them, then at least you get feedback.

Now, what is this supposed to do?


if YStr == "Yes" and 
   YInt == "Yes" and 
   YWis == "Yes" and 
   YDex == "Yes" and 
   YCon == "Yes" and 
   YCha == "Yes"
then 
    Send = "n"
else
    Send = "y"
end


All that does is set a variable ("Send") - it doesn't send anything. Unless you are doing the sending somewhere else, this needs to look like:


if YStr == "Yes" and 
   YInt == "Yes" and 
   YWis == "Yes" and 
   YDex == "Yes" and 
   YCon == "Yes" and 
   YCha == "Yes"
then 
    Send ("n")
else
    Send ("y")
    print ("** Stats rejected **")
end


A function like Send has to be called, which means you have to follows its name by brackets, and any argument(s) to the function go inside the brackets.

In fact what your code has done is replaced the function Send with a string Send, which means it won't work until you close that world and re-open it.




The other problem I see is that your variables YStr and so on are only set to "Yes" on a positive match, but are left at their former value on a negative match. So what this would do is accept the stats once you got a positive match on all the stats, but not necessarily in the same roll.

What would be better would be to make them a boolean value, and set it to true or false, like this:

Instead of:


if Str == "Powerful" or 
   Str == "Strong" or 
   Str == "Potent" or 
   Str == "Muscular"
then
   YStr = "Yes"
end


Have:


YStr =  Str == "Powerful" or 
        Str == "Strong" or 
        Str == "Potent" or 
        Str == "Muscular"


Now YStr will be true if all those match, and false otherwise. Ditto for the others. Then at the end just test all of them:


if YStr and 
   YInt and 
   YWis and 
   YDex and 
   YCon and 
   YCha 
then 
    Send ("n")
else
    Send ("y")
    print ("** Stats rejected **")
end





Try not to make your stat roller too desperate for good stats. It could just sit there rejecting rolls for hours until an admin notices you are consuming a lot of their bandwidth and kicks you off.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Slashdotcoma   (6 posts)  Bio
Date Reply #9 on Fri 11 May 2018 03:52 AM (UTC)

Amended on Fri 11 May 2018 03:53 AM (UTC) by Slashdotcoma

Message
Hi,

I'm made the changes you've suggested and the trigger is working well, and I really like the Print command you've put in there.

In regards to your comment:

Quote:

Try not to make your stat roller too desperate for good stats. It could just sit there rejecting rolls for hours until an admin notices you are consuming a lot of their bandwidth and kicks you off.


Currently, I get booted from the mud after approx. 100 rolls. How do I put a pause of 1/2 second after each roll? I thought I'd try pausing for 1 second, to test, before trying for 1/2 a second (ie. adding a decimal).

I tried:


    print ("** Stats rejected **")
    wait (1)
    Send ("y")


Which causes the following error, on that line.


Error number: 0
Event:        Run-time error
Description:  [string "Trigger: "]:70: attempt to call global 'wait' (a table value)

stack traceback:

	[string "Trigger: "]:70: in main chunk
Called by:    Immediate execution
Top

Posted by Fiendish   USA  (2,534 posts)  Bio   Global Moderator
Date Reply #10 on Fri 11 May 2018 04:06 AM (UTC)
Message
You want

DoAfter(0.5, "y")

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #11 on Fri 11 May 2018 07:18 AM (UTC)

Amended on Fri 11 May 2018 07:24 AM (UTC) by Nick Gammon

Message

You might want to seriously look at this: The Secretary problem.

The problem is hiring the best secretary when you have n candidates, and after you interview each one you have to immediately accept or reject them (like the stats roll).

The solution is apparently to interview n/e (e being roughly 2.718281828459) candidates, noting their stats and then rejecting them, and after that hire the next one which is better than the ones you interviewed.

So in your case, if you can do 100 rolls, total up their stats (turn them into a number) and after 100/e rolls (37 rolls in other words) then accept the next roll that is better than the first 37.

This strategy works around the problem of your having a limited number of rolls, and also means you don’t have to decide exactly what stats you want. It will give you the best stats 37% of the time. You may say, of course, but I want the best stats over 1000 rolls, but the best stats may have shown up in roll #1, and it is too late to go back and accept it.

To put it another way, even if you did 1000000 rolls, and had to stop at the last one, the last one might be quite bad, but roll 800000 was much better (and you might never achieve the stats you have specified in your script, even after a billion rolls).


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Slashdotcoma   (6 posts)  Bio
Date Reply #12 on Wed 16 May 2018 07:18 AM (UTC)
Message
Here is the trigger I ended up using to get a Character with decent stats.


<triggers>
  <trigger
   ignore_case="y"
   lines_to_match="2"
   keep_evaluating="y"
   match="^  Str  \[(...........)\]  Int  \[(..........)\]  Wis  \[(............)\]\n  Dex  \[(...........)\]  Con  \[(..........)\]  Cha  \[(............)\]$"
   multi_line="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>require "wait"

Str = Trim("%1")
Int = Trim("%2")
Wis = Trim("%3")
Dex = Trim("%4")
Con = Trim("%5")
Cha = Trim("%6")

YStr = "No"
YInt = "No"
YWis = "No"
YDex = "No"
YCon = "No"
YCha = "No"

if Str == "Powerful" or 
   Str == "Strong" or 
   Str == "Potent" or 
   Str == "Muscular" or
   Str == "Sinewy" or
   Str == "Wiry" or
   Str == "Vigorous"
then
   YStr = "Yes"
end

if Int == "Genius" or 
   Int == "Gifted" or 
   Int == "Brilliant" or
   Int == "Exceptnl" or
   Int == "Intellignt" or
   Int == "Clever" or
   Int == "Smart"
then
   YInt = "Yes"
end

if Wis == "Shrewd" or
   Wis == "Crafty" or
   Wis == "Keen"
then
   YWis = "Yes"
end

if Dex == "Agile" or
   Dex == "Nimble" or
   Dex == "Smooth" or
   Dex == "Adroit" or
   Dex == "Deft"
then
   YDex = "Yes"
end

if Con == "Sturdy" or
   Con == "Hardy" or
   Con == "Husky" or
   Con == "Healthy"
then
   YCon = "Yes"
end

if Cha == "Gorgeous" or
   Cha == "Stunning" or
   Cha == "Charming" or
   Cha == "Comely" or
   Cha == "Attractive" or
   Cha == "Appealing" or
   Cha == "Average" or
   Cha == "Plain" or
   Cha == "Below Avg" or
   Cha == "Unattractive" or
   Cha == "Ugly"
then
   YCha = "Yes"
end

if YStr == "Yes" and 
   YInt == "Yes" and 
   YWis == "Yes" and 
   YDex == "Yes" and 
   YCon == "Yes" and 
   YCha == "Yes"
then 
    Send ("n")
else
    print ("** Stats rejected **  ", YStr, "  ", YInt, "  ", YWis, "  ",  YDex, "  ", YCon, "  ", YCha)
    DoAfter(0.25,"y")
end
</send>
  </trigger>
</triggers>
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.


28,632 views.

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

Go to topic:           Search the forum


[Go to top] top

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