Ulysses Stuff > Ulysses Release Archives
[BROKEN] UMotd Revived - Motd and OTHER informational screens.
Reiko:
Sorry about posting this unfinished. I accidentilly hit tab, then space and the form submitted. Editing it now.
--- Code: ---local HTML = { }
local UMotd = { }
local UWindow = { }
--local UMotd_sc
local UMotd_sstart
for k, v in ipairs ( UMotd_sounds ) do
util.PrecacheSound( v )
UMotd_sc = k
end
function HTML:StatusChanged( text )
end
function HTML:ProgressChanged( progress )
end
function HTML:FinishedURL( url )
end
function HTML:OpeningURL( url, target )
end
vgui.Register( "UMotd", HTML, "HTML" )
function UMotd.showUMotd()
if Uwindow != nil then
Uwindow:Close()
end
Uwindow = vgui.Create( "DFrame" )
if ScrW() > 640 then -- Make it larger if we can.
Uwindow:SetSize( ScrW()*0.9, ScrH()*0.9 )
else
Uwindow:SetSize( 640, 480 )
end
Uwindow:Center()
Uwindow:SetTitle( "UMotd v" .. UMotd.version .." - Viewing the " .. UMotd.command .. " screen." )
Uwindow:SetVisible( true )
Uwindow:MakePopup()
--- End code ---
Right, this is a lot closer. Now; the first time you open up a radio (hiding) window the window opens up fine, then the next time, the old one closes first. However, upon using the "X" button at the top of the window or using a different window such as !motd and closing we get an error;
--- Quote ---Umotd/umotd_client.lua:56: attempt to call method 'Close' (a nil value)
--- End quote ---
Which I thought the if was suppost to take of. Any ideas?
Thanks again for all the help
JamminR:
Lua is case sensitive. And you've tried to convert Uwindow to a table.
At the top, you have
--- Code: ---local HTML = { }
local UMotd = { }
local UWindow = { }
--- End code ---
Change that to
--- Code: ---local HTML = { }
local UMotd = { }
local Uwindow
--- End code ---
I simply changed W to w. And I changed it from the assignment you were doing that declared a table to just a local variable.
Reiko:
--- Code: ---MsgN( Uwindow )
if Uwindow != nil then
Uwindow:Close()
end
Uwindow = vgui.Create( "DFrame" )
MsgN( Uwindow )
if ScrW() > 640 then -- Make it larger if we can.
Uwindow:SetSize( ScrW()*0.9, ScrH()*0.9 )
else
Uwindow:SetSize( 640, 480 )
end
Uwindow:Center()
Uwindow:SetTitle( "UMotd v" .. UMotd.version .." - Viewing the " .. UMotd.command .. " screen." )
Uwindow:SetVisible( true )
Uwindow:MakePopup()
local html = vgui.Create( "UMotd", Uwindow )
local Ubutton = vgui.Create( "DButton", Uwindow )
if UMotd.command:lower() == "radio" then
Ubutton:SetText( "Hide" )
Ubutton.DoClick = function() Uwindow:SetVisible( false ) end
else
Ubutton:SetText( "Close" )
Ubutton.DoClick = function() Uwindow:Close() Uwindow = nil MsgN( Uwindow ) end
end
--- End code ---
This helped a lot, didn't realize I was making it a table however, using MsgN as debug I found that even after the panel is closed, the variable keep's it... ID (or whatever that code was) so to get around that, after I noticed that the button was in a function, I added in that once the close button had been pushed, it set Uwindow to nil. Now it works perfectly UNLESS you press the "X" button up in the corner. Is there any way to register when that has been pressed or just when the panel has been closed in general?
JamminR:
--- Quote from: Reiko on October 01, 2008, 08:00:19 PM ---I found that even after the panel is closed, the variable keep's it... ID
<clip>
Is there any way to register when that has been pressed or just when the panel has been closed in general?
--- End quote ---
Ah, sorry about that. I forgot to tell you to account for the fact that Uwindow wasn't local to the function anymore, just the script.
When it's local to a function, it gets set back to nil after the function is over. When we removed it from the function and declared it local to the script, we have to manipulate it ourselves. Though we didn't want it to be nil at the beginning if the radio was playing, we do want it to go nil if the radio is stopped.
Glad to see you learned how to account and fix it yourself now though.
Wow, you seem to be learning quite nicely.
As for the X button, yes, there's a way to detect it. Unfortunately, I cant' find it on the Gmod wiki at the moment.
You know about the Gmod Lua wiki, right? Lots of insight to GLua can be found there to tinker with for various projects and ideas.
Several tutorals too.
Anyway, I found this that could be used to now show the X. Perhaps that would work for you.
[Edit] Oh, that 'id' as you call it by the way is I believe a memory address where the object is stored. One of my fellow team mates can correct me on this, or elaborate if I'm close. It's not a string variable, so it doesn't get printed as a 'readable' string.
Reiko:
--- Quote from: JamminR on October 01, 2008, 08:33:39 PM ---Anyway, I found this that could be used to now show the X. Perhaps that would work for you.
--- End quote ---
That's perfect! It's now fool proof.
--- Quote from: JamminR on October 01, 2008, 08:33:39 PM ---[Edit] Oh, that 'id' as you call it by the way is I believe a memory address where the object is stored. One of my fellow team mates can correct me on this, or elaborate if I'm close. It's not a string variable, so it doesn't get printed as a 'readable' string.
--- End quote ---
That makes sense.
Great! It's working perfectly now. Thanks so much for all your help!
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version