Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags
(+1)

I'm just starting with decker, and I feel like my question is absolutely basic and stupid, but I swear I've been digging at the documentation and examples and can't find the issue.
I have a button on a card that has the following script:

on click do
 key: 1
 go[bednokey]
end

The idea being that you pick up the key and it leads you to an identical card of the same location with no key.

On a previous card, I have the following script on a button, to avoid going to the card with the key once it's been picked up already:

on click do
 if key=0
  go["fieldbed" "SlideUp"]
 else
  go["fieldbednokey" "SlideUp"]
 end
end

And it won't work at all. It always goes to the card with the key. I tried reversing the conditions, using other symbols, no dice. What's the proper way to do this check?

(+1)

Anything that you want to "remember" across event handlers needs to be stored in a widget. A true/false flag, for example, could be stored in a hidden checkbox. If we had a card named "flags" with a checkbox widget named "hasKey" your scripts might look something like

on click do
 flags.widgets.hasKey.value:1
 go[bednokey]
end
...
on click do
 if flags.widgets.hasKey.value
  go[bednokey "SlideUp"]
 else
  go[bed "SlideUp"]
 end
end

If the widget happens to be on the same card as the script which references it you can shorten paths like "flags.widgets.hasKey.value" to just "hasKey.value".

If you want to show or hide objects on a card, you may find it more flexible to use a transparent Canvas widget containing an image of the key. You can show, hide, or reposition canvases at will, sort of like a sprite object:

myCanvas.show:"solid"
myCanvas.show:"transparent" 
myCanvas.show:"none"
myCanvas.toggle["solid" booleanExpression]
myCanvas.pos:otherWidget.pos

This may also remove the need for a separate "flag" widget; the canvas itself will remember its visibility setting:

if bed.widgets.keyCanvas.show~"none"
 # ...
end

Does that help answer your question? There are lots of other examples of doing this sort of thing in this thread and elsewhere on the forum.

(+1)

This absolutely goes above and beyond answering my question, thanks! I'll try all these out right away.