hahec Posted February 11, 2012 Share Posted February 11, 2012 Hello MTA. In what casec can i use this functions? ipairs string tostring and rest of string functions. Could someone explain me what can they be used for. Ty Link to comment
Castillo Posted February 11, 2012 Share Posted February 11, 2012 local messages = { "Hello World!", 2, } for index, message in ipairs(messages) do if string.find(message, "World") then -- We search for the world: "World", if found we output a message. outputChatBox("Found word: World") else outputChatBox(tostring(message)) -- Convert numbers (if found) to string. end end Link to comment
hahec Posted February 12, 2012 Author Share Posted February 12, 2012 Okay. Tnx very much i finally understand what string function is but i stil don't really get what actually happeens if you make "ipairs" or "in ipairs". Tnx in advance Link to comment
Castillo Posted February 12, 2012 Share Posted February 12, 2012 "ipairs" is used for indexed tables. And "pairs" can be used for any table (as far as I know). You need "in" combined with "(i)pairs" in a for-loop. Link to comment
hahec Posted February 12, 2012 Author Share Posted February 12, 2012 As beginner...will i use this function oftenly? Link to comment
Castillo Posted February 12, 2012 Share Posted February 12, 2012 Is not a function. And should use it when you need it only. Link to comment
drk Posted February 13, 2012 Share Posted February 13, 2012 We can use like this? local myTable = { [1] = { question='What the Fuck?!', answer='This is a shit!' }, [2] = { question='What the Hell?!', answer='I know, this is a shit xd' } } for i, data in ipairs(myTable) do if myTable[1]['question'] then -- We can use like myTable[index]['value1'] ?? outputChatBox(myTable[1]['answer']) end end I don't know why I need 'if myTable[1]['question'] It's only a example. 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