world event script question

Posted by Guest1 on Tue 11 Jul 2006 02:43 AM — 7 posts, 24,143 views.

USA #0
Hey. Using v3.75. I have a sub that is run when the world is opened (Shift+Ctrl+6 and in the 'World Events' input boxes) ..when the world is opened it calls a sub called, wait for it, 'world_open'. The sub is used to generate and resize some notepad windows, resize the main MC window, and resize the world window. This is the sub:

sub world_open
   MoveMainWindow -1, -1, 1024, 741
   world.SendToNotepad "STATUS", "status window generated.."
   NotepadFont "STATUS", "WhiteRabbit", 9, 0, 0
   NotepadColour "STATUS", "#FAEBD7", "#000000"
   MoveNotepadWindow "STATUS", 690, 0, 322, 335
   world.SendToNotepad "GROUPSTATUS", "group status window generated.."
   NotepadFont "GROUPSTATUS", "WhiteRabbit", 9, 0, 0
   NotepadColour "GROUPSTATUS", "#FAEBD7", "#000000"
   MoveNotepadWindow "GROUPSTATUS", 690, 335, 322, 198
   world.SendToNotepad "TELLS", "tells window generated.."
   NotepadFont "TELLS", "Verdana", 8, 0, 0
   NotepadColour "TELLS", "#FAEBD7", "#000000"
   MoveNotepadWindow "TELLS", 690, 533, 322, 140
   MoveWorldWindow 0, 0, 690, 673
   world.activate
end sub


Everything works except the resize of the world window itself.. it retains whatever size it was at last time it was closed, and the above sub does not alter it..

If I create another sub on world connect instead of world open, for example:

sub world_resize
   MoveWorldWindow 0, 0, 690, 673
end sub


that works, but I want to use that world connect option for something else. I even tried adding a world.DoAfterSpecial into the world_open sub above, eg:

  world.DoAfterSpecial 1, "world_resize", 12


but nothing.. it seems world.DoAfterSpecial only runs when connected to a world.. any suggestions?
Amended on Tue 11 Jul 2006 02:56 AM by Guest1
Australia Forum Administrator #1
Ah, yes I have. :)

If you look at your timer list you will see your timer sitting there, because the world is disconnected, and it doesn't fire on disconnected worlds.

You need to make a timer that fires even if the world is disconnected. Unfortunately a straight DoAfterSpecial won't work, as that doesn't give you the option of doing that. This worked for me (Lua version):


function world_resize ()
 MoveWorldWindow (0, 0, 690, 673)
end -- world_open

function world_open ()
 AddTimer ("resize_my_world", 0, 0, 1, "world_resize ()", 5 + 32, "")
 SetTimerOption ("resize_my_world", "send_to", 12)
end -- world_open


I have added a timer named "resize_my_world" with flags:

  • 1 - enabled
  • 4 - one shot
  • 32 - active when closed


Then I used SetTimerOption to force the send_to field to be 12 (script).

I suspect your original problem is caused by the order in which things are being done internally in MUSHclient. I think the "on document open" is being called before the part which remembers where you last positioned the world window.
Australia Forum Administrator #2
You could save the extra function by simply doing the resize directly on the timer:


function world_open ()
 AddTimer ("resize_my_world", 0, 0, 1, "MoveWorldWindow (0, 0, 690, 673)", 5 + 32, "")
 SetTimerOption ("resize_my_world", "send_to", 12)
end -- world_open

Australia Forum Administrator #3
Or, use ImportXML, which is particularly easy in Lua because of multi-line strings:


function world_open () 
ImportXML [[
<timers>
  <timer 
   name="resize_my_world" 
   enabled="y" 
   second="1.00"    
   send_to="12"
   one_shot="y" 
   active_closed="y" >
  <send>MoveWorldWindow (0, 0, 690, 673)</send>
  </timer>
</timers>
]]
end -- world_open

USA #4
thanks :) except all my scripts are in VB.. so can I still use one of these options alright?
Australia Forum Administrator #5
Sure, the VBscript version would be:


Sub world_open

'
'  your other stuff here ...
'

   AddTimer "resize_my_world", 0, 0, 1, "MoveWorldWindow 0, 0, 690, 673", 5 + 32, ""
   SetTimerOption "resize_my_world", "send_to", 12
End Sub

USA #6
YAY that did it, thanks :)