Switching worlds from command line MultiWorld

Posted by Cyote on Tue 20 Oct 2015 05:38 PM — 4 posts, 19,246 views.

#0
Hi,

Is there a way to send commands directly from commandline or switching worlds with commands without using accelerator keys like zmud/cmud/tintin style??

Thank you.
USA Global Moderator #1
Quote:
without using accelerator keys

Why without?
Australia Forum Administrator #2
You need a "world reference" which you can get by name or world ID code. Safer is the ID string, because that won't change if you rename the world. With scripting enabled, and "/" as the "script" character, type:


/print ( GetWorldID () )


(Or use the Immediate Window (Ctrl+I) and leave out the slash.

You should see something like this in your output window:


f52a5090c219b0efebe1b521


That is the "world ID" (in my case, for my test world).

Now you can, in the command window (and again, assuming scripting is active and you have "/" as the scripting prefix) type:


/GetWorldById ("f52a5090c219b0efebe1b521"):Activate ()


That gets a "world reference" to that particular ID, and then calls the Activate function for that world, bringing that world to the front.

To switch back, you need the ID of the other word, eg.


/GetWorldById ("8c1e6fc91017ec9408ced4c0"):Activate ()





Template:function=GetWorldID
GetWorldID

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



Template:function=GetWorldById
GetWorldById

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



Template:function=Activate
Activate

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






Now you can make an alias, if wanted, to save all that typing, eg.


<aliases>
  <alias
   match="world3"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>GetWorldById ("f52a5090c219b0efebe1b521"):Activate ()</send>
  </alias>
</aliases>


Template:pasting
For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.





This simple approach will give an error message if the wanted world is not open. You could make the alias "smarter" and test if GetWorldById returns nil or not:


<aliases>
  <alias
   match="world3"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>

local w = GetWorldById ("f52a5090c219b0efebe1b521")

if w then
  w:Activate ()
else
  ColourNote ("red", "", "Requested world is not available")
end

</send>
  </alias>
</aliases>


Template:pasting
For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.
Amended on Tue 20 Oct 2015 07:58 PM by Nick Gammon
Australia Forum Administrator #3
If you have short and easily-remembered world names (in the configuration dialog -> General -> IP address part) then you could use the name, like this:


/GetWorld ("smaug2"):Activate ()


Then you could make a single alias that takes a wildcard, and substitute that into the GetWorld part, and have it switch to any world.