Function values

Hi, i've been searching but i couldn't really find anything.
How do you change values inside a function? something like:

1
2
3
4
5
6
local function example()
   apple = 1
end
 
 
example.apple = 2

Example 1.

1
2
3
4
5
6
7
local apple = 1
 
local function(apple)
    apple = 2
end
 
print(apple) -- prints 2

Good Job Rob,:)

undecode here some more for ya..;)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
--** copy and go code ;)
--** some simple code to add or subtract apples..using a function ;)
_G.totalApples = 16; --Global depending program needs and scope
--** local totalApples = 16; --**Or could be local like this
 
 
local function addMoreApples(howManyFound)
 
        --** you could add / subtract / ...etc
        totalApples = (totalApples + howManyFound);
        
        --** then return to calling function
        return totalApples;
        
end
 
local function main()
 
        local applesReturned = 0;
 
        print("\nTotal apples when we started:  ", totalApples);
        
        --** we found some more apples under the tree..;)
        applesReturned = addMoreApples(14);
        
        
        print("\nThis Way also!  ", applesReturned);
        
        
        print("\nTotal apples this way too!", addMoreApples(14));
        
        
        print("\nTotal apples when we ended:  ", totalApples);
 
        
        --** main()'s return to system
        return 0;
        
        --** anyway there's alot of different ways to do what
        --** you need / want
        --** just stay with-in the .lua/corona programming lanq. ;)
 
end
 
--** run our main() 
main();
views:1680 update:2012/2/7 8:40:54
corona forums © 2003-2011