Hello, this is my first post, so hello everybody.
My question is:
I have a fuction that return a table
prototype is as follow :
TheFuncProvided() -- (args - 0, results - 1 (table of key(string).value(boolean))
so to get the result i wrote this :
Table = TheFuncProvided()
if Table then
Val = Table.astringaskey
if Val then
--do somthing
end
end
As resukt Val is always nil, but table is not empty.
What i'm doing wrog ?
Thanks for your help.
Well, nobody know anything about arrays ?
hmm, its probably because ppl are confused by ur "problem", in lua arrays are more or less like tables,
to assign a value to a table in lua u do it more or less like this :
table["stuff"] = 1
to read a key from a table u do it more or less like this:
val =table.stuff , or
val =table["stuff"]
or u can use a loop to acess the info in a table something like e.g:
local temp,temp2 =nil,nil
for index,value in table do
temp =temp.."index "
temp2 =temp2.."value "
end
P.S. u cant just assign a function to a table, unless a function returns a value which u can add to a table !
hope it helps with ur dilema !
here's a example script 2 give you an idea of what you want 2 do.
!this and !that work as main chat commands and are called from a table.
the way you were trying allready failed on TheFunctionProv, as that isn't how you declare a function in lua.
and using an array for these this isn't handy, you would always have 2 loop the array, while tables can be hashed.
and like dessamator said, array's are tables in lua which are indexed by numbers.
for example:
Array = {var1, var2, var3, var4}
is inside lua
Array = {1=var1, 2=var2, 3=var3, 4=var4}
here's the example script for functions inside tables.
tTable = {
["this"] = function(var1, var2)
SendToAll("botje", "doing this")
return 1
end,
["that"] = function(var1, var2)
SendToAll("botje", "doing that")
return 1
end,
}
function ChatArrival(user, data)
local s,e,sCmd = string.find(data, "%b<>%s+%p(%S+).*|")
if sCmd and tTable[sCmd] then
if tTable[sCmd](user, data) then
return 1
end
end
end
if you want more examples then check my freshstuff and texter series or zcrazy.
these all use functions which are stored in tables.
plop
Thanks gys, i'll check if ican get it work.
Thanks again, i'll keep in touch