working with "true" and "false" strings

Posted by R-Strunk on Tue 01 Mar 2022 08:16 PM — 2 posts, 10,252 views.

#0
I want to create a set of filters that will stay consistent from one session to the next. I believe the best way to do this is with the GetVariable and SetVariable functions.
However, I'm also hoping to be able to have the variables in a set of tables, such that the final object might look like this for ease of comparisons:
beaconfilter = {
asteroid = {text = false, sound = false},
cargo = {text = false, sound = false},
cloud = {text = false, sound = false},
mineable = {text = false, sound = false},
organic = {text = false, sound = false}}

I could, in theory, populate the table with GetVariable on world open using a nested set of for loops.
In so doing, however, the sub-tables would be populated with "true" and "false" strings rather than true and false bools.
A few questions, then:
1. Am I off my rocker in terms of this approach?
2. If this approach is decent, how might I convert the GetVariable results to bools so I don't have to worry about quite so many quote marks when processing the code?
Thanks!
Australia Forum Administrator #1
The easiest way is to "serialize" your table as described here: http://www.gammon.com.au/forum/?id=4960

Then the bools stay bools and you only have to do one SetVariable rather than one per item.