[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Miniwindows
. . -> [Subject]  miniwindow startup issue
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

miniwindow startup issue

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Herl   (3 posts)  [Biography] bio
Date Fri 30 Jan 2015 01:58 PM (UTC)

Amended on Fri 30 Jan 2015 02:03 PM (UTC) by Herl

Message
So I made a miniwin plugin that works wonders.... if it's reinstalled. The issue I have is that if close my world, and open it again, the miniwin stops working. It only displays the window, but nothing ever is written once the trigger that updates the writing is activated. If I go to File > plugins > reinsttall, the plugin comes back to life and works exactly as intended.

Aditionally, I installed movewindow into it, and whenever I reload the world, the plugin begins at the initial position, top left, and stays there for a few seconds before it jumps back to the last saved position in the screen.

I deconstructed the code to leave only the essential part of how it works in an attempt to find what's the issue, however I'm not particularly an expert in Lua or plugins, and so I haven't found the problem. I paste this oversimplified version of the code I deconstructed that still preserves the same problem I've been having. Any help would be most amazing!

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>

<!-- Bits of this plugin and ideas were borrowed and remixed from the MUSHclient community.-->

<muclient>
    <plugin
    name="test"
    author="H"
    id="8c1ab2792ea52210aa67798f"
    language="Lua"
    purpose="Displays test"
    date_written="2015-01-28"
    date_modified="2015-01-29"
    requires="4.52"
    version="2.0"
    save_state="y"
    >
    
<description trim="y">

</description>
  
</plugin>

<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   keep_evaluating="y"
   match="Hall of the Fellowship."
   script="test_update"
   sequence="100"
  ></trigger>

</triggers>


<script>


require "movewindow"  -- load the movewindow.lua module

win = GetPluginID ( )
font = "f"

window_width = 200
window_heigth = 300
WINDOW_POSITION = miniwin.pos_top_left 

WindowFont ( win, font, "arial", 10, false)

WindowCreate ( win, 0, 0, window_width, window_heigth, WINDOW_POSITION, 0, 0x000000)
WindowRectOp( win, miniwin.rect_draw_edge, 2, 2, -2, -2, miniwin.rect_edge_etched, miniwin.rect_edge_at_all)

WindowText ( win, font, "this", 50, 100, 0, 0, ColourNameToRGB ( "red" ) )

WindowShow ( win )

-- windowinfo = movewindow.install (win, WINDOW_POSITION)
-- movewindow.add_drag_handler (win, 0, 0, 0, 0)


function test_update ()
refresh()
WindowText ( win, font, "that", 100, 100, 0, 0, ColourNameToRGB ( "red" ) )
WindowShow ( win )
end 

function refresh()
WindowRectOp (win, miniwin.rect_fill, 0, 0, 0, 0, ColourNameToRGB ("black"))
WindowRectOp( win, miniwin.rect_draw_edge, 2, 2, -2, -2, miniwin.rect_edge_etched, miniwin.rect_edge_at_all)
end

-- hide window on removal
function OnPluginClose ()
  WindowShow (win,  false)  -- hide it
end -- OnPluginClose

-- hide window on disable
function OnPluginDisable ()
  WindowShow (win,  false)  -- hide it
end -- OnPluginDisable

-- show window on enable
function OnPluginEnable ()
    WindowShow (win,  true)  -- show it
end -- OnPluginEnable

function OnPluginInstall()
    WindowShow (win,  true)  -- show it
end

function OnPluginSaveState ()
  -- save window current location for next time  
--  movewindow.save_state (win)
end -- function OnPluginSaveState


</script>
</muclient>


For example, this code should display "this," and after the trigger happens, it should display "that". On reinstall, this is exactly how it works. If I get out of the world and reopen it again, "this" won't be displayed, only the black window will be there, and the trigger won't change anything. On reinstall, it goes back to working right.
[Go to top] top

Posted by Fiendish   USA  (1,641 posts)  [Biography] bio   Global Moderator
Date Reply #1 on Fri 30 Jan 2015 04:25 PM (UTC)
Message
Quote:
WindowShow ( win )

Doesn't WindowShow take a second parameter?

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Nick Gammon   Australia  (21,323 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Fri 30 Jan 2015 09:18 PM (UTC)
Message
It defaults to true if omitted.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Herl   (3 posts)  [Biography] bio
Date Reply #3 on Sat 31 Jan 2015 01:25 AM (UTC)
Message
yeah, that's not the issue :/ it's differently written in different parts of the code because the code is a bunch of other plugins found here in the forum stitched together.
[Go to top] top

Posted by Donecce   (16 posts)  [Biography] bio
Date Reply #4 on Sat 31 Jan 2015 01:50 AM (UTC)
Message
I think maybe the font installation must be after the window creation.
[Go to top] top

Posted by Nick Gammon   Australia  (21,323 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Sat 31 Jan 2015 02:04 AM (UTC)

Amended on Sat 31 Jan 2015 02:05 AM (UTC) by Nick Gammon

Message
Here's your problem:


WindowFont ( win, font, "arial", 10, false)

WindowCreate ( win, 0, 0, window_width, window_heigth, WINDOW_POSITION, 0, 0x000000)


WindowFont adds a font to an existing window. However the window is created a line further down. Thus it fails to load the font, thus it cannot draw the text.

A good trick is to use the "check" function when things are not going as expected. For example:


check (WindowFont ( win, font, "arial", 10, false))


Now we get the message:


Run-time error
Plugin: test (called from world: smaug2)
Function/Sub: OnPluginInstall called by Plugin test
Reason: Executing plugin test sub OnPluginInstall
[string "Plugin"]:37: Requested miniwindow does not exist
stack traceback:
        [C]: in function 'error'
        [string "Check function"]:1: in function 'check'
        [string "Plugin"]:37: in function <[string "Plugin"]:27>
Error context in script:
  33 :   window_width = 200
  34 :   window_heigth = 300
  35 :   WINDOW_POSITION = miniwin.pos_top_left 
  36 :   
  37*:   check (WindowFont ( win, font, "arial", 10, false))
  38 :   
  39 :   WindowCreate ( win, 0, 0, window_width, window_heigth, WINDOW_POSITION, 0, 0x000000)
  40 :   WindowRectOp( win, miniwin.rect_draw_edge, 2, 2, -2, -2, miniwin.rect_edge_etched, miniwin.rect_edge_at_all)
  41 :   



That would give you a clue.

Move the WindowFont call down to after the window is created. It worked when you reinstalled because the window existed then, and it was able to add the font.

I got a clue from the "summary" plugin, like this:


Window: '8c1ab2792ea52210aa67798f', at (0,0,200,300), shown: yes
        width: 200, height: 300, position: 4, hotspots: 0, fonts: 0, images: 0



When I saw that I thought "fonts: 0? There should be a WindowFont call there!".

And there was, but then I spotted it was in the wrong place.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Herl   (3 posts)  [Biography] bio
Date Reply #6 on Sat 31 Jan 2015 10:20 AM (UTC)
Message
How come it's always the small things huh?

Thank you very much guys!
[Go to top] top

Posted by Nick Gammon   Australia  (21,323 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Sat 31 Jan 2015 10:44 AM (UTC)
Message
Donecce said:

I think maybe the font installation must be after the window creation.


Donecce was right. :)

- 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.


4,819 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]