timer to know if character is in life ?

Hi,

i have a character that could be dead or in life.

character.IsVisible = true -- in life character.isVisible = false -- dead local function testInLife() if character.isVisible then ..... end end

but the problem is that :

my character could be dead and after be in life… So how do i know the true state of my character. I should have a timer that say my character.isVisible during x seconds and after apply a condition like :

if characer.isVisible during x.second then .....

How do you do for code that ? and also that this function is not to big for the memory …

Thanks for your advice.

You could either use an enterframe listener:

function testInLife() -- do stuff end Runtime:addEventListener("enterFrame", testInLife)

or use a timer:

function testInLife() -- do stuff end -- check status every 100 milliseconds forever. local testTimer = timer.performWithDelay(100, testInLife, 0)

hi, thanks for the advice, here below my solution with your tips.

local function scaleItem(element,k,de,ti,a,sy,sx,tr,namefunction)     transition.to(element[k],{delay=de,time=ti,alpha=a,yScale=sy,xScale=sx,transition=tr, onComplete=function() namefunction() end}) end local function testLittleCharacterInLife()     for k=1,number.littleCharacter do         if littleCharacter[k].isVisible == true then             littleCharacter[k].timeInLife = littleCharacter[k].timeInLife +1             if littleCharacter[k].timeInLife \> 5 then                 if littleCharacter[k].flagBig then                     littleCharacter[k].flagBig=false                     local function returnFlagLittleCharacter()                         littleCharacter[k].flagBig=true                     end                     scaleItem(littleCharacter,k,0,500,1,2,2,easing.inQuint,returnFlagLittleCharacter)                 end             end         else                 littleCharacter[k].timeInLife = 0         end     end end timer.performWithDelay(1000,testLittleCharacterInLife,-1)

 

character.IsVisible = true -- in life

The I in isVisible is capitalized. It should start with a lowercase “i”.

Any way, if it were me, I would have a variable that tracked the character’s health or a simple isAlive, something like

character.isAlive = true character.health = 100

You can use ether depending on your games logic, but when you determine if the character has died, then you could:

character.isAlive = false character.health = 0 -- if you're measuring health...

When you determine the player is alive again, set it to true or give them some health back. Then you simply test either condition:

if character.isAlive then &nbsp;&nbsp;&nbsp;&nbsp; -- do things when the character is aliave end if character.health \<= 0 then &nbsp;&nbsp;&nbsp; -- do stuff when the character is dead end

Rob

You could either use an enterframe listener:

function testInLife() -- do stuff end Runtime:addEventListener("enterFrame", testInLife)

or use a timer:

function testInLife() -- do stuff end -- check status every 100 milliseconds forever. local testTimer = timer.performWithDelay(100, testInLife, 0)

hi, thanks for the advice, here below my solution with your tips.

local function scaleItem(element,k,de,ti,a,sy,sx,tr,namefunction) &nbsp;&nbsp; &nbsp;transition.to(element[k],{delay=de,time=ti,alpha=a,yScale=sy,xScale=sx,transition=tr, onComplete=function() namefunction() end}) end local function testLittleCharacterInLife() &nbsp;&nbsp; &nbsp;for k=1,number.littleCharacter do &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if littleCharacter[k].isVisible == true then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;littleCharacter[k].timeInLife = littleCharacter[k].timeInLife +1 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if littleCharacter[k].timeInLife \> 5 then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if littleCharacter[k].flagBig then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;littleCharacter[k].flagBig=false &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;local function returnFlagLittleCharacter() &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;littleCharacter[k].flagBig=true &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;scaleItem(littleCharacter,k,0,500,1,2,2,easing.inQuint,returnFlagLittleCharacter) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;littleCharacter[k].timeInLife = 0 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;end end timer.performWithDelay(1000,testLittleCharacterInLife,-1)

 

character.IsVisible = true -- in life

The I in isVisible is capitalized. It should start with a lowercase “i”.

Any way, if it were me, I would have a variable that tracked the character’s health or a simple isAlive, something like

character.isAlive = true character.health = 100

You can use ether depending on your games logic, but when you determine if the character has died, then you could:

character.isAlive = false character.health = 0 -- if you're measuring health...

When you determine the player is alive again, set it to true or give them some health back. Then you simply test either condition:

if character.isAlive then &nbsp;&nbsp;&nbsp;&nbsp; -- do things when the character is aliave end if character.health \<= 0 then &nbsp;&nbsp;&nbsp; -- do stuff when the character is dead end

Rob