Orlo
Orlo

Reputation: 828

Save and access multidimensional arrays

I'm working with multidimensional arrays for a users settings.

I create them as follows:

myGameSettings = {}
myGameSettings["core"] = {}

myGameSettings["core"].soundOn="Sound^true^onOf"
myGameSettings["core"].musicOn="Music^true^onOf"

than when user change the setting with "widget.newSwitch" I want to change the value accordingly. the problem is, when I try to save the value it creates a new multidimensional array instead of changing the existing one. I can confirm with print that my values are correct

print("setting: " .. "myGameSettings" .. "[" .. type .."]" .. "." .. setting)
myGameSettings[type].setting=tostring(switch.isOn)

print from the console setting: myGameSettings[core].musicOn

Upvotes: 0

Views: 64

Answers (1)

Oliver
Oliver

Reputation: 29453

Try

myGameSettings[type][setting]=tostring(switch.isOn)

Upvotes: 2

Related Questions