How to change focus to another already opened world window through scripting?

Posted by VBMeireles on Wed 27 Jan 2016 02:29 PM — 4 posts, 17,571 views.

Brazil #0
I have a couple of world windows open.

If I want to go to another world window I can either:

a. click its window;
b. click the Window menu and then the world I want to go to;
c. hit ALT+W and then the number of the world I want to go to (which is the same thing but using only the keyboard) or
d. hit CTRL+TAB or CTRL+SHIFT+TAB to cycle through opened worlds until I get to the one I want.

However, I'd like to be able to change focus through use of a script command. For example: ChangeFocusToWorldWindow("worldWindowId").

Is that possible? Does such a function exist? I wasn't able to find any that would do it from the alphabetical list.
Australia Forum Administrator #1
Using Lua scripting (the default) an alias like this will do it:


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

wantedWorldID = "f52a5090c219b0efebe1b521"  -- or whatever

w = GetWorldById (wantedWorldID)  -- get userdata item for wanted world

-- if not found, bail out
if not w then 
  ColourNote ("red", "", "Wanted world not open")
  return 
end  -- if

-- activate (set the focus to) that world
w:Activate ()

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



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


I made an alias "foo" to do it, but those same lines could be in a script somewhere.

To find the current world ID execute this script command:


print (GetWorldID ( ))
Brazil #2
Would I run into problems by calling GetWorldById("worldIdString"):Activate() directly?
Australia Forum Administrator #3
You would if the world wasn't open because you would be attempting to call a function from a nil userdata. It is probably safer to have the test in-between.