confused GS user. need help with "rules"

just started learning corona yesterday so my mind set is still thinking the same way as if im using gamesalad. tried various things but im not sure what im doing wrong or where to start to be honest. i have an image that i want to remove when the condition is true. it has *10 lives* i want these lives to decrease by 1 everytime it's touched. also can i change my username? lol or am i stuck with my real name thanks :)

local candytower1 = display.newImageRect ("poptower.png", 64,128 )
candytower1.x = display.contentWidth / 2
candytower1.y = display.contentHeight / 2

local

function killcandytower1 (event)
candytower1:removeSelf()
end

local candytowerlife = 10

local function takelifeoff (event)
candytowerlife = candytowerlife -1

end

candytower1:addEventListener ("touch", takelifeoff)

Try the following code (changes noted via comment,i.e. --)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
local candytower1 = display.newImageRect ("poptower.png", 64,128 )
candytower1.x = display.contentWidth / 2
candytower1.y = display.contentHeight / 2
 
local function killcandytower1() --event removed, you don't use it for anything within this function
candytower1:removeSelf()
end
 
local candytowerlife = 10
 
local function takelifeoff () --event removed, you don't use it for anything within this function
candytowerlife = candytowerlife -1
    if candytowerlife == 0 then --this "if" statement should do what you are looking for.  Note the double equals "=="
        killcandytower1() --call your other function 
    end --close "if" statement
 
end
 
candytower1:addEventListener ("touch", takelifeoff)

hi shane. thanks for the help. and nothing wrong with using my name. just not use to seeing my actual name as my display name lol

Hey Harley,

Firstly, I know you're new so you aren't in trouble ;) but please post your code inside lua tags, like this;

< lua >
My code here
< / lua >

Obviously without the spaces - makes it much easier to read.

As to your name, you can use the support request form.

I know it all seems a bit overwhelming and confusing at first but it gets a LOT better very quickly and will become intuitive. (I'm ex GS, too :))

Peach

hi peach. sorry bout that. its good to know that gs users are here. im trying to rebuild an app that i made in gs and got half way through so im very slowly trying to work out how to do the equivalent tasks in corona.

No worries Harley, just worth remembering for future posts :)

There are actually a HUGE number of ex GS users here, many of them have rebuilt their games in Corona.

Work through learning the basics and you'll get a good idea of the logic behind it all - it might seem slow now but as you adjust your way of thinking you'll see Corona is remarkably fast to use.

Peach :)

could you advise me on something. i read somewhere that its possible to have whole/most of the game all in main.lua. is there any effect on performance doing it this way? or having serperate lua files for the levels. world1.lua, world2.lua etc i want to optimize my game for iphone/ipod touch 2g use so ill do whatever i can to keep things running smoothly

@harley_hopkins :

There is little benefit to keeping everything in 1 lua file. However usually there shouldn't be a need to have each individual level as a separate lua file. Your best using states.

Ie :

1
2
3
4
5
6
7
8
_G.levelNo = 1 --In main.lua for instance
 
--Below code in game.lua
 
local levelTbl = {lvl1 = "level1.data"}
 
--load a level based on level number
loadLevel(levelNo, levelTbl)  --Would be a function to load in a level based on level number and table to load from. level1.data could contain a table of all your elements encoded in json.
views:1535 update:2011/10/11 8:57:46
corona forums © 2003-2011