Recent Posts

Pages: [1] 2 3 ... 10
1
Developers Corner / Re: Modding the ULX MOTD to have a timer.
« Last post by iViscosity on Today at 03:59:01 AM »
I just realized you're passing the entire window to the accept function when I think all you're trying to do is edit the button, am I correct? If that's the case, you should pass just the button, not the window. Also your timer only loops once, and then doesn't do anything to even if it worked you'd only get to 9 seconds. Make the timer run indefinitely, then when time == 0,  timer.Remove it.
2
Developers Corner / Re: MySQLoo callback pause
« Last post by Timmy on Yesterday at 10:16:46 PM »
I discourage querying databases synchronously. Databases can take a while to respond to a query. This will make a server halt until the query finishes.

I noticed that you used the asynchronous callbacks Query:onSucess and Query:onData in your code. These are not necessary when writing synchronous code. After Query:wait() finishes, you should have access to Query:getData() (unless an error occurs).

Synchronous query example:
Code: Lua
  1. local query = db:query("SELECT column FROM table WHERE id = 1")
  2. query:start()
  3. query:wait() -- Hang server until query finishes
  4.  
  5. if query:error() ~= "" then
  6.   print("Query error message: ", query:error())
  7.   return
  8. end
  9.  
  10. print("Query response data:")
  11. PrintTable(query:getData())

Would running a do while loop pause in an infinite loop until a condition (such as data from a DB appearing in a var) work for captain?
It wouldn't work.

An infinite loop that checks if a var was populated would lock up the server, unless the inside of the loop is going to change that condition or break at some point. The module would have to provide a function that continues to execute the query inside the loop.

If you were okay with using coroutines, you could perform the query in another thread and make the main thread wait for the result using a loop. Or maybe not... using MySQLOO in another thread seems to crash the server. :P (The code I used to test that: https://gist.github.com/anonymous/863806a7968924630f54ee5999d284af)
3
Developers Corner / Re: Modding the ULX MOTD to have a timer.
« Last post by FUImACat on Yesterday at 09:58:17 PM »
Code: Lua
  1. timer.Create("accepttimer", 1, 11, accept, window)

You're "accept" function requires an argument, "button". You're passing this timer with the function, but it's not receiving any argument, so 'button' doesn't mean anything. (Aka, a nil value)

Also, timer.Create only accepts 4 arguments, the string name, number delay, number repetitions, and func function. However, you  have a fifth argument "window" which I'm assuming you were trying to send to the accept funtion? If that's the case you'd need to do

Code: Lua
  1. timer.Create("accepttimer", 1, 11, function() accept( window ) end)

Edit: Also, looking at your timer, you have "time = time - 1" in your accept function, this means the time is only going to go down by 1 every 11 seconds. You should have the timer repeat indefinitely until time == 0, then timer.Remove the timer.

I did as much as i could under stand Lua/ code in general inst my strong point, I've got this and now there is no errors but the accept button never becomes active.

Code: Lua
  1. ulx.motdmenu_exists = true
  2.  
  3. local isUrl
  4. local url
  5.  
  6.     function accept(button)
  7.         if time == 1 then
  8.             button:SetText("1 second remaining")
  9.         else
  10.             button:SetText(string.format("%i more seconds", time))
  11.         end
  12.         if time == 0 then
  13.             button:SetText("I Agree")
  14.             button:SetDisabled( false )
  15.         end
  16.         time = time - 1
  17.              
  18.     end
  19.  
  20. function ulx.showMotdMenu()
  21.         local window = vgui.Create( "DFrame" )
  22.         if ScrW() > 640 then -- Make it larger if we can.
  23.                 window:SetSize( ScrW()*0.9, ScrH()*0.9 )
  24.         else
  25.                 window:SetSize( 640, 480 )
  26.         end
  27.         window:Center()
  28.         window:SetTitle( "Benders Villa" )
  29.     window:ShowCloseButton( false ) -- Show the close button?
  30.         window:SetVisible( true )
  31.         window:MakePopup()
  32.        
  33.         local panel = vgui.Create( "DPanel", window )
  34.         local html = vgui.Create( "HTML", panel )
  35.  
  36.         local button = vgui.Create( "DButton", window )
  37.         button:SetText( "10 seconds remaining" )
  38.             button.DoClick = function()
  39.                 window:Close();
  40.                     timer.Create("chat1", 1, 1, function() RunConsoleCommand("say", "I have read and agree to the rules listed in the motd.") end)
  41.                         timer.Create("chat2", 2, 1, function() RunConsoleCommand("say_team", "I have read and agree to the rules listed in the motd.") end)      
  42.     end
  43.         button:SetSize( 100, 40 )
  44.         button:SetDisabled( true )
  45.         button:SetPos( (window:GetWide() - button:GetWide()) / 3, window:GetTall() - button:GetTall() - 10 )
  46.        
  47.     local buttoncancel = vgui.Create( "DButton", window )
  48.         buttoncancel:SetText( "I Disagree" )
  49.         buttoncancel.DoClick = function()
  50.             timer.Create("leave", 1, 1, function() RunConsoleCommand("disconnect") end)
  51.            
  52.     end
  53.         buttoncancel:SetSize( 100, 40 )
  54.         buttoncancel:SetPos( (window:GetWide() - buttoncancel:GetWide()) / 1.5, window:GetTall() - buttoncancel:GetTall() - 10 )
  55.  
  56.         panel:SetSize( window:GetWide() - 20, window:GetTall() - button:GetTall() - 50 )
  57.         panel:SetPos( 10, 30 )
  58.         html:Dock( FILL )
  59.        
  60.         time = 10
  61.         timer.Create("accepttimer", 1, 1, function() accept( window ) end)
  62.         if( not ValidPanel( button ) )then return end
  63.         if not isUrl then
  64.                 html:SetHTML( file.Read( "ulx/motd.txt" ) )
  65.         else
  66.                 html:OpenURL( url )
  67.         end
  68. end
  69.  
4
Off-Topic / Re: Learning Python
« Last post by iViscosity on Yesterday at 04:52:47 PM »
bytewave, iviscosity is not a mod. I placed that there so he knew who said it.
Nono they don't need to know that haha :D

Also sorry :(

Sent from my XT1080 using Tapatalk
5
Off-Topic / Re: Learning Python
« Last post by Bytewave on Yesterday at 04:11:20 PM »
bytewave, iviscosity is not a mod. I placed that there so he knew who said it.
Ooh, I should probably read the "last edit" indicator. :P
6
Off-Topic / Re: Learning Python
« Last post by JamminR on Yesterday at 03:44:59 PM »
bytewave, iviscosity is not a mod. I placed that there so he knew who said it.
7
Post link
Gaben's user page (Follow his replies to questions here)

They're trying to keep HL3 spam to a minimum, so please respect their rules. But, feel free to browse around, ask questions, whatever!

edit: Well, I suppose I was a little late, but Gabe had to go. Still, the questions are there, and so are the answers.
8
Off-Topic / Re: Learning Python
« Last post by Bytewave on Yesterday at 03:39:04 PM »
-SNIP- I'm silly.
9
Developers Corner / Re: MySQLoo callback pause
« Last post by JamminR on Yesterday at 03:34:16 PM »
All,
Would running a do while loop pause in an infinite loop until a condition (such as data from a DB appearing in a var) work for captain?
(Been too long, I'm unsure if stopping code in an infinite(until data appears) loop might halt all other scripts/crash the game too.

Also, captain, i forget where, but somewhere in ULX i could swear we have a bit of code that repeats itself until ULib is loaded/initialized and then moves on.
I might be dreaming.
10
Off-Topic / Re: Learning Python
« Last post by iViscosity on Yesterday at 01:22:16 PM »
I feel like being mean and locking the topic just so no more replies haha

I won't though... Yet




EDIT-JamminR - watch the language
Pages: [1] 2 3 ... 10