Opening worlds from plugins.

Posted by Poromenos on Wed 28 May 2003 10:32 PM — 11 posts, 35,351 views.

Greece #0
How can i connect to a world from another world's plugin? I need to find a way for one char to load another when he needs him.
Australia Forum Administrator #1
You mean create a new world? Open an existing one (on disk)? Connect to one that is already open?
Greece #2
Opening one and controlling it would be best, but if that's not possible, connecting to an already open world is fine.
Australia Forum Administrator #3
Just open that character's world file, see world.Open. I would now store the world's ID instead of the name and use world.GetWorldById later on in the controlling world to get back the "reference" to the world object. Once you have that you can use it to control it. See the example in world.GetWorldById for how you would do that.
Greece #4
Oh great, that's exactly what I wanted, thanks!
#5
In regards to this topic, is there also a way to close the world when finished? I can use commands to log off the world, but I don't know how to actually close it.

The problem that comes up is that sometimes I need to send world.open, but sometimes I need to send world.connect. If you do use world.connect, it seems you have to use world.DoAfter instead of just world.send because it sends so fast the world has not yet connected...
Australia Forum Administrator #6
Quote:

In regards to this topic, is there also a way to close the world when finished?



world.DoCommand "close"



Quote:

... it seems you have to use world.DoAfter instead of just world.send because it sends so fast the world has not yet connected


Yes, connecting is asynchronous, that is it takes time and is done in the background while the client does other things, otherwise the client would hang every time you opened a world. You need to build in a delay. Technically the script should wait until it is connected, see:

http://www.gammon.com.au/scripts/doc.php?function=IsConnected

You could make a timer that checks every couple of seconds to see if it is connected yet.
#7
Thanks, that ALMOST solved the problem. :-)

Now, my command sent to world don't have time to execute... I have a trigger that matches and then sends this:

world.activate
world.execute "save"
world.execute "quit"

world.DoCommand "save"
world.DoCommand "close"

For some reason, even if I do world.DoCommand "save", I still get the message asking if I want to save because internal variables have changed, but if I click save then it won't ask me this. Either way, I can turn that off in Global Preferences. The problem is that it doesn't give the mud time to accept "save" and "quit" before closing the world, leaving my character link-dead...

I tried world.DoAfter 3, "world.DoCommand "close""
but that gives end of line expected errors...
Any way around this...
Australia Forum Administrator #8
You want:


world.DoAfterSpecial (3, "world.DoCommand 'close'", 12)


You have to use different quotes (or double or escape the quotes) because you have quotes within quotes.

The 12 says "send to script engine".
#9
Parenthesis won't work...

Taking the parenthesis completely out gets past that part, but then it says world.doCommand is not a valid arguement...

Error number: -2146827839
Event: Execution of line 1 column 1
Description: Argument not optional: 'world.DoCommand'
Line in error:

Called by: Immediate execution
Australia Forum Administrator #10
OK, this is VBscript I gather. In that case you have to double the quotes:


world.DoAfterSpecial 3, "world.DoCommand ""close""", 12