Jump to content

Some help.


hahec

Recommended Posts

Posted

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

Posted
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 

Posted

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

Posted

"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.

Posted

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'] xD It's only a example.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...