My background prior to about 6 weeks ago was Adobe Flash back to the Flash 3 and the Macromedia days. It was very common for some of the swf apps I wrote to use dynamic variables for repetative tasks. In ActionScript it would be something like this:
num = 1;
eval("box" + num) == 10
The variable box1 is now equal to 10
or in a dynamic movieclip
num = 1;
MovieClip[num].gotoAndStop(10)
MovieClip1 is now on frame 10
Fast forward to Lua. I was looking for the same technique in my Corona app. I bought the “Programming in Lua” 2nd edition and it talks about how to do this on p. 129. I followed this and my function looks something like this:
-- Swap ability function
local function swapAbilities(stat)
local ability1 = \_G[swapValue1]
\_G[swapValue1] = \_G[stat]
\_G[stat] = ability1
\_G[stat.."\_object"].text = \_G[stat]
\_G[swapValue1.."\_object"].text = \_G[swapValue1]
swapValue1 = nil
end
where “swapValue1” and “stat” are Global variables.
(I know this might not be the best way to do this but bear with me… 
Using just “main.lua” this works like a CHAMP!! but, the moment I use this code in another module, it fails! Even if I declare the variables in the same module. I have checked in the terminal and everything is there, i.e. the variables exist but using _G to dynamically work with the variables fails in the external modules.
Any ideas? (I’m sure it’s Operator Error)
Thanks!
Brian [import]uid: 71093 topic_id: 14545 reply_id: 314545[/import]
