Skip to main content

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

I want the button to make a sound, change the variable and hide the flower. Button should do all that if the variable = 0 wich should be like it from the start of the game. Then when we click the button it should change the variable and so make it impossible to click it again. But all the things doesn't want to work when I add conditions to the play... and I am so confused and I did read everything... but I just can't , it's all so complicated :_(

Also would like the game to "save" the variable to the next cards, so we can... give the flower to somebody but only if we have it, you know?.. Please, please, pretty please, explain to me how it needs to be done, but in a simplest manner imaginable, Im so dumb 😭

(+2)

Hello! This looks like a charming game already.

When you want to create a variable in decker to be referred back to later you need to store them in a widget. A temporary variable can be created within a specific script while it's running, but these temporary variables aren't stored anywhere and can't easily be edited unless you put them inside a widget.

But it's pretty easy to do exactly that!

For things where you want to track true/false (has the flower been picked?) a checkbox-style button is really useful. If you created a checkbox called "pickedflower" and gave it the value 1 like this:

pickedflower.value:1

.value means different things for different widgets, but generally it refers to the kind of information stored in them. I'll keep it simple and say that in the case of buttons (including checkboxes) they can only store a boolean 0/1 (false/true) as their value.

To check this value in your if statement you can write it like this:

if pickedflower.value
# the rest of your script here
end

But... since the checkbox is a widget that will live on a specific card, you'll need to put it somewhere. 

From what you explained about your game you want to set the variable while picking up the flower on one card... and then check the variable on another card later to give the flower to someone later, right?

So we also have to talk about how to refer to a widget that's on another card.

If the "pickedflower" checkbox lived on a card called "garden", you could refer to it this way on your scripts, when you need to refer to it's stored value from other cards:

garden.widgets.pickedflower.value

It's a little long to write it like this, but I think that's okay when you only have a couple things to check. If you have a lot of things to track, let me know and I'll come up with some suggestions for how to store them and refer to them more easily!

Also, you can set your checkbox to show:"none" and it'll be completely hidden to your player.  
Or you can store all your game state-related widgets on a card that the player never sees (I recommended this if you have a lot of them!)

Optionally, if you don't want to store a variable this way at all... there's other ways to do something similar. 

For example: you can check the current visibility of your flower canvas to see if it's been hidden or not:

if theflower.show="none"
# something that happens only if the flower's canvas is hidden
end

And you can also lock a button if you no longer want it to be clickable.

thebutton.locked:1

If you do this make sure to add unlocking it (thebutton.locked:0) to your reset button too.

I'm happy to explain more if it would be helpful. But I wanted to get an answer for you quickly so you could get started playing around with it.

(1 edit)

THANK YOU  SM! As long as I can tell right now it works in different cards!

But there is a problem with the lock button thingy you told about in the last paragraph. It doesn't want to lock, like... the sound plays anyway, even if we already grabbed the flower!

But maybe I oversimplicated it and you meant it as a variable for the button that works only in the script of the button itself?

(+2)

I was rushing a bit at the end of my post so let's see....

You figured it out (correctly) that I meant "thebutton" as the name of the button. I didn't know what yours was called, but I also didn't make it clear that I was making up a name for it. Sorry about that! But something is still not right, huh...

Is it possible there's an extra space at the beginning or end of the widget name? I do that all the time... and it will technically affect what the name of the button.

If the button's name is just "GrabFlowerButton", then that's how you should be able to write it in the code.

GrabFlowerButton.locked:1

Also! Since you mentioned things that only work inside a widget's script, I'll also mention this in case it's useful: 

When you're writing a script for a widget you can always refer to that specific widget as "me"

So for the script inside the button you can write it like this:

me.locked:1

Though you'll still have to use its name whenever you're referring to it in scripts that live anywhere else in your project.

I hope one of these things can help! I'll check back again later. 🫡

(+1)

OMG! Thank you again! :^3

It finally works how I intended it to! 

(When I created the first question I thought that no one will answer me, cause first questions in this topic were soo long before and I assumed everyone just forgot about this program ":-D )

Would it be ok if I had any questions much later and answered to your last reply with new ones?

(+1)

Hooray! I'm so glad!

Things are sometimes a little quieter here in the forum during August because one of the official decker jams just happened in July. But there's always enough people stopping by to make sure that questions get answered.

Feel free to reply here or leave a new comment on the thread, I'll keep an eye out for you. :)

Hi again! Yeah it wasn't so long as I thought I would text you, but yeah.

Could you help me again please? 😅

So eventually I ran into the problem with the need of usage a variable that needs to be changed and saved, but it would have a different event at each number.

By the way... I used it only in this script but it doesn't want to work. Firstly it was called in a short nickname, but it came to "DormitoryHall1.widgets"...... and so on because I tried to make it be saveble since I guess Everytime script ends widget forgets it.

SO how do I make a variable that has more than 1/0 in it that can be saved... or just work at least in this script how I wanted it to?.. But I know you might say that in this situation I could use just 1 and 0, but in the end I want to use 1,2,3 here! 

Also a question I got is how can I make a >= (≥) and ect, cause I read in the doc that this engine don't have that? Or maybe I just misread that...

Thanks in advance, my saviour! ;3

Hello! And yeah absolutely!

For starters: referring to widgets by a shorter nickname. I think you were on the right track already, but I'll explain it in more detail anyway.

One option is to create a variable which is just the full path to a widget somewhere else in the deck:

doorknock: DormitoryHall1.widgets.DoorDepr

And that should make it possible to use "doorknock" as a shortcut for the longer name.

Or a project that has many info tracking widgets on a secret storage card could just simplify part of the path:

status:secretstoragecard.widgets

And then be able to use that in your scripts like this:

if status.pickedflower.value

And while you can define these shortcuts in the specific scripts where you're using them... you could also put them in the Deck-level script if you use them a lot. Just like Widgets and Cards can have scripts, you can also define events and variables at the Deck level.

Things put in the Deck script are always visible to every widget in the project (unless overridden more locally, but that's a different subject).

You can access this script  with File > Properties > [Script...]

Or if you're already in a script editor for something else you can use File > Go to Deck to move there directly.

And this kind of nickname variable doesn't need to be in an event handler or anything, just define the variable and you're done.

Okay, now on to your real questions....

Just like a checkbox can hold 1 and 0 as true/false... other widgets are good at holding other kinds of information.

In this case I recommend a slider widget, specifically. They're very good at storing numbers within a specific range, and you can choose the minimum and maximum of that range, and how big of a step is allowed between each point on the slider.

They're my go-to widget when I'm keeping count of something!

I'd recommend setting the style of your slider to "Compact" in the properties dialog to make the number easier to read while you're testing, and then you can also set the min and max of the range of numbers you want to use.

A nice thing about using a slider for this job is that your existing script doesn't need to change much.

The current number stored in a slider is also called .value in scripts. 

And you can adjust it by doing things you already understand how to do:

yourslider.value: yourslider.value +1

If you need to reset it back to the beginning you can just assign it the number you want to start at. Assuming that's zero at the beginning of the game, just do this:

yourslider.value:0

(And, as always, make the names match your actual project)

For the other part... It's true that we can't use combined operators but you can usually get the effect you need by writing things a little differently. I'm not completely sure all the ways you were thinking about using >= so this may not fully answer your question...

But for this script example... I think things could be simplified a little with the power of "else".

(I'm not copying your full script here so I'll just leave placeholders for the different scene possibilities, okay?)

if doorknock.value =1
 # "Erm, Hello?"
else
 # "...."
end

Basically else is "If the condition wasn't true...  do this other thing instead." 

Or you could add more possible outcomes with elseif

The first true thing in the series of possibilities will be the one that happens, so if two things could technically be true at the same time, make sure to put the higher priority one earlier in the list:

if doorknock.value =1
 # "Erm, Hello?"
elseif doorknock.value =20
# "Please stop knocking!!"
elseif doorknock.value > 15
# "...!! >:O"
else
 # "...."
end

20 is more than 15, so the event for ">15" could have happened at value=20..... but =20 was earlier in the order of possibilities, so only that one will happen. It's kind of a silly example, but I hope it makes sense.

And while I'm thinking about it, you can also move your dd.open[] and dd.close[] lines to be before and after your branching dialog possibilities if you want. Like this:

on click do
dd.open[deck]
 if doorknock.value =1  
 dd.say["Erm, Hello?"]
 else  
 dd.say["...."] 
 end
dd.close[]
end

I've got to stop here for now but I'm happy to come back and clarify if I wrote things in a confusing way, or if I didn't answer your real question!