..:D&G:.. Posted December 29, 2015 Share Posted December 29, 2015 Hello guys, I made this simple script to output some info messages in chat. The thing is that it only outputs the first byte (letter/number) from the table where I've inserted the messages. I know there should be a thing to get the whole string as a whole, but I don't know what it is... local messages = { "1) Message 1", "2) Message 2", "3) Message 3" } local message = math.random(1, #messages) function showInfoMessages() setTimer ( function() outputChatBox ("#D60606INFO: "..message, getRootElement(), 255, 255, 255, true) end, 10000, 0 ) end showInfoMessages() Link to comment
Dealman Posted December 29, 2015 Share Posted December 29, 2015 It's not outputting the first byte, it's outputting your random number. It will be either 1, 2 or 3. If you want to get the table entry at that index, you need to structure it like this; outputChatBox ("#D60606INFO: "..messages[message], getRootElement(), 255, 255, 255, true) You're also only generating the the random number once, you don't really need a function for this, simply do it like this; local messages = { "1) Message 1", "2) Message 2", "3) Message 3" } -- Store the timer as a variable so you can manipulate the timer if you need to local messageTimer = setTimer(function() local randInt = math.random(1, #messages) -- Generate a new int every cycle outputChatBox ("#D60606INFO: "..tostring(messages[randInt]), getRootElement(), 255, 255, 255, true) -- Output the message at the randomly generated index end, 10000, 0) 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