Greets everyone,
I've run into a bit of a snag and I believe that metatables may hold the answer for me. However, I'm a little unsure how to go about getting what I need done.
Part of one of my functions looks something like this:
The problem is, with the way I've set up my tables, if there's no elves online at all the characters_online.elf key doesn't exist and if this function is called I get an error stating that I tried to index a nil value.
What I would prefer is to have a situation where if the characters_online.elf key is nil, it returns a boolean false rather than an error.
Does anyone have any idea about how this might be achieved?
I've run into a bit of a snag and I believe that metatables may hold the answer for me. However, I'm a little unsure how to go about getting what I need done.
Part of one of my functions looks something like this:
if characters_online.elf.warrior then
Note ("Yay, there's at least one elf warrior online!")
end
The problem is, with the way I've set up my tables, if there's no elves online at all the characters_online.elf key doesn't exist and if this function is called I get an error stating that I tried to index a nil value.
What I would prefer is to have a situation where if the characters_online.elf key is nil, it returns a boolean false rather than an error.
Does anyone have any idea about how this might be achieved?