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

How to make "if" for string value? How to release this script, to work it?

Asked by
Shaehl -11
6 years ago

I want this:

local randomString = "Random"

if randomString = **string** then
print("Its a string!")
else
print("Its isn't a string!")
end

But how to release this script, to work it?

2 answers

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

Use type. Type will return table, string, number, boolean, or userdata if it's one. local randomString = "Random" if type(randomString) == "string" then print("Its a string!") else print("Its isn't a string!") end

0
What I need! Shaehl -11 — 6y
0
Shouldn't `type(randomString) = "string"` be `type(randomString) == "string"` ? fredfishy 833 — 6y
0
^ SulaymanArafat 230 — 6y
0
Yes, common error lol User#22219 20 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

Using type() will help you here! Here's some code I put through lua and the results to help you out:

local f = 1
local sa = "1"
print(type("fsa"))
print(type(f..sa))
print(type(f))
print(type(sa))
print(type(function() print("foobar") end))

Output:

string
string
number
string
function

For example:

if(type("string") == "string") then
print("foo")
else
print("bar")
end

Output:

foo

If you need any help just ask! :D

Answer this question