How to empty bottle and get money script

Hi, I’m a newbie in this kind of stuff and I kinda stuck on some of the script…

You see I was developing game where the player collect a bottle and at the corner of the player can dump the bottle in exchange for money.

So when I have 10 bottle and I go to the corner, I would get $20 and the bottle count become zero again.

at first my initial script was like:

function cornerZone ()
money = bottle * 2
bottle = 0 – to make the bottle count to zero again
end

Obviously that doesn’t work because it become zero in the end for the money. Is there an easy way to fix this? [import]uid: 117857 topic_id: 20389 reply_id: 320389[/import]

I’m not sure I completely understand the problem, but I’ll lay it out how I see it:

1.) Player collects bottles on screen
2.) Player moves into the ‘Corner Zone’
3.) Player receives $20 per bottle collected
4.) Number of bottles is reset to 0
5.) Player collects more bottles
6.) etc. etc. etc

Depending on how your code is calling this function, will depend on what the code should be.

if you are calling this via a listener that listens for the first contact between the player and the corner zone your code would be perfect.

if however your code has a listener that constantly fires when the player enters the corner zone then your code would have to be:

function cornerZone ()  
 money = money + (bottle \* 20) --(money = current money plus number of bottles times $20 each)  
 bottle = 0 -- to make the bottle count to zero again  
end  

You do this because your current code was saying that money = bottles x $20 but then in the next frame it then says money = bottles (which is now 0)x$20 (which still is 0)

Hope I’ve helped!
~Shane.G [import]uid: 8838 topic_id: 20389 reply_id: 79729[/import]

Omg… How can I be so dumb not to thought of that… just add money + (score * 2)… hh… thank you… that is exactly what I been looking for… I been thinking about this for 36 hours…

thanks again… [import]uid: 117857 topic_id: 20389 reply_id: 79730[/import]

You’re welcome and don’t worry, I’ve done this plenty of times. [import]uid: 8838 topic_id: 20389 reply_id: 80011[/import]