I need a bit of help :)

So i just started using codea like a month ago and i really enjoy it

I was so suprise of how much i like coding ! + you can see the change right away wich is super awsome but anyways

So here i am with 0 coding skill and trying to make a game wich i didnt really know what to make so i decided to make a simple clicker game (i know not a clicker game again!) but like i said im really trying to learn so anyways

Im stuck and i looked everywhere but i cant seem to figure out how to make a cps/cookie per second code

If someone could plz help me it could be awsome !

Just a simple code by adding 0.1 to the score every second

Thx you !

https://coolcodea.wordpress.com/2013/04/30/46-timers/

@JulieChelsea Here’s some simple code to add .1 to the score each second. The draw() function normally runs 60 times per second.

function setup()
    delay=0
    score=0
    fill(255)
    fontSize(100)
end

function draw()
    background(40, 40, 50)
    addScore()
    text(string.format("%.1f",score),WIDTH/2,HEIGHT/2)
end

function addScore() -- this get called 60 times per second
    delay=delay+1
    if delay>=60 then   -- 1 second has passed when delay reaches 60
        score=score+.1  -- add .1 each second
        delay=0  -- reset delay
    end
end

thank you so much dave1707 ! finally i have the codes :stuck_out_tongue: now i just need to figure out how to put it in ^^ have a wonderful day !

is there a way that i dont see the .0? like instead of 0.1,0.2,0.3 etc theres just 0 then after a while when the delay is done i see 1

so 0,1,2,3 etc and not 0.1,0.2,0.3 etc ?

sry if im cofusing you :confused:

@JulieChelsea either add one each time (not .1) or say math.floor(score)

@JulieChelsea Like this.

function setup()
    delay=0
    score=0
    fill(255)
    fontSize(100)
end

function draw()
    background(40, 40, 50)
    addScore()
    text(score,WIDTH/2,HEIGHT/2)
end

function addScore() -- this get called 60 times per second
    delay=delay+1
    if delay>=60 then   -- 1 second has passed when delay reaches 60
        score=score+1  -- add 1 each second
        delay=0  -- reset delay
    end
end

@dave1707 the problem that i have now is that how do i make it so when i buy an upgrade it goes up by 0.1? and everytime i buy it, it goes up by 0.1(0.1,0.2 etc)

thx again for the help !

I have quickly whipped up something. I hope it helps. It solves the increase by upgrade feature. You just need to convert the parameter to the upgrade of your choice. Let me know if you need help with that.

-- JulieChelsea Timer

function setup()
     
    parameter.action("Increase", function() 
        print("Score has been increased by "..scoreIncrease + 1) -- Parameter that increases the score when pressed
        increase()
    end)
        
    
    delay = 0 -- your delay between adding scores
    score = 0 -- your default score
        scoreIncrease = 1 -- the amount that the score will be increased by
    

end

function draw()
    
    background(0)
  add() -- calls the add function
    text(score, WIDTH/2, HEIGHT/2)  -- draws the text
    
end

function add()
    
  delay = delay + 1 -- everytime add gets called, this happens
    if delay == 60 then
        score = score + scoreIncrease
        delay = 0
        
    end
    
end

function increase()
    
    scoreIncrease = scoreIncrease + 1 -- everytime increase is called (in the parameter), this happens
    
end

Sorry if it’s a bit hard to understand. Just go through it and you will get the hang of it. Good luck with your coding. :slight_smile:

@JulieChelsea I guess I don’t understand what you want. First you said to add 0.1 each second, then you said not 0.1 but 1. So my questions are: What value do you want to add. How often do you want to add that value. How do you want the total to look like. For example, you want to add .1 each second, but you want the total to look like 1, 2, 3. That means the total will change every 10 seconds.

@dave1707, I think that’s it. @JulieChelsea show math.floor(score), but increase score by .1 every time.