Really quick question

So this is really simple, I only have a little bit of code:

import "CoreLibs/graphics"
import "CoreLibs/object"
import "CoreLibs/sprites"
import "CoreLibs/nineslice"
import "CoreLibs/timer"
import "CoreLibs/frameTimer"

import "config"

import "core/definitions"
import "core/cotton/all"

import "scripts/index"

import "core/lieb/all"
import "core/CoreGame"


bpm = 60;

function addCircle(), math.random(240), 10)

function playdate.update()

    playdate.timer.performAfterDelay(60000 / bpm, addCircle)

BTW the "config" files and stuff are because I'm using Cotton (it's on github its super helpful and lets you use ltdk and stuff). I'm not actually using LTdk, I'm just using Cotton because it has a good template for games, but ANYWAYS: I'm trying to call the addCircle() function ONCE every beat (haven't added the music yet but the BPM variable exists), but playdate.timer.performAfterDelay() still calls it every frame, just starts later. I'm wondering how to change that?

Since you are calling performAfterDelay within playdate.update, you’re setting up a new timer every time playdate.update runs, i.e. every frame.

The simplest way to fix this would be to set up the timer outside of playdate.update, then set it to repeat, like so:

(put this somewhere outside of playdate.update so it only gets performed once)

beatTimer = playdate.timer.performAfterDelay(60000 / bpm, addCircle)
beatTimer.repeats = true

Then if you need to stop or change it, you can call any of the timer methods on beatTimer.

Thanks, it worked! Also, I want the circles to all generate next to eachother, just in a random direction. Have any ideas?

Store the last x,y coords in variables, and keep changing them by a random amount before using them? So the random changes are cumulative and always adjacent to the previous instance?

I get what you mean, but to be honest, I have no idea how to do that :frowning: I suck at Lua, since I'm mostly a web developer

Oh wait, I think I figured it out! Thanks for your help.