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

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Identifying Active World

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: Identifying Active World
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please)
Maximum of 6000 characters. Text only please, no HTML.
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Posted by Nick Gammon   Australia  (18,769 posts)  [Biography] bio   Forum Administrator
Date Mon 29 Jan 2007 01:39 AM (UTC)  quote  ]
Message
Quote:

I've got a trigger that ends up sending a message to all open worlds ...


In case you haven't done so already, this is a good candidate for a small plugin. That way, if you make amendments, you only have to make them once.

Then you could go to Global Preference -> Plugins, and make that a global plugin, so it is automatically loaded into every world.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Balerion   (18 posts)  [Biography] bio
Date Sun 28 Jan 2007 08:55 PM (UTC)  quote  ]
Message
Thanks again, Nick. That was silly of me, heh. I think I'm getting more of a grasp of LUA now. Will have to ponder what sort of nifty things I'll want to do with it.
[Go to top] top

Posted by Nick Gammon   Australia  (18,769 posts)  [Biography] bio   Forum Administrator
Date Sat 27 Jan 2007 09:43 PM (UTC)  quote  ]
Message
You are comparing two different types of things here, one is a world userdatum, one is the world ID. For example:


foo = GetWorldID ()
print (foo) --> ba5f85fd5e7c9ab5a8f62f3d


You want to change:


if w ~= foo then


to:


if v ~= foo then


In this case "v" is the ID from GetWorldIdList, so you are now comparing an ID to an ID.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Balerion   (18 posts)  [Biography] bio
Date Sat 27 Jan 2007 12:18 PM (UTC)  quote  ]
Message
Thanks, Nick. That's done the trick. I realize that I need one more wrinkle in there: how do I have it _not_ send the notice if I receive the message in the active world? No real point for it to notify me if I'm looking right at it.

I figured something of this sort might work, but it doesn't for some reason:

local foo
foo = GetWorldID ()
for k, v in pairs (GetWorldIdList ()) do
w = GetWorldById (v) -- world userdatum
if isActive (w) then -- is it active?
if w ~= foo then
w:ColourNote ("red", "white", message)
end -- if
end -- if
end -- for

Nothing seems to break, but it seems to always come out that w (active world) and foo ('current world', which I'm assuming is the world triggering the script?) are not equal even when this is not true.
[Go to top] top

Posted by Nick Gammon   Australia  (18,769 posts)  [Biography] bio   Forum Administrator
Date Sat 27 Jan 2007 03:40 AM (UTC)  quote  ]

Amended on Sat 27 Jan 2007 03:45 AM (UTC) by Nick Gammon

Message
This test routine worked for me. For all open worlds it displays a message showing the world name, and whether it is active or not:


message = "test"
for k, v in pairs (GetWorldIdList ()) do
  w = GetWorldById (v)  -- world userdatum
  w:Tell (w:WorldName() .. ": ")
  w:Tell (tostring (w:GetInfo (113)) .. ": ")
  w:ColourNote ("red", "white", message)
end -- for


I would also take the the comma you have in "white,".

Now using that idea, we can write the loop like this:


message = "test"

for k, v in pairs (GetWorldIdList ()) do
  w = GetWorldById (v) -- world userdatum
  if w:GetInfo (113) then  -- is it active?
    w:ColourNote ("red", "white", message)
  end -- if
end -- for


If you want to keep your separate isActive function, you could write it like this:


function isActive (w)
  if w then
    return w:GetInfo (113)
  else
    return GetInfo (113)
  end -- if
end -- function isActive 

message = "test"

for k, v in pairs (GetWorldIdList ()) do
  w = GetWorldById (v)  -- world userdatum
  if isActive (w) then  -- is it active?
    w:ColourNote ("red", "white", message)
  end -- if
end -- for


You have to pass down to isActive which world is the one whose activity you are testing for.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Balerion   (18 posts)  [Biography] bio
Date Fri 26 Jan 2007 11:24 PM (UTC)  quote  ]
Message
I've just started digging into MUSHclient's scripting capabilities after a number of years of using it. I started with VBScript, but given Nick's recommendation of LUA for scripting novices, it seemed the wiser choice. I've managed quite a few of the things I wanted to do, but I'd like to refine it if possible.

I've got a trigger that ends up sending a message to all open worlds (I always run several) when it's run -- basically, notifying me that I've been contacted on said world. What I'd like to do is have it send only to the active world. What I'm using to send to all worlds is this:

function SendToAllWorlds (message)

for k, v in pairs (GetWorldIdList ()) do
GetWorldById (v):ColourNote ("red","white,",message)
end

What I'd like to do is something like this instead:

function SendToActiveWorld (message)

for k, v in pairs (GetWorldIdList ()) do
if GetWorldById (v):isActive() then
GetWorldById (v):ColourNote ("red","white,",message)
end
end

Where isActive() is something that uses GetInfo(113), I guess (I suspect this may be a place where I'm going wrong):

function isActive ()

GetInfo(113)
end

What's happening right now is that I get this error message when the trigger's script tries to execute:

[string "Script file"]:676: attempt to call method `isActive' (a nil value)
stack traceback:
[string "Script file"]:676: in function `SendToActiveWorld'
[string "Trigger: "]:2: in main chunk

Any pointers much appreciated.
[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.


1,301 views.

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]