Skip to main content

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

Hi, I'm brand new to coding and Decker so I know my questions will be stupid, but I don't have much choice other than to ask as I've lurked and read up as much as I could (although not everything I read I understood). 

Basically I have a button to begin the game I'm working on, but I have it set up so that when I press that button a gif starts playing (instead of just going to the next card immediately). I want the gif to play for about 5 - 10 seconds before decker automatically forces the player to the next card. Frankly, I have no idea how to do that.

The small amount of progress I've made so far has been from looking at other people's decks and seeing what I can understand and use, but I've not been able to find anything that fits this particular need. I saw a few references people on here made to sys.me and stuff but idk how to code so I haven't been able to work that out. Decker is really cool so far though. Even though I don't know how to code I made a pretty neat looking title screen for my game, so I'm happy about that.

Thanks for any help anyway, sorry if it's very simple and I'm just dumb.

(+4)

There's a lot of material in this thread that might be helpful.

There are a number of possible approaches for what you're describing. I'll assume that when you say "play a GIF" you intend to use a gif or colorgif contraption?

If you have set up a button to take you to another card, its script might look something like the following:

on click do
 go["otherCard"]
end

If you simply wanted to wait for time to elapse before changing cards, you could use the sleep[] function, which accepts a number of frames to wait as an argument. Decker runs at 60 frames per second, so a 5 second delay would look like this:

on click do
 sleep[5 * 60]
 go["otherCard"]
end

While Decker is sleeping, the user can't interact with other widgets, and contraptions that normally animate or otherwise update themselves on every frame will appear to be "frozen". Some contraptions are designed to allow an external script to explicitly tell them to update themselves; by convention this will often take the form of exposing an .animate[] function which can be called from the outside. I have updated the gif and colorgif contraptions (see above) to support this convention. (If you already have a gif or colorgif contraption in your deck, re-pasting the updated definition from the bazaar will "upgrade" any existing instances of the contraption.)

If the card contained a gif widget named "mygif", we could rewrite the above script to give it a chance to keep running while Decker waits for 5 seconds by using a loop and only sleeping one frame at a time:

on click do
 each in range 5 * 60
  mygif.animate[]
  sleep[1]
 end
 go["otherCard"]
end

You alluded to wanting the GIF to start playing only when the button was clicked in the first place. Perhaps you meant you want the contraption to appear during that interval? This sort of thing can be done by manipulating the .show attribute of the widget. Supposing the contraption was initially set to "Show None",

on click do
 mygif.show:"solid"
 each in range 5 * 60
  mygif.animate[]
  sleep[1]
 end
 mygif.show:"none"
 go["otherCard"]
end

(Note that I reset the GIF to be invisible again at the end; this is not essential, but makes testing easier!)

I'd also like to point out that it's very straightforward to script simple "slideshow" animations with sleep[] by putting each frame on its own card:

on click do
 go["firstCard"]
 sleep[30]
 go["secondCard"]
 sleep[30]
 go["thirdCard"]
 sleep[30]
 # and so on
end

Or more concisely, for many frames of the same delay,

on click do
 each cardName in ("firstCard","secondCard","thirdCard","fourthCard","fifthCard")
  go[cardName]
  sleep[30]
 end
end

Of course, having a very large number of frames in such an animation can also make your deck quite large!

Does any of this point you in the right direction?

(+2)

Thank you for your detailed reply! I was indeed using colorgif already and had worked out how to hide it and make it appear when the button is pressed as you mention, but that was as far as I had gotten with it. Thank you so much for updating the gif contraption to make this work the way I wanted. I used your code and it all works beautifully now.

I have a small follow up question if that's ok (not related to gifs). I was wondering if there's a way to do the same thing with sounds as you did with the gif. So rather than waiting until the sleep ends before the sound plays, it could play as soon as the button is pressed. I have the code to start the sound on the same button as the code that begins the gif, but of course the sound only begins playing after the transition to the next card.

Sorry for all the questions, but your last reply was very helpful so I'd be remiss not to ask.

(+2)

There's no need at all to apologize for asking questions, especially when you've clearly done some experimenting and reading on your own before reaching out!

In a script like so:

on click do
 sleep[5*60]
 play["sosumi"]
end

Decker will wait five seconds before playing the sound. If you reverse the order of those operations:

on click do
 play["sosumi"]
 sleep[5*60]
end

The sound will begin to play immediately, with its playback overlapping the 5-second sleep.

You can also use sleep["play"] to ask Decker to sleep until all sound clips have finished play[]ing:

on click do
 play["sosumi"]
 sleep["play"]
end

See All About Sound for more detail and examples.

(+2)

That was surprisingly simple... thank you again :)