Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(1 edit) (+4)

(Edit: looks like ahmwma beat me to it with a reply, so hopefully the extra explanation is also helpful)

Hi!

So there's a few things you've got wrong here. I'll go through them in a way that hopefully explains it all.

The first is that Decker doesn't really have global variables in this way - i.e. a variable doesn't persist between scripts. But what does persist is values in widgets - so we can do it that way and make the widgets invisible with the "show none" option. Depending what you need to store, you'll use a different widget, in this case since it's just a true or false it's best to use a checkbox (i.e. a button with the style set to "checkbox"). Just put that somewhere on your card, name it accordingly, and make it invisible. Then you can refer to its value by using haveIceFish.value, or if you're in another script that's setting the value you can use like haveIceFish.value:1 or haveIceFish.value:0 (the colon is how we assign values in decker). If you want to access the tickbox from another card (e.g. I find it helpful to just have one card where I keep everything I'm using to store information like this) then you can go like cardname.widgets.haveIceFish.value to get the value from any card but for now we'll assume it's on the same card as the button for simplicity.

Next is the syntax around the "if" statements. The == sign isn't how we check for equality in Decker, generally we use = or ~ (which in most cases are the same but behave differently with regards to lists, for cases like this it's best to use ~ but there's details in the lil doco if you're curious) but in this case since it's a true/false we don't need to check equality at all, we can just do an if/else with the value. Also, an "if" statement has to have a matching "end" at the end so that we know which parts of the code fall under the if and which come after.

Finally, wait isn't a built-in function in decker. I'm guessing what you want is the sleep[] function, which needs a parameter. You can do like sleep[60] to have it wait 60 frames (i.e. 1 second) for example, or if you do sleep["play"] it'll wait until any sounds are finishing playing.

So overall, if you've set up a checkbox to store the "haveIceFish" value, then your code would look something like this. Hopefully this makes sense to you!

on click do
 play["sound2"]
 sleep["play"]
 if haveIceFish.value
  go["card3"]
 else
  go["card2"]
 end
end