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
➜ can't figure out GetWorld
|
can't figure out GetWorld
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Sgbarter
(6 posts) Bio
|
| Date
| Thu 24 Jul 2008 06:29 PM (UTC) |
| Message
| What is the world "name" referring to when using the GetWorld function?
I'm trying to use that function but I always get nil world.
The world name above where the IP address goes is cp_info. The file name for the world is cp_info.mcl. But whenever I pass "cp_info" to GetWorld it comes back nil.
This is what I'm using...
SendToWorld ("cp_info", Note("Hey"))
function SendToWorld (name, message)
local otherworld
otherworld = GetWorld (name)
if otherworld == nil then
Note ("World " .. name .. " is not open")
return
end
Send (otherworld, message)
-- alternative syntax: otherworld:Send (message)
end -- of SendToWorld
| | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #1 on Thu 24 Jul 2008 11:37 PM (UTC) Amended on Thu 24 Jul 2008 11:38 PM (UTC) by Nick Gammon
|
| Message
| Is the cp_info world actually open when you run this code? GetWorld only returns a reference to an open world, it doesn't open one on disk.
In the getworld.lua file which ships with recent versions of MUSHclient there is a "get_a_world" function that attempts to open the world file if it is not already open.
In that case you would do:
require "getworld"
otherworld = get_a_world (name)
Quote:
What is the world "name" referring to when using the GetWorld function?
You are correct, it is the world name which appears above the IP address. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Sgbarter
(6 posts) Bio
|
| Date
| Reply #2 on Sat 26 Jul 2008 08:41 PM (UTC) |
| Message
| This is really strange now.
BTW, I am using the Aardwolf mushclient, and all the included plugins are working fine (eg: stats, map, bigmap).
I started using get_a_world. It will open the world if it's not already open, BUT when it tries to use the Note() function to send to that world it comes back with World not open, or this message: Can't open world file: C:\Users\Sgbarter\Program Files\MUSHclient\worlds\Aardwolf\.mcl
(Notice it doesn't have the world name in the path?)
I have this code in the main lua script file, which I assume should be okay. The aardwolf plugins using the same functions are working, and the only difference with my code is that it's not a plugin.
| | Top |
|
| Posted by
| Sgbarter
(6 posts) Bio
|
| Date
| Reply #3 on Sat 26 Jul 2008 08:52 PM (UTC) |
| Message
| I made a plugin, so it should be easier to show the exact code I'm trying to use:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Saturday, July 26, 2008, 4:43 PM -->
<!-- MuClient version 4.33 -->
<!-- Plugin "Cpinfo" generated by Plugin Wizard -->
<muclient>
<plugin
name="Cpinfo"
id="0f494a9207703ffb09f71c03"
language="Lua"
save_state="y"
date_written="2008-07-26 16:42:39"
requires="4.33"
version="1.0"
>
</plugin>
<!-- Get our standard constants -->
<include name="constants.lua"/>
<!-- Triggers -->
<triggers>
<trigger
enabled="y"
match="^You are friends with \:"
omit_from_output="y"
regexp="y"
script="funsend_to_world"
send_to="14"
sequence="100"
>
<send>funsend_to_world("Cpinfo","HEY")
</send>
</trigger>
</triggers>
<!-- Script -->
<script>
<![CDATA[
function funsend_to_world(worldname, message)
require "getworld"
wname = worldname
folder = "Aardwolf"
local otherworld = get_a_world(wname, folder)
otherworld:DeleteOutput()
otherworld:Note (message)
end -- funsend_to_world
]]>
</script>
</muclient>
| | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #4 on Sat 26 Jul 2008 10:22 PM (UTC) |
| Message
| Ah, you had be puzzled for a while there.
This is how I worked it out. I changed your function to display the world name it got:
function funsend_to_world(worldname, message)
require "getworld"
wname = worldname
folder = "Aardwolf"
print ("worldname=", worldname, "wname=", wname)
local otherworld = get_a_world(wname, folder)
otherworld:DeleteOutput()
otherworld:Note (message)
end -- funsend_to_world
Forcing through a test line I saw this:
worldname= Cpinfo wname= Cpinfo
worldname= wname=
Can't open world file: C:\Program Files\MUSHclient\worlds\Aardwolf\.mcl
Run-time error
First time the world name was right, but what was the second time?
Then I spotted it. You are calling the script twice:
<triggers>
<trigger
enabled="y"
match="^You are friends with \:"
omit_from_output="y"
regexp="y"
script="funsend_to_world"
send_to="14"
sequence="100"
>
<send>funsend_to_world("Cpinfo","HEY")
</send>
</trigger>
</triggers>
If you are using "send to script" you don't also place the function name in the script box.
Delete the line:
script="funsend_to_world"
That was calling your function without sending "cpinfo" down to it, and thus it couldn't open the world.
|
- 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.
16,876 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top