i just want a button to send me to one place if a variable is one thing, and another place if the variable is another thing. it wont let me use this
(sorry this sounds stupid, it is)
Hi! No stupid questions, it's always good to ask if you're confused -- and this looks like a fun project!
I'm going to take a guess at rewriting your script, and then explain the changes I made.
on click do play["sound2"] sleep["play"] if haveicefish.value go["card3"] else go["card2"] end end
And now I'll walk you through it:
sleep["play"]
sleep[] is used to make pauses/delays in Decker.
In this case, I'm telling Decker to sleep[] until it's done "play"-ing that sound.
if haveicefish.value go["card3"] else go["card2"] end
Since it's a binary choice like this, we can put everything together into one If... Else... statement.
(I'll get back to the .value thing in a moment.)
I'm only checking for haveicefish.value now. If the player doesn't haveicefish Decker will use the script written under else instead.
(And if the script under "else" would be "do nothing", you don't need to have an "else" section at all.)
Additionally, if you need more branching possibilities you can use elseif
if haveicefish.value go["fishparty"] elseif havesmallfry.value go["bigpond"] else go["smallpond"] end
You can also check if multiple things are True, if one or the other is True, or is something is False in these ways:
if thing1.value & thing2.value # AND
if thing1.value | thing2.value # OR
if ! thing1.value # NOT
Finally, each If... statement needs it's own end, separate from the end of the overall script.
on click do if truething.value alert["yay!"] end end
Hopefully this all made some amount of sense so far! Let's talk about the other thing...
haveicefish.value
So, I've been using .value here because I'm actually not sure what you're checking. (I might just be missing something.) But I'll explain what I'm doing with that.
Variables in Decker are typically stored in widgets.
If it's a binary true/false situation I might store it in a button styled as a checkbox:
if haveicefish.value would check to see if this checkbox is marked/True/value=1
Checkboxes can be made to be true or false in your various scripts like this:
haveicefish.value:1 #writes the value true/checked/1 to this checkbox haveicefish.value:0 #writes the value false/unchecked/0 to this checkbox
If you're doing something that isn't just true/false and you need to store a number (perhaps the number of fish caught?), you might put that in a slider or a field. This slider's .value is the number that it has stored in it.
It really depends on what you're trying to do though, so please ask! Especially if I've rambled about things you don't need, or if I've made something more confusing.
---
One more note about storing things in widgets... sometimes I'll store all my widgets that track game flags and variables that I'll need to check later on a "behind-the-scenes" card and point to them in my scripts like this:
if fishstatus.widgets.haveicefish.value
This would look for the card "fishstatus", look at the names of it's widgets, find the widget named "haveicefish" and see if it's value is true (a marked checkbox, I guess) before proceeding with the rest of the if statement.
It can be longer to write (depending on how you name things), but it's often handy to store this stuff -- in their widget containers -- on a separate card together.
I hope something in here helped.
(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
I guess the only thing left to note is a dash of convenience!
If you have a bunch of game flags stored in checkboxes on a card named, say, "inventory", you might have buttons with game logic that look something like
on click do if inventory.widgets.frog.value play["munch"] alert["delicious!"] inventory.widgets.frog.value:0 else alert["i wish i had a frog..."] end end
That "inventory.widgets.frog.value" phrase could get a little verbose if you have to write it frequently. If you wanted, you could define some "helper" functions in the Deck-level script (see: File -> Properties... -> Script in the menu):
on setflag name do inventory.widgets[name].value:1 end on clearflag name do inventory.widgets[name].value:0 end on getflag name do inventory.widgets[name].value end
Which will make those functions available in any script elsewhere in the deck.
We could then simplify the earlier example:
on click do if getflag["frog"] play["munch"] alert["delicious!"] clearflag["frog"] else alert["i wish i had a frog..."] end end
In Lil,
thing["name"]
is equivalent to
thing.name
so long as 'name' is a Lil identifier: it must consist of letters, digits, and underscores (_) and may not begin with a digit or contain any spaces.
Thus, provided we follow appropriate naming conventions for our flags, we could go another step further:
on click do if getflag.frog play.munch alert["delicious!"] clearflag.frog else alert["i wish i had a frog..."] end end
Does any of this help?