lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


So I'm trying to make a counter for a function  to work the way I would like it to. Which is when the player clicks four  dots a slowmotion function activates then this is where the counter comes in  for a few seconds  then the other half of the slowmation function kicks in to deactivate 


this is the function

function hitDots (event)
    if (event.phase== "ended" ) then
            overDrive = overDrive + 1
            print("+1")
        if overDrive == 4 then
             
         slow = false
            if slow == false then
                slow = true
                print("on") -- Print "on" in terminal to show that this is functioning
                    for i = 1, #blueDots do -- Use a for loop so we can call each individual object in the table all at once
                         blueDots[i].linearDamping = 1.0 -- Set linearDamping to 1.5 (slows object linear velocity)
                        for i = 1, #redDottable do -- Use a for loop so we can call each individual object in the table all at once
                         redDottable[i].linearDamping = 2.0 -- Set linearDamping to 1.5 (slows object linear velocity)
                        end

                     end
           
   

 
  counter function here
 
 
 
   
   
                    print("slow on")
                            overDive = 0              
             end
             
        if overDrive == 0 then
            slow = true
           
            elseif slow == true then
                    slow = false
                print("off") -- Print "on" in terminal to show that this is functioning
                    for i = 1, #blueDots do
                         blueDots[i].linearDamping = 0 -- Set linearDamping to 0 (resume original linear velocity)
                        for i = 1, #redDottable do -- Use a for loop so we can call each individual object in the table all at once
                          redDottable[i].linearDamping = 0 -- Set linearDamping to 1.5 (slows object linear velocity)
                        end
                   
                    end
                   
            end
                overDrive = 0
                print("slow off")
               
        end
           
    end

end


and here are some ways I try to make a counter


   
    local timePass = os.time()
   
    local function counter  ( event )
 
    local delayCounter = os.time() - timePass
 
    -- check if 10 seconds has passed since last spawn
    if delayCounter >= 10 then
        print(i)
    end
end
 
-- start game's main enterFrame listener
Runtime:addEventListener( "enterFrame", counter )
   
   
   
   
    local markTime = os.time()
    local timePassed = os.time() - markTime
   
    local countDown = 5000
if slow == false then
  slow = true
               
        countDown = countDown - 1
            if countDown >= 5000 then
                        print(i)
                        end
                       
end

   
             
           
                           -- local delayCounter = 10
                            local function counter  ( event )
 
                        local delayCounter = os.time() - markTime
                        --        local    delayCounter = delayCounter - 1
                            -- check if 10 seconds has passed since last spawn
                                if delayCounter >= 10 then
                                            print(i)
                                end
                               
                                    Runtime:addEventListener( "enterFrame", counter )

                            end
 
        local countDown = 50000
if slow == false then
  slow = true
               
        countDown = countDown - 1
            if countDown >= 50000 then
                        print(i)
                        end
                       
end
   
   
   
   
    local function countDown(event)
            if (timeRemain == 10)then
        slowmo = true
        print(i)
        end
        timeRemain = timeRemain -1
            if timeRemain == 0 then
            slowmo = false
        end
    end   
   
   
   
     local function cout( event )
    print(i )
 end
 
 timer.performWithDelay( 1000, count )
   
   
    none of them worked for me

and when I used loops it would freeze the screen instead of slowing down

oh i'm building this in the corona sdk

but if you know what i'm doing wrong or know how to make a