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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  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] Refresh page


Posted by forral   USA  (79 posts)  [Biography] 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
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] 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
[Go to top] top

Posted by forral   USA  (79 posts)  [Biography] 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.
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] 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
[Go to top] top

Posted by forral   USA  (79 posts)  [Biography] 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
[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.


13,766 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]