unknooooown Posted June 15, 2011 Share Posted June 15, 2011 (edited) Hi. I'm back! Really getting hooked on scripting Lua Well, my new problem is a math.random, problem. When I try to get the value of my randMoney, I ALWAYS get a nil value. I am not sure what I am doing wrong, because of my other math.random works just fine. Anyways.. Here is the script. Hope someone can help me out on this one function drugRunner (thePlayer, command) local randDrugMarker = { {-720,961,12}, {-705,968,12}, {-698,954,12}, {-711,942,12} } local randDrugMoneyGet = math.random(50,500) local randomX, randomY, randomZ = unpack(randDrugMarker[math.random(#randDrugMarker)]) local theDrugMarker = createMarker ( randomX, randomY, randomZ, "cylinder", 1.5, 255, 255, 0, 170 ) local randMoney = unpack(randDrugMoneyGet[math.random(#randDrugMoneyGet)]) end function markerHit ( thePlayer ) if(randMoney) then outputChatBox ("The Number Is:" .. tostring(randMoney)) else outputChatBox ("Value is nil!") end end addCommandHandler("drugrun", drugRunner) addCommandHandler("a", markerHit) Edited June 15, 2011 by Guest Link to comment
Castillo Posted June 15, 2011 Share Posted June 15, 2011 Your code is a bit weird.... try this: local randDrugMarker = { {-720,961,12}, {-705,968,12}, {-698,954,12}, {-711,942,12} } function drugRunner (thePlayer, command) local randomX, randomY, randomZ = unpack(randDrugMarker[math.random(#randDrugMarker)]) local theDrugMarker = createMarker ( randomX, randomY, randomZ, "cylinder", 1.5, 255, 255, 0, 170 ) end addCommandHandler("drugrun", drugRunner) function markerHit ( thePlayer ) local randMoney = math.random(50,500) if(randMoney) then outputChatBox ("The Number Is:" .. tostring(randMoney)) else outputChatBox ("Value is nil!") end end addCommandHandler("a", markerHit) Link to comment
unknooooown Posted June 15, 2011 Author Share Posted June 15, 2011 Btw... How come that randDrugMarker is outside the function, when randMoney is inside the function? Link to comment
JR10 Posted June 15, 2011 Share Posted June 15, 2011 local randDrugMoneyGet = math.random(50,500) local randMoney = unpack(randDrugMoneyGet[math.random(#randDrugMoneyGet)]) I don't understand what you want to do with the randMoney variable , seems like you are trying to get a random from randDrugMoneyGet which is impossible because its an integer not a table. randDrugMoneyGet is an integer ranging between 50 and 500. maybe explain what you want with randMoney. you should do the following: local randMoney = math.random(50,500) EDIT: iam too late EDIT2: Btw...How come that randDrugMarker is outside the function, when randMoney is inside the function? randDrugMarker have nothing to do with randMoney. randDrugMarker is the coordinates of the marker randMoney is the random money. And dont double post. Link to comment
unknooooown Posted June 15, 2011 Author Share Posted June 15, 2011 I didnt double post did I? Yeah, I know what randDrugMarker and randMoney does I was just wondering why randDrugMarker can be outside the function where it is used, when randMoney is inside the function where it is used. Link to comment
Castillo Posted June 15, 2011 Share Posted June 15, 2011 randDrugMarker is a table, it's not necesary to be into the function in this case. Link to comment
unknooooown Posted June 15, 2011 Author Share Posted June 15, 2011 randDrugMarker is a table, it's not necesary to be into the function in this case. That was all I needed to hear. Thank you 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