• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Better isInArrayFunction - (isInArray(arr,val[,checkindex])

Mock

Mock the bear (MTB)
Joined
Jul 29, 2008
Messages
619
Reaction score
106
Location
Brazil
Lua:
function isInArray(arr,val,checkindex) --By Mock the bear (MTB)
	assert(type(arr)=='table','#1 must be a table')
	for i,b in pairs(arr) do
		if (checkindex and i == val) or (not checkindex and b == val) then
			return true, checkindex and b or i
		end
	end
     return false
end
This is the function that i use.
The old isInArray return only true. This function return false and the value from table.
You can use like this:
Code:
local tabl = {"hi","My","Name",4,"is","mock",lol="mock"}
local dat,find = isInArray(tabl,'mock')
if dat then print("The index form the find is:"..find) end
---- Or
local dat,find = isInArray(tabl,8,true)
if not dat then
   print('There is no index 8')
end
local dat,find = isInArray(tabl,'lol',true)
if dat then
     print('the index lol get a value:'..find)
end
The it will print:
The index form the find is:6
There is no index 8
the index lol get a value:mock

:D
 
Last edited:
Lua:
function isInArray(arr,val,checkindex) --By Mock the bear (MTB)
	assert(type(arr)=='table','#1 must be a table')
	for i,b in pairs(arr) do
		if (checkindex and i == val) or (not checkindex and b == val) then
			return true, checkindex and b or i
		end
	end
     return false
end
This is the function that i use.
The old isInArray return only true. This function return false and the value from table.
You can use like this:
Code:
local tabl = {"hi","My","Name",4,"is","mock",lol="mock"}
local dat,find = isInArray(tabl,'mock')
if dat then print("The index form the find is:"..find) end
---- Or
local dat,find = isInArray(tabl,8,true)
if not dat then
   print('There is no index 8')
end
local dat,find = isInArray(tabl,'lol',true)
if dat then
     print('the index lol get a value:'..find)
end
The it will print:


:D

Nice!! you are alive mock!!
 
the only problem is that it is not "CaSe sEnsItive", but still can be easily fixed
Regards
 
Back
Top