In such a case, which is common, just add "stop" before the error message:
"stop attempt to index local 'image' (a nil value)"
Now you know what to do. Apply this schema to every error message you will get. Most programmers do that trick, it's faster than posting every error message and waiting for answer.
Don't be mad I'm a dush, karma will pay me back when I'll be in a need of help.
How to refer to a table inside another table?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- DaedalusYoung
- Party member
- Posts: 413
- Joined: Sun Jul 14, 2013 8:04 pm
Re: How to refer to a table inside another table?
True and false are the only possible values of the boolean type. Nil is of type nil. Therefore, of course, nil ~= false. In fact, nil just means 'different from any other value'[1].Exasperation wrote:Wait a second... this:returns true while this:Code: Select all
not nil
returns false.Code: Select all
nil == false
So, since the two options behave differently for the same input, shouldn't we use the one that provides the desired behavior in whatever particular situation we're using it?
Generally, when writing code like 'if x == false', you don't actually care if x is false (or nil or any other value), you only want to know if x is not true, so it's better to just use 'if not x'. It's easier to debug too, not having to reverse the statement in your head (causing paradoxical "the statement 'x == false' is not true" situations).
So yes, there is a difference between false and nil, but the only time you need to know this in your code is if you really need to know if x is declared or not, and for that you would check if it's nil. And how often does that really happen? There's never* any need to explicitly check if x is true or false.
*Nothing I can think of anyway
- Exasperation
- Prole
- Posts: 11
- Joined: Sat Oct 02, 2010 7:11 pm
Re: How to refer to a table inside another table?
I pretty regularly use functions with optional parameters in Lua; the following is a perfectly reasonable thing to do:
and I don't think it's less readable than this equivalent:
re: the original topic, it looks like the if statement in currMapSegment() is failing to match any of the values from ipairs(map), but why isn't obvious from what you've posted.
Code: Select all
foo = function (bar, optional_flag)
apply_bar(bar)
if optional_flag == false then
do_something()
end
end
foo(bat)
Code: Select all
foo = function (bar, optional_flag)
apply_bar(bar)
if type(optional_flag) == "boolean" and not optional_flag then
do_something()
end
end
foo(bat)
Re: How to refer to a table inside another table?
I've tried "currMapSegment().data" too, to no avail.
All your code are belong to us.
- moikmellah
- Prole
- Posts: 12
- Joined: Fri Jan 31, 2014 8:31 pm
- Location: USA
- Contact:
Re: How to refer to a table inside another table?
The segments in your map table are indexed as 'a1', 'b1', etc., so using ipairs() to iterate over them doesn't work - the logic in your for loop is never actually executed, so currentMapSegment() always returns nil. Try using pairs() instead of ipairs() - pairs() will iterate over all key/value pairs in a table regardless of key type, whereas ipairs() will only iterate over integer indexes from 1 to #table.
Also, not really an error, but for readability's sake I'd avoid variable names that are the same as the function they're declared in (or any function, really) - maybe change the function name to getCurrentMapSegment(). Makes it a bit more descriptive, and helps to avoid confusion with error messages.
Also, not really an error, but for readability's sake I'd avoid variable names that are the same as the function they're declared in (or any function, really) - maybe change the function name to getCurrentMapSegment(). Makes it a bit more descriptive, and helps to avoid confusion with error messages.
Who is online
Users browsing this forum: Google [Bot] and 14 guests