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
➜ Selecting random items from a group
Selecting random items from a group
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| forral
USA (79 posts) Bio
|
Date
| Mon 17 May 2010 05:13 AM (UTC) Amended on Mon 17 May 2010 06:07 AM (UTC) by forral
|
Message
| Hi all,
I am, once again, trying to adapt some functionalities that I had on Portal over to MUSH, and one of the major things I have missing is my rotating clan-talk tags. By "rotating" I mean that I would supply a set of strings, and it would randomly choose the strings, thus making it seem as if it is "rotating" through that list.
In Portal, the code was simply |R(item1,item2,item3) etc. What is the proper way to emulate this in MUSH?
Thank you very much for all the patience with these novice questions, and the help this forum has provided. It truly is an invaluable resource!
Sincerely,
Forral | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #1 on Mon 17 May 2010 06:05 AM (UTC) |
Message
| To just send stuff you can do this:
stuff = {
"sigh",
"dance",
"laugh",
"sing",
}
Send (stuff [math.random (1, #stuff)])
The first part is a table of the things you want to choose from randomly.
Then the Send indexes into the table, using math.random to get a number from 1 (the first item) to #stuff (which is the number of items in the table).
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| forral
USA (79 posts) Bio
|
Date
| Reply #2 on Mon 17 May 2010 06:10 AM (UTC) Amended on Mon 17 May 2010 06:58 AM (UTC) by forral
|
Message
|
Nick Gammon said:
To just send stuff you can do this:
stuff = {
"sigh",
"dance",
"laugh",
"sing",
}
Send (stuff [math.random (1, #stuff)])
The first part is a table of the things you want to choose from randomly.
Then the Send indexes into the table, using math.random to get a number from 1 (the first item) to #stuff (which is the number of items in the table).
Wow Nick, thanks for the speedy response. Where would I put this though, in an alias? Send to world or script? and does it have to be called "stuff" or can I name it something like "ct"? My alias in portal was: ct
The command it executed was: clan talk |R(tag1,tag2,tag3,tag4)
*EDIT* Err, I should clarify that what I'm wanting to do is append these tags on the beginning of my clan talk alias, so if I type "ct test" it would say [X] clan members heard you say: tag1 test.....and I could keep sending that command and having random tags append before the actual test. | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #3 on Mon 17 May 2010 06:36 AM (UTC) |
Message
| That is a (Lua) script, so it would be in send to script.
The thing called "stuff" is just the table of things you choose randomly from. The alias itself would be called whatever you want to call it.
As for the appending, instead of sending you can set up a variable, eg.
x = stuff [math.random (1, #stuff)]
Now "x" is a randomly-chosen word.
If your alias had a wildcard in it, this becomes %1, so you could do this:
Send ("clan talk " .. x .. " %1")
Or something along those lines. The .. in Lua is string concatenation. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| forral
USA (79 posts) Bio
|
Date
| Reply #4 on Mon 17 May 2010 08:24 PM (UTC) |
Message
| Nick, you are amazing. As I was just replying to ask for more help, I had an epiphany, and it works perfect. For anyone else who might read this post (since I will reference it later on), put all the code in the alias.
In my case, my alias was: ct *
And in the box I have:
stuff = {
"|R/>|GF0rg3 |WWh0r3|R<\|C",
"|G4|Mplay|W",
"|M4|Rsome|Y",
"|rMino |RSlayer|W",
"|R-|G>|BCarter|G<|R-|W",
}
x = stuff [math.random (1, #stuff)]
Send ("clan talk " .. x .. " %1")
Was sent to script.
Thank you very much for this help Nick. Just another reason to cement my MUSHClient usage.
Sincerely,
Forral
| 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.
15,627 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top