how do i check if a value is nil?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
how do i check if a value is nil?
i tried "if not [value] then" and "if [value] == nil then" but it says its trying to index a nil value :/
-
- Party member
- Posts: 730
- Joined: Sat Apr 26, 2014 7:46 pm
Re: how do i check if a value is nil?
Make sure to check that the table exists.
Code: Select all
If table then
If table[index] then
Do stuff
end
end
Re: how do i check if a value is nil?
Well its simpler to do
The problem seems to be thaz you try to do A.B but A is already nil.
Code: Select all
if table and table.value then
end
Or
if table and table.value == nil then
end
Re: how do i check if a value is nil?
the table does exist, however
still causes an error.
Code: Select all
if not table[value] then...
Re: how do i check if a value is nil?
The error message states that the table does not exist.
If the table truly does exist, then there's no way we can help you with the information you have provided.
If the table truly does exist, then there's no way we can help you with the information you have provided.
My game called Hat Cat and the Obvious Crimes Against the Fundamental Laws of Physics is out now!
Re: how do i check if a value is nil?
whenever i put a for loop in LoadLevel (so the map resets when the player dies), it seems to crash, but when i put a line of code that points to the level, it seems to work fine :/
- Attachments
-
- awedd-beta.love
- (6.1 MiB) Downloaded 166 times
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: how do i check if a value is nil?
Right, you're nearly there. The problem is that you have a doubly nested table. This should work:
Code: Select all
if not CurrentLevel[chartiley] or not CurrentLevel[chartiley][chartilex] then return end
Help us help you: attach a .love.
Who is online
Users browsing this forum: No registered users and 6 guests