• Help with Timer
    7 replies, posted
Im trying to make a timer but i keep getting this when ever it fires: Timer Error: attempt to call a nil value heres the timer code can't figure out whats wrong timer.Create( "my_timer", 10, 0, myfunc())
Where did you define "myfunc"?
Heres the full code ------------- WARNING: NO I DO NOT KNOW HOW TO ADD LUA TAGS TO MY CODE OR WHATEVER YOU CALL IT SO PLEASE STOP SAYING YOU WONT HELP ME BACAUSE I HAVEN'T ADDED THEM ------------- function myfunc ( ) local Frame = vgui.Create( "Frame" ); Frame:SetSize(150,150); Frame:SetPos(50,80); Frame:SetVisible( true ); Frame:MakePopup( ); Frame:PostMessage( "SetTitle", "text", "Select Team" ); //Set the title to "This is the title" local SButton = vgui.Create( "Button", Frame ); //Create a button that is attached to Frame SButton:SetText( "Raiders" ); //Set the button's text to "Click me!" SButton:SetPos( 25, 40 ); //Se t the button's position relative to it's parent(Frame) SButton:SetWide( 100 ); //Sets the width of the button you're making function Button:DoClick( ) //This is called when the button is clicked player.GetByID(1):SetTeam(1) end local MButton = vgui.Create( "Button", Frame ); //Create a button that is attached to Frame MButton:SetText( "Wastelander" ); //Set the button's text to "Click me!" MButton:SetPos( 25, 70 ); //Se t the button's position relative to it's parent(Frame) MButton:SetWide( 100 ); //Sets the width of the button you're making function Button:DoClick( ) //This is called when the button is clicked end end timer.Create( "my_timer", 10, 0, myfunc())
Its [lua][/ lua] Without the space.
[lua]function myfunc ( ) local Frame = vgui.Create( "Frame" ); Frame:SetSize(150,150); Frame:SetPos(50,80); Frame:SetVisible( true ); Frame:MakePopup( ); Frame:PostMessage( "SetTitle", "text", "Select Team" ); //Set the title to "This is the title" local SButton = vgui.Create( "Button", Frame ); //Create a button that is attached to Frame SButton:SetText( "Raiders" ); //Set the button's text to "Click me!" SButton:SetPos( 25, 40 ); //Se t the button's position relative to it's parent(Frame) SButton:SetWide( 100 ); //Sets the width of the button you're making function Button:DoClick( ) //This is called when the button is clicked player.GetByID(1):SetTeam(1) end local MButton = vgui.Create( "Button", Frame ); //Create a button that is attached to Frame MButton:SetText( "Wastelander" ); //Set the button's text to "Click me!" MButton:SetPos( 25, 70 ); //Se t the button's position relative to it's parent(Frame) MButton:SetWide( 100 ); //Sets the width of the button you're making function Button:DoClick( ) //This is called when the button is clicked end end timer.Create( "my_timer", 10, 0, myfunc()) [/lua]
There shouldn't be a space between myfunc and ( )
[QUOTE=Yobdren;16504611]There shouldn't be a space between myfunc and ( )[/QUOTE] No. Add this instead of timer.Create: [lua] timer.Simple(10,myfunc) [/lua] And you're good :eng101: [editline]04:31PM[/editline] The reason it's not working is because, in your timer.Create arguments, you put myfunc with (). It should just be myfunc. If you wanted to add arguments, separate them by commas in timer.Create instead. For the record, using my above timer.Simple is just 1000x easier to understand.
[QUOTE=Yobdren;16504611]There shouldn't be a space between myfunc and ( )[/QUOTE] Not even lua is that picky [editline]10:39PM[/editline] Thanks dude been giving me a headace for 2 days now =)
Sorry, you need to Log In to post a reply to this thread.