Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR LUA

roblox __index and __newindex

myMetaTable = {
	__index = function(table, index)
		print("Sorry, but the element ".. tostring(index).. " does not exist.")
		-- runs when you try to index a nil element of the table this metatable is connected to, table[index]
	end,
	__newindex = function(table, index, value)
		print("Sorry, but the element ".. tostring(index).. " can't be set to ".. tostring(value).. " because this element does not exist.")
		-- runs when you try to index and set a nil element of the table this metatable is connected to, table[index] = value
	end
}
 
PREVIOUS NEXT
Tagged: #roblox
ADD COMMENT
Topic
Name
4+7 =