I am wondering what is the best way or how do you guys normally deal with testing to see if an array is nil.
Take my current example. I have an array with a bunch subarrays:
filter_settings['clan_settings'][clan_name]['selected'] = "Y"
filter_settings['clan_settings'][clan_name]['player_clan'] = "Y"
There are 3 or 4 different functions that either change these values or display them for the user so there is no guarantee that it is not NIL.
I know anytime I access or change an array I can test if it is nil, and then create the array if it does not already exist. I don't like that approach in the above case because I end up having to do a lot of ifs. Even if I assume the clan_settings array already exists within the filter_settings array, I still have to check if filter_settings['clan_settings'][clan_name] is nil, and then if either filter_settings['clan_settings'][clan_name]['selected']/['player_clan'] are nil.
Doing this 3 or 4 times gets messy.
I came up with the idea of just testing to see if the filter_settings['clan_settings'][clan_name] is nil, and if it is nil then filling the array with default values for every clan OnPluginInstall. This works for now, but if I later decide I want to add a third value like filter_settings['clan_settings'][clan_name]['never_select'] then my plugin will have to back in and go through every clan name and make sure there is a default value for the never_select. If I end up adding a few different values after I first published the plugin then it ends up looking like a mess.
Am I missing a third option, or an easier way of doing this?
Take my current example. I have an array with a bunch subarrays:
filter_settings['clan_settings'][clan_name]['selected'] = "Y"
filter_settings['clan_settings'][clan_name]['player_clan'] = "Y"
There are 3 or 4 different functions that either change these values or display them for the user so there is no guarantee that it is not NIL.
I know anytime I access or change an array I can test if it is nil, and then create the array if it does not already exist. I don't like that approach in the above case because I end up having to do a lot of ifs. Even if I assume the clan_settings array already exists within the filter_settings array, I still have to check if filter_settings['clan_settings'][clan_name] is nil, and then if either filter_settings['clan_settings'][clan_name]['selected']/['player_clan'] are nil.
Doing this 3 or 4 times gets messy.
I came up with the idea of just testing to see if the filter_settings['clan_settings'][clan_name] is nil, and if it is nil then filling the array with default values for every clan OnPluginInstall. This works for now, but if I later decide I want to add a third value like filter_settings['clan_settings'][clan_name]['never_select'] then my plugin will have to back in and go through every clan name and make sure there is a default value for the never_select. If I end up adding a few different values after I first published the plugin then it ends up looking like a mess.
Am I missing a third option, or an easier way of doing this?