Hi everyone. Welcome to this video about variables. We are going to look at specifically a number variable. It's gonna do this. We're gonna be a bit of hit plus and minus inside our prototype. Very cool and a nice introduction to variables for us.
Let's jump in and make it work. Alright, to get started, I have grabbed our cart from our previous file and just put it into a new document just to keep things separate. This is an update video by the way. So things might look a little different. Uh, and the variables interface might change a bit. If it change significantly, I'll update the video, but if it looks close enough, you'll get the drift.
Okay, so to get started, what I want to do is I'm gonna grab my text tool, click once. I'm gonna type in our number, I'm gonna use zero. Okay? And I'm gonna kind of put it in the right spot. You can go over there. Okay?
So what we need to do is define our variables, okay? Our local variables, what that means is we have nothing selected. I'm using Escape and there's this new option over here called local variables. Let's click on those options here, okay? And we're gonna create a variable, okay? We're gonna look at the number variable in this video, okay?
And we're gonna give it a name. You can call anything you like. Okay, I'm gonna call mine total. What is the value gonna be? Let's just change it. Let's change it to five.
And that is it. Okay, so we have defined our variable in here. Let's close this down. Now we need to assign it or apply it to something and we're gonna apply it to this. So I'm gonna click on this text box here and I'm gonna say you my friend over in the text panel. Okay?
There's this option, okay? That little hexagon Pentagon, I'm not sure which one it is. Shape with.in it. Okay? If you click on apply variable, we've only got one, which makes it easy and we apply it and watch what's gonna happen to the zero. You're looking at the zero, I'm looking at the zero watch change to five.
Kind of exciting, not really, but at least we know it's connected. Okay, let's have a look. Let's open, let's have nothing selected. Click off in the background. Let's open this up and I can say the total is zero and watch it change. Can you see it changed over there?
Okay, they are connected, which is awesome. What I would like to now is actually show you how to break it just while we're here. So I've got the text box selected. See down the bottom here, this little pill here that is showing me that this text object that I've selected has this variable assigned to it called total. I can break it by clicking this. I can also wreck it by accident by changing it.
Okay? I've worked out that if I change it to two it goes wow, just got rid of the connection and there it's broken now. Okay, it's not gonna work, so I'm gonna undo it till it was working and that's back there. Excellent. Okay, the next bit is making this plus button work. Okay, so with this selected, let's switch to prototype mode.
That's the big thing that I was kind of getting confused when I first learned this, okay, was that uh, some of the work happens in design view, some work for happens in prototype view. So in prototype mode, with this selected, I'm gonna say let's add an interaction. We've done this before. Okay, on tap, okay, or on click, doesn't matter. Okay? And I'm gonna say I'd like to set a variable on this little uh, thing I've got selected here.
What I want it to do is, first of all, it's gonna say, Hey, If you wanna do this, you need to move it to a paid account. I'm gonna do that. Okay, I'm back. So with it selected, I'm added an interaction, hitting the plus button. I'm gonna say you want to set the variable or variable, I want it to be the total. Okay?
What expression do I wanna write? So I wanna set total, which is this thing here. I wanna set it, what do I wanna do to it? I would like total to add one. I just typed in one. So I'm saying find the total and then get the total and add one to it.
There you go. It said enter on the keyboard. Kinda looks weird, but there you go. Let's see if it works. So I'm gonna go to my prototype. Let's use this snazzy new one that you haven't seen much in the course 'cause it's new.
Uh, there we go. Shift space bar and ready. Seti. Oh look at us. Goes on forever though. Okay, we don't have a minus, but there you go.
We set our first variable. High five. Not so hard. Let's make it go backwards. So let's do the same thing. I'm gonna have this selected switch to prototype mode and an interaction.
It's gonna be an ONTAP and I'd like it to be set. The variable on this thing, what do I want to set? I want it to control the total, which is this thing over here. My little zero. What I want it to do, once it's find it, I want to write the expression that says total. I want it to go minus one head into, let's see if it works.
Shift space bar and let's go. Positive, negative, positive, negative, positive, positive, positive. Negative, negative. Ne. Ah, there you go. There might be a couple of problems with yours.
You might be going like, I know there's a negative one. Am I gonna pay negative money? Are they gonna give me money? We will fix that in the next video with conditions, okay, but for the moment it's working. A couple things I wanna show you is I find it easier to operate on these things. See there's little diamonds that pop out once you've assigned the variable, they're actually easier to do it when you select them in here.
Why are they better? I don't know. This thing feels very detached over here. It's bound to look different by the time you get to it. 'cause this is brand new update for the course. Last things I wanna show you before we go is you can remove everything, uh, from these individually, these set variables.
Okay? We can say none and it will get rid of it. I'm gonna undo that if you want to get rid of the local variables. So remember in design view, nothing selected under local variables. Okay? You can go, you can right click them and say delete variable.
And if you wanna remove it off the, uh, text here, okay? You can just delete this thing here. Okay? Say detached variable and it will break it apart. There you go. We added some variables and it controlled something.
What's really cool about it is we know that in the past we've probably tried to create prototypes and just not done them okay? As efficiently because, uh, you'd end up having to make frame after frame after frame and kind of joining the prototypes together. So there you go. Let's go to the next video where we get rid of this minus, okay? And they're called conditions. See you in the next video.