Skip to content

Actions and timers

Actions do things: animate a property, run code later, put things back, play a sound. They're the building blocks everything else is made of - even the shortcuts (flash(), zoom(), flipScroll(), ...) are just ready-made actions for the common cases.

Kind Actions
Animate tween · approach · stopTween
Later and again after · every · cancel
Put things back reset / resetAll · resetCamera · resetFighter · resetPuppet · resetFx · resetWindow
The song scrollTo / scrollBy · countdown · scatterStrums
Sound playSound · loopSound
Debugging log / print

Durations are milliseconds. Write them with beats(2), steps(4), seconds(0.5) or ms(300) - beats and steps use the tempo at the moment of the call, so a song's tempo changes are taken care of.


Animate

tween

tween(prop, to, duration[, ease])

Animates a property from where it is now to to.

prop a number or colour property: camera.zoom, strum[2].x, flash.color, ...
to where it ends up
duration how long - beats(2), seconds(1); 0 = at once
ease optional - how it moves, one of the easing curves (default "linear")
tween(camera.zoom, 1.2, beats(2), "sineInOut")   -- zoom in over two beats
tween(flash.color, #FF0000, beats(1))             -- colours blend channel by channel

Setting the property directly stops a tween on it, and a new tween replaces the old one. Opacities stay inside 0-1 even when an overshooting ease (backOut, elasticOut) swings past.

Psych: doTweenX, doTweenAlpha, doTweenZoom, noteTweenX, startTween · Kade: tweenPos, tweenAngle, tweenFadeIn

approach

approach(prop, to, rate)

Moves a property a share of the way toward to every 60th of a second - it follows a moving target smoothly, at the same speed whatever the frame rate. rate is that share, 0-1 (0.05 = gentle, 0.3 = snappy).

function onFrame(dt)
    approach(hud.angle, player.combo > 50 ? 2 : 0, 0.05)   -- tilts while the combo is high
end

stopTween

stopTween(prop)

Stops a tween right where it is. (reset would put the property back to its default instead.)

stopTween(camera.zoom)       -- the zoom stays where the tween had got to

Psych: cancelTween(tag)


Later and again

after

after(duration, function() ... end[, "name"])

Runs the function that much later, in song time. It remembers every local as it was when you called after, so each round of a loop keeps its own value:

function onEvent(p)
    for lane = 0, 3 do
        after(beats(lane * 0.5), function()
            tween(strum[lane].angle, 360, beats(1), "backOut")   -- one lane after the other
        end)
    end
end

With a name, cancel can drop it before it runs.

Psych: runTimer(tag, seconds) + onTimerCompleted

every

every(duration, function() ... end[, times][, "name"])

Runs the function again and again, one duration apart - times times, or until the song ends. The first run is one duration from now. Its locals stay from one run to the next, so a counter inside it counts on.

function onEvent(p)
    local ticks = 0

    every(beats(1), function()                -- 8 times, once a beat
        ticks += 1
        text[2].value = str(ticks)
    end, 8)

    every(beats(0.5), function()              -- until cancel("blink")
        hud.alpha = hud.alpha == 1 ? 0.6 : 1
    end, "blink")
end

It runs at most once a frame, however short the duration.

Psych: runTimer(tag, seconds, loops)

cancel

cancel("name")

Drops this event's waiting after / every calls with that name. Other events' timers aren't touched.

after(beats(16), function()
    cancel("blink")
    strums.alpha = 1
end)

Psych: cancelTimer(tag)


Put things back

reset

reset(what[, duration[, ease]])
resetAll([duration[, ease]])

Puts things back to their defaults - at once, or eased over a duration (the easing defaults to "sineInOut"). what is:

what Puts back
one property: hud.angle, strum[2].x that property
a group: hud, judgments, underlay, camera, fx, screen, flash, vignette, volume, ... every property of it (camera with the bump settings)
strums the whole strumline and every lane
one slot: strum[2], text[0], image[4], shader[1] everything of that slot
text, image, shader every slot
a fighter: player, opponent, boyfriend, dad, fighter[i], puppet[i] like resetFighter
a body part: player.head that part
window like resetWindow
popout[n] eases it home, then closes it

resetAll puts back every property the scripts can write. Numbers and colours ease; texts and switches change at once. A text, picture or shader reset over a duration fades out (alpha / amount to 0) and is cleared at the end - unless a script writes to it meanwhile. Tweens on what's reset stop.

reset(hud.angle)                         -- at once
reset(hud, beats(1), "backOut")          -- the whole HUD, overshooting a little
reset(text[0], beats(1))                 -- fades out, then empty
resetAll(beats(2))                       -- everything this kind of file writes, over two beats

The lanes are put back in a .modchart file: reset(strum[2], beats(0.5)) (one lane), reset(strums).

The song's end resets the moving parts by itself - see When the song ends.

Psych: — (set every value back by hand) · Kade: —

resetCamera

resetCamera([duration[, ease]])

Puts the fight camera back: at once, or gliding home over the duration. fights

resetCamera(beats(2))

resetFighter

resetFighter(who[, duration[, ease]])

Puts a fighter back - position, size, turn, tint, body parts: "player", "opponent", "both", or 0 / 1. fights

resetFighter("both", beats(1))

resetPuppet

resetPuppet(who[, duration[, ease]])

The same for the two puppets beside the lanes in practice. In a fight it does nothing (and resetFighter does nothing in practice) - a script can hold both. reset(player) works in both modes.

resetPuppet("both", beats(1))

resetFx

resetFx([duration[, ease]])

Switches the effects and shaders off: at once, or fading out.

resetFx(beats(2))

resetWindow

resetWindow([duration[, ease]])

Puts the game window back and closes every pop-out: at once, or gliding home first.

resetWindow(beats(1))

The song

scrollTo

scrollTo(speed[, duration])
scrollBy(factor[, duration])

scrollTo sets the scroll speed (1 = the player's own); scrollBy multiplies the current one. In the "modern" scroll style notes are placed on the planned curve, so the changes are worked out when the song starts.

scrollTo(1.5, beats(2))     -- 1.5x, eased in over two beats
scrollBy(0.5)               -- half of what it is now, at once

Psych: the built-in "Change Scroll Speed" event · Kade: scrollspeed

countdown

countdown()

Shows the 3-2-1-GO countdown over the running song - for a song that "starts again" after a break.

scatterStrums

scatterStrums([rate])

Throws your four lanes to random spots that never overlap or leave the screen, easing there at rate (default 0.7). resetLanes brings them home. Players find it hard to read - use it sparingly, if at all.


Sound

Sound files are .ogg files in the song's folder or its events/ folder. More in Sounds and music.

playSound

playSound(file[, volume[, "name"]])

Plays a sound once. volume 0-1 (default 1), on top of MineFunkin's own volume. With a name it can be faded and stopped later; a new sound under the same name replaces the one still playing.

playSound("cymbal.ogg", 0.7)
playSound("thunder.ogg", 1, "thunder")

Psych: playSound(file, volume, tag)

loopSound

loopSound(file, volume, "name")

Plays a sound over and over until stopSound("name") or the song's end. A loop always needs a name.

loopSound("rain.ogg", 0.6, "rain")

Psych: playSound + onSoundFinished to start it again


Debugging

log

log(...)
print(...)

Writes the values, joined with spaces, to the event log (logs/minefunkin-events.log). The quickest way to find out what a script does. At most 200 lines per event per run.

log("combo is", player.combo, "at", time)

Psych: debugPrint


Easing curves

Family In Out In and out
sine (gentle) sineIn sineOut sineInOut
quad quadIn quadOut quadInOut
cubic cubicIn cubicOut cubicInOut
quart quartIn quartOut quartInOut
expo (sharp) expoIn expoOut
circ circIn circOut
back (overshoots) backIn backOut backInOut
elastic (springs) elasticOut
bounce bounceOut

In starts slow and ends fast, out starts fast and settles - the usual pick for something that arrives. backOut, elasticOut and bounceOut overshoot and settle: great for pops, squashes and landings. linear keeps the same speed all the way.