okay…step by step…I like that.
I have a folder.
inside that folder I have the main.lua file to start the app.
I have the requiere storyboard in main.lua and that takes me to home.lua – another file/module
In there I have 3 variables to add score or points.
– scoreLabel – where I have the image of the word “score”
– scoreObject – here is a number “0” it’s an object that changes as it gets more points.
– score = 0 – this is a variable named score and that has 0 points
in the same home.lua file I have right under those 3 variables, 1 functions
function addToScore(num) score = score + num scoreObject.text = score end
This function is to pass a number
so when I call the function to run…
I use this command…
addToScore ( ) – but Inside the parenthesis I add the points I want to give to the player, like this:
addToScore(10)
the function I use is this
if plant.x == 670 then transition.to(plant, {time=100, x=670, y=406}) plant:removeEventListener ("touch", plantTouch) audio.play(win) coinPlanta.isVisible = true transition.to(coinPlanta, {time=1000, x=glowCoin.x, y=40, onComplete=glow}) addToScore(10) end
And it works, it adds 10 points and in the variable … I see now 10, where before was a 0
So far so good.
All I need, it’s to be able to go to another file/module, not home.lua
let’s say page2.lu, and call the addToScore (20) function and add the points
10 in the home.lua plus 20 in the page2.lua
and I will have 30 points in the scoreObject.
I need the storyboard because I have many files in my app.
The problem is when I go to page2.lua and call addToScore
it gives me a nil value.
because page2 does not have the function name “addToScore”
so that’s why I get nil
I hope this will explain things a little bit better.
Programming experience – not much.
I have 2 apps in the app store already, they are very simple apps
but very nice. Actually I have sold about 300 of one of them
“Piano For Kids Level 1”
For me 300 it’s a lot, I’m very happy.
That’s why I want to learn more
so I can make better apps
Right now I just want to be able to add points to the score
all the games have that, I thought, it was not going to be too hard
but it seems it is really difficult.
Thanks for your help.