[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]  General
. . -> [Subject]  can't figure out GetWorld

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

can't figure out GetWorld

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


Posted by Sgbarter   (6 posts)  [Biography] bio
Date Thu 24 Jul 2008 06:29 PM (UTC)  quote  ]
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
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Thu 24 Jul 2008 11:37 PM (UTC)  quote  ]

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
[Go to top] top

Posted by Sgbarter   (6 posts)  [Biography] bio
Date Reply #2 on Sat 26 Jul 2008 08:41 PM (UTC)  quote  ]
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.
[Go to top] top

Posted by Sgbarter   (6 posts)  [Biography] bio
Date Reply #3 on Sat 26 Jul 2008 08:52 PM (UTC)  quote  ]
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>
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Sat 26 Jul 2008 10:22 PM (UTC)  quote  ]
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
[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,205 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]