Teach me something!

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.



local frame = vgui.Create("DFrame")
	frame:SetSize**(ScrW(), 200)**
	frame:SetPos(0, 75)
	frame:ShowCloseButton(true)
	frame.Paint = function()
		draw.RoundedBox(0, 0, 0, ScrW(), 200, NiandraMOTD.MainFrameColour)
	end


2-- HTML

I don’t know what the (ScrW()-200-NiandraMOTD.HTMLSpacing and stuff alike mean, or what exactly it does.

Y+, X+, -, +



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)


3-- Couldn’t find anything on this other than it was python I think.

I have no Idea where k, v does.


for k, v in pairs(NiandraMOTD.ButtonsTable) do

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.

  1. 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: http://lua-users.org/wiki/ForTutorial

Thanks that actually helps a lot, one of the other questions I had was in this code


(0,0+num*NiandraMOTD.ButtonHeight)

how exactly is it setting the position.


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

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.