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 ➜ How to call a variable inside this function.

How to call a variable inside this function.

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


Posted by CrazyPaladin   (12 posts)  Bio
Date Thu 19 Mar 2015 05:50 PM (UTC)

Amended on Thu 19 Mar 2015 05:55 PM (UTC) by CrazyPaladin

Message
Hello! This is my modified version of Nick's chat script. Just needing to know how I can call my "port" variable in the script portion, so that I'll get...

(portvariable)<string>

...over in my chats window.

Thank you for your help!


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Saturday, June 30, 2007, 10:48  -->
<!-- MuClient version 4.13 -->

<!-- Plugin "Chat_Redirector" generated by Plugin Wizard -->

<!--
Edit plugin and change "chat_world" variable to be the name of the 
world you want chats to go to.
-->

<muclient>
<plugin
   name="Chat_Redirector"
   author="Nick Gammon"
   id="cb84a526b476f69f403517da"
   language="Lua"
   purpose="Redirects chat messages to another world"
   date_written="2007-06-30 10:45:35"
   requires="4.08"
   version="1.0"
   >
<description trim="y">
<![CDATA[
Redirects chats to the specified world.

Add or modify "chat" triggers to capture different sorts of message.

Change the variable "chat_world" to be the name of the world chats are to go to.
]]>
</description>

</plugin>

<!--  Triggers  -->

<triggers>

  <trigger
   enabled="y"
   match="(tell|tells) the group '.+'$"
   omit_from_output="n"
   regexp="y"
   script="redirect"
   sequence="100"
  >
  </trigger>

  <trigger
   enabled="y"
   match="(^|>)([A-Za-z]+|A cloaked figure|a cloaked figure) (tell|tells|reply|replies|mutter|mutters|answer|answers|question|questions|yell|yells|whine|whines|gossip|gossips|auction|auctions).+\'.+\'"
   omit_from_output="n"
   regexp="y"
   script="redirect"
   sequence="100"
  >
  </trigger>

  <trigger
   enabled="y"
   match="(^|>)\(ck\) ([A-Za-z]+|A cloaked figure|a cloaked figure) (tell|tells|reply|replies|mutter|mutters|answer|answers|question|questions|yell|yells|whine|whines|gossip|gossips|auction|auctions).+\'.+\'"
   omit_from_output="n"
   regexp="y"
   script="redirect"
   sequence="100"
  >
  </trigger>

</triggers>

<!--  Aliases  -->

<aliases>

  <alias
   match="port *"
   enabled="y"
   variable="port"
   send_to="9"
   sequence="100"
  >
  <send>%1</send>
  </alias>

</aliases>


<!--  Script  -->


<script>
<![CDATA[
chat_world = "RoD chats"
local first_time = true

function redirect (name, line, wildcards, styles)

  -- try to find "chat" world
  local w = GetWorld (chat_world)  -- get "chat" world

  -- if not found, try to open it
  if first_time and not w then
    local filename = GetInfo (67) .. chat_world .. ".mcl"
    Open (filename)
    w = GetWorld (chat_world)  -- try again
    if not w then
      ColourNote ("white", "red", "Can't open chat world file: " .. filename)
      first_time = false  -- don't repeatedly show failure message
    end -- can't find world 
  end -- can't find world first time around

  if w then  -- if present
    for _, v in ipairs (styles) do
      w:ColourTell (RGBColourToName (v.textcolour), 
                    RGBColourToName (v.backcolour), 
                    v.text)  
    end -- for each style run
    w:Note ("")  -- wrap up line

  end -- world found

end -- function redirect 

]]>
</script>


</muclient>
Top

Posted by Nick Gammon   Australia  (23,166 posts)  Bio   Forum Administrator
Date Reply #1 on Thu 19 Mar 2015 07:30 PM (UTC)
Message
Template:function=GetVariable GetVariable

The documentation for the GetVariable script function is available online. It is also in the MUSHclient help file.


- Nick Gammon

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

Posted by CrazyPaladin   (12 posts)  Bio
Date Reply #2 on Thu 19 Mar 2015 08:44 PM (UTC)
Message
So...


if w then  -- if present
    local port
    port = GetVariable("port")
      if port == nil then
        Note ("port is not defined")
      end
    for _, v in ipairs (styles) do
      w:ColourTell (RGBColourToName (v.textcolour), 
                    RGBColourToName (v.backcolour), 
                    v.text)
      end -- for each style run
    w:Note ("")  -- wrap up line

  end -- world found


But how do I go about getting it to add to the beginning of the "v.text". I do not know lua, and have only thus far made more triggers for the Triggers section. I don't even begin to understand this part, so just trying to muddle through. I'm sure its easy to you, but I am lost.
Top

Posted by Nick Gammon   Australia  (23,166 posts)  Bio   Forum Administrator
Date Reply #3 on Fri 20 Mar 2015 07:14 AM (UTC)
Message
You concatenate with "..", so it might look like this:


      w:ColourTell (RGBColourToName (v.textcolour), 
                    RGBColourToName (v.backcolour), 
                    port .. v.text)

- Nick Gammon

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

Posted by CrazyPaladin   (12 posts)  Bio
Date Reply #4 on Fri 20 Mar 2015 03:33 PM (UTC)
Message
Its getting there, but it now puts the "port" variable at the beginning of each color change.


  if w then  -- if present
    local port
    port = GetVariable("port")
      if port == nil then
        Note ("port is not defined")
      end
    for _, v in ipairs (styles) do
      w:ColourTell (RGBColourToName (v.textcolour), 
                    RGBColourToName (v.backcolour), 
                    port .. v.text)
      end -- for each style run
    w:Note ("")  -- wrap up line

  end -- world found


Gives this, after making the "port" variable "Live". Left side is output from the MUD, right side is the RoD Chats window the script is dumping too.

http://imgur.com/uu5EWWn
Top

Posted by Nick Gammon   Australia  (23,166 posts)  Bio   Forum Administrator
Date Reply #5 on Fri 20 Mar 2015 08:50 PM (UTC)
Message
Oh yeah, well just move things around:



  if w then  -- if present
    local port
    port = GetVariable("port")
      if port == nil then
        Note ("port is not defined")
      end
    Tell (port)
    for _, v in ipairs (styles) do
      w:ColourTell (RGBColourToName (v.textcolour), 
                    RGBColourToName (v.backcolour), 
                    v.text)
      end -- for each style run
    w:Note ("")  -- wrap up line

  end -- world found


- Nick Gammon

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

Posted by CrazyPaladin   (12 posts)  Bio
Date Reply #6 on Fri 20 Mar 2015 11:32 PM (UTC)
Message
Almost, but managed to figure out the last bit. "Tell (port)" puts the port in the MUD window, so I did "w:Tell (port)" and it WORKED!!! Thank you so very much, Nick! Much appreciated!


  if w then  -- if present
    local port
    port = GetVariable("port")
      if port == nil then
        Note ("port is not defined")
      end
    w:Tell (port)
    for _, v in ipairs (styles) do
      w:ColourTell (RGBColourToName (v.textcolour), 
                    RGBColourToName (v.backcolour), 
                    v.text)
      end -- for each style run
    w:Note ("")  -- wrap up line

  end -- world found
Top

Posted by Nick Gammon   Australia  (23,166 posts)  Bio   Forum Administrator
Date Reply #7 on Sat 21 Mar 2015 12:53 AM (UTC)
Message
That sounds right, glad it's working.

- 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.


27,217 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.