Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(+2)

Hi, I'm sorry I'm answering this on my phone and can't go into super detail so let me know and I can work up some better examples. Contraptions can definitely play sounds but I think they aren't able to see deck level resources (like sounds that have been added). So I think what you'd need to do is create the sound resource inside the contraption.

If you run in the listener 'deck.sounds.soundname.encoded' it'll give you a string that represents that sound. You can then in the contraption create a sound object in your code using sound["whatever the string is"] and use that as the input for the play function.

Let me know if this doesn't make sense and I will try to work up some proper examples and explain better!

(I have had a bit of experiences making music sequencer type things in Decker haha, I look forward to seeing what you come up with)

(1 edit) (+1)

Thanks millie, that makes somewhat of sense if you could later go into a little more detail that would amazing! I'm a little confused on how I create a sound resource for a contraption, I'll have a squiz at the docs but I'd greatly appreciate some more detail. no promises on when ill release it but I would put it up on my website so you can check soon. 


edit: I just looked at your janky sequencer, that is seriously impressive, mine is not going to be that in depth but yk its for the love of the game <3

(+1)

OK, so I'm doing a bit of experimentation, and from what I can tell calling play["soundname"] in a contraption does seem to play the corresponding sound in the deck actually! Could be worth checking your syntax, since you've got a single quote in your example instead of a double quote? But what you've got should work, I think! If it's not working, maybe there's an example deck you can share so we can have a look?

But nevertheless, I'd say this isn't ideal for a contraption since a contraption should be transferable between decks as a single unit, and the sound resources don't come with it if you paste it into a new deck. So I think it's probably better if the sounds are contained in the contraption.

Essentially what you can do is in the code for the contraption (either in the code for a button or in the whole of contraption code, depending where you need it, do something like

sound1:sound["the big text string goes here"]

only using the output from running deck.sounds.soundname.encoded in place of the string.

And then you just call like sound[sound1] when you want to play it.

I did up a quick demo contraption, with one button that'll look for a sound named "amen" in the deck resources and play it, and one button that contains the sound itself encoded as a string. If you have a sound in the deck named "amen" (I just copied it across from the example sounds.deck) then both buttons should work the same way. But if you don't have a sound like this, the top button won't do anything, but the bottom button should. It looks like my contraption is too big for the itch editor so I've uploaded a deck containing it here: https://zine.milliesquilly.com/surprises/sounddemo.html

Feel free to poke around the contraption code, see how it behaves when copied into another deck, etc.

(+1)

Thanks so much, I think it might be something with my code in the contraption or its just bugged somehow, I tried the embed technique and it didn't work so I tried making a new deck with a new contraption and even just play["snare"] (the sound was just in the deck sounds) worked so I think its somehow messed up. ill share the deck on my website if you want to have a squiz at my dismal code. my ultimate goal is to make it so you can easily change the sounds by adding sounds to the deck named like track1, track2, track3 so its easily customisable. The current code I have should calculate the time for a step based off the bpm and the using the sys.ms interface, then it should run a loop for the amount of times the loop slider is set to. then it should check when the step time in ms has passed, then steps and then will check each check box if its check and then play the sound. Its convoluted as hell but i'm trying my best T-T also ignore the prints in the listener its me trying so hard to debug. My original plan was to make each check box check its self when the play button is hit and then each button manages its own sound but I can't seem to get that to work. Here is the deck link https://wieke.neocities.org/drumtest and I appreciate your help so much!

(+2)

It looks like your contraption has a button named "play". This will shadow (take precedence over) the definition of the built-in function "play[]". You also have a function play[] defined in the contraption-level script. If you clear up the first problem by e.g. renaming the play button to "_play" or "start_loop" or something else distinct then your listener logging prints, but as written it calls itself recursively instead of calling the built-in play[] function.

It is possible for a function which overrides a builtin to use "send" to invoke the "next-higher up definition", like so:

on play x do
 show["invoked wrapper!"]
 send play[x]
end

Sometimes this can be a handy way to bodge in extra behavior or logging without modifying existing scripts.

...but you can also sidestep this issue entirely by using distinct names for your widgets and functions.

Does that make sense?

(+1)

Thank you so much! I half understood, that makes sense it wasn't working especially since "play[]" is a function and I had a function named the same thing. I changed the button name and function name and it's now playing the sound however it is playing them all at the same time. It may have to do with the way the "while L > 0" statement is setup and how it interacts with the function, the listener shows the loop variable doing some funky stuff. also I believe that it plays all the sounds at the same time because if you set the loop slider to a high number, the sound gets very distorted like many iterations of the snare are being played at the same time. I really don't know why this is, it may be because of the way the code is. I updated the link with my new attempt (I don't think the sounds work with neocities so maybe save the html and run it in your browser or something), please take a poke around and see if you can spot anything, again thank you guys for your support and I hope one day ill be competent enough in lil to make some really cool gadgets and stuff!

(1 edit) (+2)

Here’s your problem:

if sys.ms-LST > T | sys.ms-LST = T

Lil always evaluates expressions right-to-left, which means this expression is understood like:

if sys.ms-(LST > (T | (sys.ms-(LST = T))))

…which probably isn’t what you wanted. You can fix it by adding brackets in the places you want:

if ((sys.ms-LST) > T) | ((sys.ms-LST) = T)

…or by leaning into the right-to-left pattern with something like this:

if !T<sys.ms-LST

After making that change, it plays the first four beats correctly.

(+1)

Thank you so much, I have the first track working!!!! thank you to all of you who helped, I really appreciate it. I have just 2 more questions, since lil doesn't do statements like ">=" the way I do a greater than or equal to statement is like how Screwtapello said by using brackets and the or statement " | "? My other question is how does the script in a button work? because I can only get it to run the script when I click it even with out the " on click do" function, so do buttons like only update to run the script when clicked or am I missing something? again thank you all and thank you IJ for making decker lol

(+1)

Lil has three comparison operators: equal-to (=), greater-than (>), and less-than (<). The negation of these (the ! operator) is equivalent to not-equal-to, less-than-or-equal-to, and greater-than-or-equal-to, respectively:

 a = b  # a is equal to b
!a = b  # a is not equal to b
 a > b  # a is greater than b
!a > b  # a is less than or equal to b
 a < b  # a is less than b
!a < b  # a is greater than or equal to b

If you click on a button in interact mode, its script is evaluated and sent a "click[]" event, executing the code declared in "on click do ... end". Any code outside an "on ... end" event handler will execute any time ANY event is sent to that widget. Buttons normally only get click[] events, so technically you can give them a script like

go["Next"]

instead of

on click do
 go["Next"]
end

and it will behave the same in most cases, but the former version becomes a problem with other widget types, which are sent a wider variety of events in different situations.

If you mark any widget as "animated" it will be sent a "view[]" event 60 times per second. This offers one way of making widgets and contraptions that continuously update themselves or move around, if that's the sort of thing you're alluding to trying to accomplish.

Does that help at all?