• CurTime()
    10 replies, posted
How can I use CurTime() to make it so that when I push a button the menu gets taller by 400 units? I tried this: [lua] start = CurTime() function t() MF = vgui.Create("DFrame") MF:SetSize(326, 218) MF:SetPos(171, 26) MF:SetTitle("DFrame") MF:MakePopup() MB = vgui.Create("DButton") MB:SetParent(MF) MB:SetSize(70, 25) MB:SetPos(118, 34) MB:SetText("DButton") MB.DoClick = function() if (CurTime() - start) > 0.1 then start = CurTime() MF:SetSize(326, MF:GetTall() + 1) elseif (CurTime() - start) > 400 then start = nil end end end concommand.Add("text", t)[/lua] It makes it so that every time I click the button it gets bigger by one unit, how can I make it so that it goes by its self? If you get what I mean.
Don't really understand :/ CurTime() = Current Time of the game. Not sure why you would need CurTime() for that.
[LUA] local start = 0 local function MenuExpand(Menu) if (CurTime() < start) then return end Menu:SetSize(326, Menu:GetTall() + 1) start = CurTime()+0.1 if Menu:GetTall() >= 400 then hook.Remove("Think", "PanelExpand") end end function t() MF = vgui.Create("DFrame") MF:SetSize(326, 218) MF:SetPos(171, 26) MF:SetTitle("DFrame") MF:MakePopup() MB = vgui.Create("DButton") MB:SetParent(MF) MB:SetSize(70, 25) MB:SetPos(118, 34) MB:SetText("DButton") MB.DoClick = function() hook.Add("Think", "PanelExpand", function() MenuExpand(MF) end) end end concommand.Add("text", t) [/LUA]
[QUOTE=-TB-;26738591][LUA] local start = 0 local function MenuExpand(Menu) if (CurTime() < start) then return end Menu:SetSize(326, Menu:GetTall() + 1) start = CurTime()=0.1 if Menu:GetTall() >= 400 then hook.Remove("Think", "PanelExpand") end end function t() MF = vgui.Create("DFrame") MF:SetSize(326, 218) MF:SetPos(171, 26) MF:SetTitle("DFrame") MF:MakePopup() MB = vgui.Create("DButton") MB:SetParent(MF) MB:SetSize(70, 25) MB:SetPos(118, 34) MB:SetText("DButton") MB.DoClick = function() hook.Add("Think", "PanelExpand", function() MenuExpand(MB) end) end end concommand.Add("text", t) [/LUA][/QUOTE] Thanks, I'll test that real quick. [editline]16th December 2010[/editline] Says there is an unexpected symbol near '=' on this line [lua]start = CurTime() = 0.1[/lua]
[QUOTE=Godlike2;26738940]Thanks, I'll test that real quick. [editline]16th December 2010[/editline] Says there is an unexpected symbol near '=' on this line start = CurTime() = 0.1[/QUOTE]He meant[LUA]start = CurTime()+ 0.1[/LUA]
That's what I figured. [editline]16th December 2010[/editline] It's making the button get bigger, I think it's because of this hook.Add("Think", "PanelExpand", function() MenuExpand(MB) end)
opps, in the click I made the MB panel get bigger and you wanted the MF panel to get bigger.
Yeah, I changed it and it works now. Thanks guys. [editline]16th December 2010[/editline] Oh, and is there anyway to make this go faster? Like which value should I change. I changed this line: [lua]start = CurTime() + 0.01[/lua] but it doesn't affect it if I start to do 0.001 to try and make it faster.
[b][url=http://wiki.garrysmod.com/?title=Panel.SizeTo]Panel.SizeTo [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] Do you guys never look into the wiki? Also you should try avoid using CurTime() on the client since its a synced time between the server and the client, means if the server laggs your expand thing will do so too, use RealTime() instead.
[QUOTE=Wizard of Ass;26740497][b][url=http://wiki.garrysmod.com/?title=Panel.SizeTo]Panel.SizeTo [img_thumb]http://wiki.garrysmod.com/favicon.ico[/img_thumb][/url][/b] Do you guys never look into the wiki? Also you should try avoid using CurTime() on the client since its a synced time between the server and the client, means if the server laggs your expand thing will do so too, use RealTime() instead.[/QUOTE] Can I usse the above code except run a replace all and replace it with RealTime()
You can, but like Wizard said, use Panel.SizeTo. No messing around with your own function for it.
Sorry, you need to Log In to post a reply to this thread.