If statement with no condition?

Ok, so I’m trying to understand someone else’s code. I tried to look it up on google and dev but couldn’t find anything on the topic. So I understand how booleans and condition statements work. but I ran into someones code that defies that.



	if gradualTextInProgress then
		return
	end
	

There’s no conditional. So what is it asking? If gradualTextInProgress is true? is it false?
Can someone please explain how this condition statement works? Below is the more code if that helps. Thanks!

local gradualTextInProgress = false


local function gradualText(text)
	
	if gradualTextInProgress then
		return
	end
	
	local length = string.len(text)
	
	for i = 1, length, 1 do
		gradualTextInProgress = true
		DialogFrame.DialogText.Text = string.sub(text, 1, i)
		wait()
	end
	
	gradualTextInProgress = false
end

Inside the script the gradualTextInProgress is false so it will not return and then run the code below
edited i made a mistake lol

1 Like

sorry if im bad at explaining but you can put a boolean value between if and then it will still work

If an if condition contains a variable with no “==” sign, then the condition will only run if the value of the variable is true or contains any value.

In this case, if the variable (gradualTextInProgress) is true, it stops the function using return.


Also, if an if condition looks like this:

if not condition then
  --...
end

then the statement will only run if the variable (condition) is false or nil.

2 Likes

so its the same as

if gradualTextInProgress == false then
return
end
??

the same as
if gradualTextInProgress ~= nil then
return
end

1 Like

ahhhh ok, thanks. I understand now

No. In programming, there are things called true, truthy, false and falsey. In Lua’s case, anything that is nil or false is considered falsey, and anything that is either true or has a value is truthy. In your case, if gradualTextInProgess is not false or nil, it will be truthy, therefore the return statement will prevent any other code from running

1 Like