How to deal with nil? #363
-
In my data, I have a table called 'Effect2'. This lists a secondary effect some cards have, which is displayed through an image. However, not every card has such a secondary effect. As such this secondary effect parameter has the following contents: ['power', 'spread', nil, nil, 'vision', 'power', nil, 'power', nil, nil, ...] The intended use is that an image is displayed corresponding to the power, if such a secondary power if nothing exists nothing needs to be displayed. In order to display this secondary effect I have the following code:
While this does work as intended, it throws a bunch of errors. I get the following message every time nil is in the 'Effect2' data. How can I get rid of this warning or is there a better way on how to handle this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The issue with my code is that I check the entire array for nil, instead of checking each item in the array. I should have checked if The following code does work and is cleaner:
|
Beta Was this translation helpful? Give feedback.
The issue with my code is that I check the entire array for nil, instead of checking each item in the array. I should have checked if
e
is nil instead ofdata['Effect2']
.The following code does work and is cleaner: