FWCentral Posted May 14, 2012 Share Posted May 14, 2012 Ok i have 3 numbers, How can i pick a random number out of them? Link to comment
FWCentral Posted May 14, 2012 Author Share Posted May 14, 2012 Doesn't that only work say if i put math.random(1,20) it will pick a random number between them? and i should have said the 3 numbers are non consecutive. Link to comment
Castillo Posted May 14, 2012 Share Posted May 14, 2012 Create a table. E.g: local numbers = { 1, 5, 8, 10 } outputChatBox ( numbers [ math.random ( #numbers ) ] ) Link to comment
FWCentral Posted May 14, 2012 Author Share Posted May 14, 2012 The numbers are coming from a db, so like this? local skins = ( skin1, skin2, skin3 ) skins [ math.random ( #skins ) ] Link to comment
Castillo Posted May 14, 2012 Share Posted May 14, 2012 No, wait, you're using parenthesis, not { }. local skins = { skin1, skin2, skin3 } skins [ math.random ( #skins ) ] Link to comment
Stanley Sathler Posted May 14, 2012 Share Posted May 14, 2012 I guess is like this, not? local skins = { skin1, skin2, skin3 } skins[math.random(#skins)] -- Note: I used "{ }", and not "( )" in table declarations --- Forget, you fixed your post. Link to comment
Castillo Posted May 14, 2012 Share Posted May 14, 2012 @StanleySathler: It has to get a random index from the table, so you have to give the max index in math.random, which you get with: #table, only if is a indexed table of course. Link to comment
Stanley Sathler Posted May 14, 2012 Share Posted May 14, 2012 Solidsnake, yes bro, I got it. I fixed my post, I had forgotten this detail. Link to comment
FWCentral Posted May 14, 2012 Author Share Posted May 14, 2012 I didn't want to start a new topic but i got another problem, Im trying to spawn a player; function spawn(source, spawn) outputChatBox("work1") local gang = executeSQLQuery("SELECT gang FROM Spawn WHERE name = ?",tostring(spawn)) if gang == "none" then outputChatBox("work2") elseif gang ~= "none" then outputChatBox("work3") end end It shows in the chatbox work1 and work3 but the gang in the db is "none" (without quotes) Link to comment
Castillo Posted May 14, 2012 Share Posted May 14, 2012 function spawn ( source, spawn ) outputChatBox ( "work1" ) local gang = executeSQLQuery ( "SELECT gang FROM Spawn WHERE name = ?", tostring ( spawn ) ) if ( gang ) then local gangName = gang [ 1 ] [ "gang" ] if ( gangName == "none" ) then outputChatBox ( "work2" ) else outputChatBox ( "work3" ) end end end Link to comment
FWCentral Posted May 14, 2012 Author Share Posted May 14, 2012 It works thank you! but how does this work? local gangName = gang [ 1 ] [ "gang" ] Link to comment
Castillo Posted May 14, 2012 Share Posted May 14, 2012 What do you mean by how does it work? you can google to check how SQLite works . P.S: You're welcome. Link to comment
Stanley Sathler Posted May 14, 2012 Share Posted May 14, 2012 The SQLQuery return a table. So you access the first item from table (gang[1]) and the column (["gang"]). Is it, I think. Link to comment
FWCentral Posted May 14, 2012 Author Share Posted May 14, 2012 Ok thanks Solidsnake and Stanley Link to comment
Castillo Posted May 14, 2012 Share Posted May 14, 2012 The SQLQuery return a table. So you access the first item from table (gang[1]) and the column (["gang"]). Is it, I think. Indeed, that's exactly what it is. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now