Code: Select all
saveData:get("myvar_xxx")Is there a way to make "xxx" a variable?
That probably sounds confusing. What I mean is, is there a way to make a variable that can have a different name depending on the value of another variable? I have variables in all the levels I've made that do the same things, but they need to be independently set in each level. To reduce the amount of coding that is required, I need to have a way to change variable names. For example, if I have this variable:
Code: Select all saveData:get("myvar_xxx")Is there a way to make "xxx" a variable? | ||
Yes you can, however there are some restirictions and recommendations:
1.) You can only make global variables out of them, not local variables. 2.) To prevent an overwrite of an already exsisting variable you should put them in a table! Code: Select all for key,value in pairs(saveData:get()) door with tables: Code: Select all local myVars = {}if you want to to check for the "myvar_" prefix you have to use string library. ▬▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬▬ Signature.start() ▬▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬
▬▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬▬ Signature.end() ▬▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬▬ | ||
I found an even simpler way to do it. I just put this code in lunadll.lua:
Code: Select all _G["level_code"] = "xxx"And this in lunaworld.lua: Code: Select all saveData:set(level_code .. "-dc-1", "collected")dc-1 is a variable that indicates if a dragon coin in the level was collected. Since there are 5 dragon coins in each level, it seemed a waste to do all that coding that I had to do before I implemented this. | ||
Who is online (over the past 5 minutes)Users browsing this forum: 1 guest | ||