Rock U - Lava - If Statements
Transcribed Video Content
Okay. So let's look at if statements within Lava. Hopefully, at this point you're very comfortable with using, filters within Lava and let's start looking at putting some conditional logic with inside your Lava. Okay. So if we take a very simple example, say we have current person and we want to look at and put a different message up depending on what their connection status is.
Okay. So within our current person, we do know the connection status. That's a value ID. So we it's a number. And so what we're gonna do here is we're gonna say if the current person's connection status value ID equals one, which means they're a member, we're gonna say welcome member.
Else if so otherwise, if the current person's connection status value ID is equal to a two or it's equal to a three, then say welcome and just put their nickname. Otherwise, if it's not any of those, if it's not one, two or three, just say welcome. Okay. And so this is a very, in some ways a complex if statement because it has basically all the options in one. A lot of times you're just saying if this, do that, end if.
And one the things you should note whenever you look at tags and that's what these things are called in in Lava, the open brace and then the the percent sign. These are tags. They usually work in pairs. Okay? So the if has an end if.
Okay? So whenever you have an if, make sure you have an end if. Otherwise you will get an error. So that's a basic if statement. Notice that there's a few different ways of of checking the the value.
So we we used equals, but you could and that's two equal signs. You could say not equal and that's an exclamation point equal sign. You could do greater than, less than, greater than or equal to or less than or equal to. And just note, if you're getting started, the equal sign always comes last. Okay?
Then also in our example, we saw the use of the word or. So if I have two conditionals and I wanna say this or this, I used to use the word or. And if I wanna use and, so it's this and this, I would just use the word and. And there's also this contains. And that basically says, does a string contain, a certain set of characters?
But for the most part, we're using the the, equal, not equal, less than equal to's, and these ands or ors. Okay? So this is basically your toolkit for the if conditionals. Now, let's look at kind of an advanced topic. So say I'm doing this with an if statement.
Notice here that I'm trying to get today's date. I'm trying to get the hour of today's date. Okay? And I wanna do some if checking on that. So I wanna try to say, is it is it morning, afternoon, or evening?
You'd be tempted maybe to do this and basically to use now and then pipe it into date to get the hour. Now, this is this is the thing you have to remember. Inside of an if statement, you you cannot, as part of your conditional, conditional, have a filter. Okay? So this is in red lava error because we have a filter in our if statement.
So with an if statement, this is the other thing you should know about is that you first must assign it to a variable. And by assigning it to a variable, it removes the need for the filter inside of the conditional. Okay. So up here, we're getting our hour and we can use our our filter inside of the assign which gives us the variable hour and then we just compare hour here. Okay.
So when you're doing it if statements, just keep that in mind. And as always, , the Rock, lava page shows you a lot of information. There's a whole, section on on the if else and so that will walk you through how that works.