Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make this If statement work?

Asked by 7 years ago
Edited 7 years ago

I am trying to make something that if someone types something other than a certain word into this text box, it will return something different than if they said what they were supposed to say. For example, in my script that I'm trying to make, a question comes up asking "Would you like a bow or a sword?" and I want people who say sword or bow to get a different response than they would get if they say something random like noodles.

This is what I have so far:


local input = script.Parent.TextBox local output = script.Parent.TextLabel local function raw_input(prompt) local text = "" output.Text = prompt input:CaptureFocus() local event = input.FocusLost:connect(function(enterPressed) if enterPressed and input.Text ~= "" then text = input.Text else input:CaptureFocus() end end) repeat wait() until text ~= "" return text end local response = raw_input("What is your name?") output.Text = "Hello, " .. response .. "!" repeat wait(2) until text ~= "" response = raw_input("Would you like to go on a quest?") output.Text = "" .. response .. "? You didn't have a choice. It was always going to be yes." wait(3) response = raw_input("You will need a weapon. Would you like a bow or sword?") if input.Text = "bow" or "sword" then output.Text = "Great choice! I knew you would pick the " .. response .. "!" else output.Text = "What? What is a " .. response .. "? Please pick a sword or bow." end

2 answers

Log in to vote
0
Answered by
Zeoic 40
7 years ago

if input.Text = "bow" or input.Text = "sword" then

Ad
Log in to vote
0
Answered by
Link150 1355 Badge of Merit Moderation Voter
7 years ago

On line #26, you wrote:

if input.Text = "bow" or "sword" then

This is wrong. In Lua, and many other programming languages, the = operator is used to assign a value to a variable. What you are looking for is the equality comparison operator ==, which returns true if, and only if both of its operands are equal.

Also, while it may seem logical to simply append your comparison with or x to compare a variable multiple times, this isn't valid syntax. The correct syntax is a == b or a == c.

if input.Text == "bow" or input.Text == "sword" then

Answer this question