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 :slight_smile:

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)
[import]uid: 80874 topic_id: 14460 reply_id: 314460[/import]

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

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)  
  

oh, and what’s wrong with using your own name… [import]uid: 64596 topic_id: 14460 reply_id: 53494[/import]

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 [import]uid: 80874 topic_id: 14460 reply_id: 53523[/import]

Hey Harley,

Firstly, I know you’re new so you aren’t in trouble :wink: 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 [import]uid: 52491 topic_id: 14460 reply_id: 53524[/import]

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. [import]uid: 80874 topic_id: 14460 reply_id: 53536[/import]

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

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 :slight_smile: [import]uid: 52491 topic_id: 14460 reply_id: 53711[/import]

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 [import]uid: 80874 topic_id: 14460 reply_id: 53726[/import]

@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 :

\_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.  
  

[import]uid: 84637 topic_id: 14460 reply_id: 53756[/import]