• 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!

Lua Can someone explain nil to me?

Printer

if Printer then print("LUA") end
Senator
Premium User
Joined
Dec 27, 2009
Messages
5,782
Solutions
31
Reaction score
2,287
Location
Sweden?
Hiho,

Can someone explain what nil is? Example:


Lua:
			local tmp = casks[itemEx.itemid]
			if(tmp == nil) then
				tmp = getFluidSourceType(itemEx.itemid)
			end
 
If you try to get a value from the table casks using a key (itemEx.itemid) that does not exist, it will return nil (nothing). You can check if something was returned by checking if the variable was set to nil or not.
 
you are trying to set a value to a new var trying to access to a data table using itemEx.itemid as key and it doesn't exist that key in the table, so its value it becomes nil or false, you can check if exist in that table by this way
Lua:
 local tmp = casks[itemEx.itemid]
			if(tmp) then
				doSomething()
			end
that means if tmp got a value when tried to access to table
Nil value means "nothing stored" as devianceone said
 
Back
Top