Perform with a delay code manipulation of the code based on collision

Hello just a genuine question based on the perform with a delay code. 

I am creating a scroll shooting game and am wishing to implement new weapon pickups to change how the automatically fired gun from my character functions. 

The default function of the gun from the start is; 

 local function startProjectiles()

    local fireTimer

    local function fireNow()

        if powerUpActive == false then

            timer.cancel(fireTimer); fireTimer = nil

        else 

            local bullet = display.newImageRect( “images/projectile_red.png”, 5, 5 )

            bullet.x = ship.x -25; bullet.y = ship.y-60; bullet.name = “laser”

            physics.addBody( bullet, { isSensor = true } )

            audio.play(laserSound)

            local bullet = display.newImageRect( “images/projectile_red.png”, 5, 5 )

            bullet.x = ship.x +25; bullet.y = ship.y-60; bullet.name = “laser”

            physics.addBody( bullet, { isSensor = true } )    

            weaponGroup:insert( bullet )

        

        end

    end

    fireTimer = timer.performWithDelay(700, fireNow, 20)

    

end

startProjectiles()

Variables found at the beginning of the code (if helps);

local background1, background2 --Background moving image

local gameIsActive = true

local powerUpActive = true

local spawnInt = 0 --Gameloop spawn control

local spawnIntMax = 30 --Gameloop max spawn

local spawned = 0 --Keep track of enemies

local spawnedMax = 10 --Max allowed per level

local score = 0

local wave = 1

local enemySpeed = 7 --How fast the enemies are

local scoreText; local levelText; local ship; 

local laserSound = audio.loadSound (“sounds/laser.mp3”)

local clickSound = audio.loadSound (“sounds/click.mp3”)

From this code the charecter starts off with 20 shots that are automatically fired from the coordinates indicated. 

The main interest of mine is how to access the iteration part of the performWithDelay code. (the 20 found in “(700, fireNow, 20)”). 

This would help as I could make ammo pickups available aswell as having the option to display the iteration on screen to help indicate to the user how many bullets they have left to use. 

Any help on how to manipulate this part of the code would be ever so grateful and I would appreciate the help highly. 

I thank you again, 

-Daniel

Hello Daniel,

You can access the number of times the timer has executed, using the “event.count” property:

http://docs.coronalabs.com/api/event/timer/count.html

Also remember to include “event” in your listener function:

[lua]

local function fireNow( event )

  --your code

end

[/lua]

Best regards,

Brent Sorrentino

Hello Daniel,

You can access the number of times the timer has executed, using the “event.count” property:

http://docs.coronalabs.com/api/event/timer/count.html

Also remember to include “event” in your listener function:

[lua]

local function fireNow( event )

  --your code

end

[/lua]

Best regards,

Brent Sorrentino