Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Trying to make an audio loop whenever a checkbox is enabled, but no idea how to make the script actually know if the checkbox is enabled or disabled. Right now, all I have is

```

on click do      

  play["bg1" "loop"]      

end

```

How do I add some sort of "if true" function, I've looked in documentations and tutorials and there's still nothing.

(2 edits) (+3)

The usual place I double-check how to write things in Lil is the Lil: A Scripting Language page.

So, what you need is an If statement. 

on click do
    if checkbox.value
    play["sound" "loop"]
    end
end

(I called the audio tracking checkbox "checkbox" but please call it whatever your widget is called.)

If the button that's being clicked to play audio is the checkbox and you'd like music to turn off when it's unchecked you might write it like this:

on click do
    if me.value
    play["sound" "loop"]
    else
    play[0 "loop"]
    end
end

Does this work for what you needed? I'm happy to give a different example if you have it set up in a different way.