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 ➜ Lua ➜ Trouble with alias dieroller

Trouble with alias dieroller

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


Posted by Silencher   (55 posts)  Bio
Date Thu 01 May 2014 03:14 AM (UTC)
Message
Hello,

I made a sort of simple dieroller just out of boredom as an alias. It works fine if I do a simple #d# roll, but if I try to add a bonus or penalty, it doesn't work.

mydice *d* <--original alias
if I did: 1d10
My output would be:
1d10 rolled 5 (or some other number besides 5)

But with:
mydice *d* + * <---'upgraded' alias
If I do my output as 1d10 + 3
My output is:
1d13 rolled 5 (or some other number between 1->13)

What I want is for it to literally do 1d10, then add 3. But that isn't happening.

Below is the body of my alias, can you tell me what is wrong? I think it has to do with me using the '+' in the actual alias command, so maybe I need a way for Lua to ignore that + somehow, so it doesn't add %2 and %3 together?

--body of alias below--
math.randomseed(os.time())
math.random()
numberOfDice = %1
dieSides = %2
result = (math.floor (MtRand () * dieSides) +1)
sum = 0
for i = 1, numberOfDice, 1 do
roll = (math.floor (MtRand () * dieSides) +1)
sum = roll + sum
end
bonus = %3
sum = sum + bonus
Note(numberOfDice .. "d" .. dieSides .. " rolled " .. sum)

--end body of alias--
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #1 on Thu 01 May 2014 05:54 AM (UTC)
Message
Can you post the actual alias please?

Template:copying For advice on how to copy aliases, timers or triggers from within MUSHclient, and paste them into a forum message, please see Copying XML.

- Nick Gammon

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

Posted by Silencher   (55 posts)  Bio
Date Reply #2 on Thu 01 May 2014 06:09 AM (UTC)

Amended on Thu 01 May 2014 06:20 AM (UTC) by Nick Gammon

Message

<aliases>
  <alias
   match="mydice *d* + *"
   enabled="y"
   group="testing"
   send_to="12"
   sequence="100"
  >
  <send>math.randomseed(os.time())
math.random() 
numberOfDice = %1
dieSides = %2
result = (math.floor (MtRand () * dieSides) +1)
sum = 0
for i = 1, numberOfDice, 1 do
   roll = (math.floor (MtRand () * dieSides) +1)
   sum = roll + sum
end
bonus = %3
sum = sum + bonus
Note(numberOfDice .. "d" .. dieSides .. " rolled " .. sum)</send>
  </alias>
</aliases>
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #3 on Thu 01 May 2014 06:24 AM (UTC)
Message
I tried your alias out, unchanged, and got this:


mydice 1d10 + 3



1d10 rolled 4
1d10 rolled 11
1d10 rolled 8
1d10 rolled 6
1d10 rolled 8
1d10 rolled 13
1d10 rolled 10
1d10 rolled 7
1d10 rolled 12
1d10 rolled 7
1d10 rolled 7
1d10 rolled 13
1d10 rolled 9


That seems to be working, yes?

Some of the rolls are over 10, which shows that adding 3 is happening.

Quote:

But that isn't happening.


Can you post what you entered, and what you got?





math.randomseed(os.time())
math.random() 


That doesn't do anything, since MtRand does not use math.randomseed.

- Nick Gammon

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

Posted by Silencher   (55 posts)  Bio
Date Reply #4 on Thu 01 May 2014 01:13 PM (UTC)
Message
Oh I see why. I have that alias, but also the original alias:

mydice *d*

If I remove mydice *d* I can't do regular rolls. 1d10.

Is there a way to alter this into one alias that would somehow catch the + and/or - and not add/subtract %2 and %3 together?

mydice *d* is the same as the other alias I posted, except there's no 'bonus' in it. So that 2nd * is catching everything as just %2, rather than %2 + %3.

Basically I need to have the + in the alias not be an operator, I think.
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #5 on Thu 01 May 2014 07:59 PM (UTC)
Message
Template:faq=50 Please read the MUSHclient FAQ - point 50.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
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.


17,723 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.