I have a function which draws a panel and I want that function to return something from panel.
[lua]
function Wait (time,text)
local time = tonumber(time)
local sizeEa = 290 / (time * 100)
local size = 0
local timeDid = 0
local nextT = CurTime()
local times = time * 10
local WaitingFrame = vgui.Create( "DFrame" ) -- Creates the frame itself
WaitingFrame:SetPos( ScrW()/2-150,ScrH()/2-50 ) -- Position on the players screen
WaitingFrame:SetSize( 300, 100 ) -- Size of the frame
WaitingFrame:SetTitle( "Please wait" ) -- Title of the frame
WaitingFrame:SetVisible( true )
WaitingFrame:SetDraggable( false ) -- Draggable by mouse?
WaitingFrame:ShowCloseButton( false ) -- Show the close button?
WaitingFrame:MakePopup() -- Show the frame
function WaitingFrame.Think()
if nextT < CurTime() then
nextT = CurTime()+0.01
size = size+1
Bar:SetSize(size*sizeEa,20)
timeDid = timeDid +0.01
if timeDid > time then
WaitingFrame:Close()
//
//Here i want the function Wait() to return true.
//I can't write "return return true" :(
//
return true
end
end
end
local Cancel = vgui.Create( "DButton",WaitingFrame )
Cancel:SetText("Cancel")
Cancel:SetPos(100,60)
Cancel:SetSize(100,30)
Cancel.DoClick = function()
WaitingFrame:Close()
//
//Here i want the function Wait() to return false.
//I can't write "return return false" :(
//
return false
end
end
[/lua]
How can i make this function to be posible to use like this?
[lua]
if Wait(15,"Start") then
...
[/lua]
P.S.: I cut out some not important code, like a Label, a bar and etc.
You are doing it wrong, basicly the way your doing it would have to block lua, but you kinda screwed up so it wont do anything at all instead.
You cant return from another functions scope
So, I should maybe add something in the end like "while WaitingFrame:IsActive() do"?
The way you're trying to do it is not possible. Why do you need a wait function?
Alternatively, you can use a timer to close the window after some seconds, but you can't pause code like that.
[QUOTE=Nevec;25567261]The way you're trying to do it is not possible. Why do you need a wait function?
Alternatively, you can use a timer to close the window after some seconds, but you can't pause code like that.[/QUOTE]
Well, I'm making something like crafting, and I want player to wait some time while the bar is expanding before something really happens, and I also want a button, so player can cancel crafting.
[QUOTE=Dave_Parker;25567807]Do it on the server.
[b][url=http://wiki.garrysmod.com/?title=Player.Freeze]Player.Freeze [img_thumb]http://wiki.garrysmod.com/favicon.ico[/img_thumb][/url][/b][/QUOTE]
No. That's not what I need.
Anyway, I redone it with timers, now it's more complicated, but works.
/thread
Sorry, you need to Log In to post a reply to this thread.