Hey
This gives me a error saying that Exambutton is a nil, when i want to change the color of it. After the button have been created there goes 60 seconds before i change the color of the button.
[CODE] local ExamButton = vgui.Create("DButton", Frame)
ExamButton:SetText("")
ExamButton:SetFont("TitleFont")
ExamButton:SetTextColor(Color(255, 255, 255 ))
ExamButton:SetPos(1567, 47)
ExamButton:SetSize(250, 101)
ExamButton:SetVisible(false)
ExamButton.Paint = function(self, w, h)
draw.RoundedBox(0, 0, 0, w, h, Color(154, 17, 17, 150))
end
ExamButton.DoClick = function()
net.Start("StartCheckExam")
net.SendToServer()
end
end );
net.Receive("StartExam", function()
ExamButton.Paint = function(self, w, h) /* Gives a error here */
draw.RoundedBox(0, 0, 0, w, h, Color(154, 17, 17, 0))
end
end)[/CODE]
Scope issue. You have defined ExamButton as a local vgui element, and are trying to edit it in a statement that is not inside the same scope.
You should instead remove 'local' from where you create the actual button element, though I sense this might pose a problem somehow.
Yeah. When i remove the local, the doesnt want to be created. :(
Is it always 60 seconds? You could store a CurTime upon creation, then in the draw hook check if CurTime is more than 60 seconds higher than your creation time, and if so change color.
[code]
local col = Color( 154, 17, 17, 150 )
local ExamButton = vgui.Create("DButton", Frame)
ExamButton:SetText("")
ExamButton:SetFont("TitleFont")
ExamButton:SetTextColor(Color(255, 255, 255 ))
ExamButton:SetPos(1567, 47)
ExamButton:SetSize(250, 101)
ExamButton:SetVisible(false)
ExamButton.Paint = function(self, w, h)
draw.RoundedBox(0, 0, 0, w, h, col)
end
ExamButton.DoClick = function()
net.Start("StartCheckExam")
net.SendToServer()
end
end );
net.Receive("StartExam", function()
col = Color( 255, 255, 255, 255 )
end)
[/code]
Make sure local col is not inside of a function
Can't you just do
[CODE]
local col = Color( 154, 17, 17, 150 )
local ExamButton = vgui.Create("DButton", Frame)
ExamButton:SetText("")
ExamButton:SetFont("TitleFont")
ExamButton:SetTextColor(Color(255, 255, 255 ))
ExamButton:SetPos(1567, 47)
ExamButton:SetSize(250, 101)
ExamButton:SetVisible(false)
ExamButton.Paint = function(self, w, h)
draw.RoundedBox(0, 0, 0, w, h, col)
end
ExamButton.DoClick = function()
col = Color( 255, 255, 255, 255 )
end
[/CODE]
Also, why are you changing the font and colour of the text of the button when you are setting the text to be nothing? What's the point of that? And, in your original code, why did you write
[CODE]
end );
[/CODE]
When there was nothing to end? And, why are you making the button invisible if you're changing it's colour?
By the way, in my example I was just assuming that StartCheckExam called StartExam...
.Paint is called every frame the menu is open; my advice would be to have the two colours inside it, with a boolean/variable to decide what is picked.
Something like:
[code]
thing.Paint = function()
if x then
colour is something
else
colour is different
end
end
[/code]
Facepunch doesn't have intending so it looks a bit messy but hopefully you get the idea - also why are you using net.Receive for this? Surely a simple timer would do fine
Sorry, you need to Log In to post a reply to this thread.