• Teach me something!
    3 replies, posted
Hello Facepunch, I need a little bit of help learning a few things regarding derma and a few other things. Please don't hesitate to provide links that will help me with what I need. I attempted to search online for awhile but to no real avail. The following code is taken from some scripts that I attempted to look at and study for future reference but I couldn't find too much information on it. GET TO THE POINT! So these codes were taken from Niandra's MOTD. 1-- Setting Size and Positioning. frame:SetSize(ScrW(), 200) I honestly just need a reference guide to this one to figure out how this works. Something that will teach me vector positioning for gmod. [CODE] local frame = vgui.Create("DFrame") frame:SetSize[B](ScrW(), 200)[/B] frame:SetPos(0, 75) frame:ShowCloseButton(true) frame.Paint = function() draw.RoundedBox(0, 0, 0, ScrW(), 200, NiandraMOTD.MainFrameColour) end [/CODE] 2-- HTML I don't know what the [B](ScrW()-200-NiandraMOTD.HTMLSpacing[/B] and stuff alike mean, or what exactly it does. Y+, X+, -, + [CODE] local NiandraMOTD_HTML_Panel = vgui.Create("HTML", frame) NiandraMOTD_HTML_Panel:SetPos(NiandraMOTD.HTML_Y+NiandraMOTD.HTMLSpacing, NiandraMOTD.HTML_X+NiandraMOTD.HTMLSpacing) NiandraMOTD_HTML_Panel:SetSize(ScrW()-200-NiandraMOTD.HTMLSpacing-NiandraMOTD.HTMLSpacing-NiandraMOTD.HTMLSpacing, 550) NiandraMOTD_HTML_Panel:OpenURL(NiandraMOTD.DefaultWebpage) [/CODE] 3-- Couldn't find anything on this other than it was python I think. I have no Idea where k, v does. [CODE]for k, v in pairs(NiandraMOTD.ButtonsTable) do[/CODE] Yes I'm a newb.
1-2. That has nothing to do with vectors. ScrW() and ScrH() return the width and height of a client's gamd window - or monitor if full screen. So setting a frame'a size to ScrW() will make it extent all the way across. 3. That is a for loop that will print all variables from a table. k = key and v = value, although any word there will work- it's not limited to k and v. This page may offer some more on for loops: look at the pairs example: [url]http://lua-users.org/wiki/ForTutorial[/url]
[QUOTE=code_gs;47235714]1-2. That has nothing to do with vectors. ScrW() and ScrH() return the width and height of a client's gamd window - or monitor if full screen. So setting a frame'a size to ScrW() will make it extent all the way across. 3. That is a for loop that will print all variables from a table. k = key and v = value, although any word there will work- it's not limited to k and v. This page may offer some more on for loops: look at the pairs example: [url]http://lua-users.org/wiki/ForTutorial[/url][/QUOTE] Thanks that actually helps a lot, one of the other questions I had was in this code [CODE](0,0+num*NiandraMOTD.ButtonHeight)[/CODE] how exactly is it setting the position. [CODE]local num = 0 for k, v in pairs(NiandraMOTD.ButtonsTable) do local NiandraMOTD_Buttons = vgui.Create("DButton", NiandraMOTD_Buttons_Back) NiandraMOTD_Buttons:SetSize(NiandraMOTD.ButtonWidth, NiandraMOTD.ButtonHeight) NiandraMOTD_Buttons:SetPos(0,0+num*NiandraMOTD.ButtonHeight) NiandraMOTD_Buttons:SetText(k) NiandraMOTD_Buttons:SetFont("Bebas40") NiandraMOTD_Buttons:SetColor(NiandraMOTD.ButtonsTextColour) if NiandraMOTD.EvenOddSwap then if math.fmod(num, 2) == 0 then NiandraMOTD_Buttons.Paint = function() draw.RoundedBox(0, 0, 0, 200, 100, NiandraMOTD.EvenButtons) end[/CODE]
I'm sure num is increased somewhere later in the function: it's just a count iterator for the loop - aka the number of times the loop has been through. So if it's the second time through the loop, the position would be 1*whatever the button height variable is.
Sorry, you need to Log In to post a reply to this thread.