A Question on Energy/Mana Bar

Hi all,
Thank you all for helping me on my previous question regarding slowing things down in a scene.
Now here is the next thing that I got stuck on:
I am creating a Energy/Mana Bar for the game, so that each time the player is using some magic spells or special moves, it will drain energy/mana and eventually can't cast anymore spells when the player used up all the energy/mana. However, the energy/mana will restore slowly over time and the player can cast spells again.
So here is what I tried:
1. I create a [game.energybar] attribute(integer), with value 5.
2. I create a button that will trigger the spell using a Boolean attribute [game.spell] when Touch is pressed, and also trigger a Timer behavior, and it will deduct 1 from [game.energybar] for every 1 second. So when the value of [game.energybar] drops to 0, the [game.spell] will switch to False.
3. So here is the problem, when I pressed the button and hold it till the [game.energybar] value drop to 0, the spell was canceled just like I wanted it to. BUT, when I release and press the button again, the value will keep on getting deducted, e.g. -1, -2, -3, -4, -5..... and the [game.spell] is working again.
4. Are there anyways to make the value stays at 0 and won't go lesser (setting a minimum value) if I keep pressing the button?
5. And something similar to my question above, how do I set a maximum value so that the Energy/Mana won't be overflowed when it restores over time?
Thank you for your help in advance!
Sito
Thank you all for helping me on my previous question regarding slowing things down in a scene.
Now here is the next thing that I got stuck on:
I am creating a Energy/Mana Bar for the game, so that each time the player is using some magic spells or special moves, it will drain energy/mana and eventually can't cast anymore spells when the player used up all the energy/mana. However, the energy/mana will restore slowly over time and the player can cast spells again.
So here is what I tried:
1. I create a [game.energybar] attribute(integer), with value 5.
2. I create a button that will trigger the spell using a Boolean attribute [game.spell] when Touch is pressed, and also trigger a Timer behavior, and it will deduct 1 from [game.energybar] for every 1 second. So when the value of [game.energybar] drops to 0, the [game.spell] will switch to False.
3. So here is the problem, when I pressed the button and hold it till the [game.energybar] value drop to 0, the spell was canceled just like I wanted it to. BUT, when I release and press the button again, the value will keep on getting deducted, e.g. -1, -2, -3, -4, -5..... and the [game.spell] is working again.
4. Are there anyways to make the value stays at 0 and won't go lesser (setting a minimum value) if I keep pressing the button?
5. And something similar to my question above, how do I set a maximum value so that the Energy/Mana won't be overflowed when it restores over time?
Thank you for your help in advance!

Sito
Comments
I have figured out to use the [game.energybar] attributes in INDEX, so that the value won't drops beyond 0. However I am still stuck at stopping the value from growing non-stop over time.
How can I set a maximum limit to the Index [game.energybar] value so that it stop growing non-stop?
Thanks!
I managed to check out the tutorial on health bar and sort of implemented it into the energy bar. Using the "min" function and it works~~!!!
I've sorted it out myself now~ No worries~!