A question about how and/or works

function tween(Object, Properties, Value, Time, Style, Direction)
	Style = Style or Enum.EasingStyle.Quad
	Direction = Direction or Enum.EasingDirection.Out

	Time = Time or 0.5

	local propertyGoals = {}

	local Table = (type(Value) == "table" and true) or false

	for i,Property in pairs(Properties) do
		propertyGoals[Property] = Table and Value[i] or Value
	local tweenInfo = TweenInfo.new(
	local tween = game:GetService("TweenService"):Create(Object,tweenInfo,propertyGoals)

I was browsing some open-source codes from advanced scripters when I found this function. The thing I did not understand is table variable. So, i think if type(Value) is table then it will return true if it is not it will return false, we will get

(true and true) or false
(false and true) or false
--this is what I think will happen
  1. why we need “and true” ?
  2. why Table and Value[i] or Value, can’t we just do Value[i] or Value?

The usage here is just mistaken. The usual way of doing this is:

local valueWithDefault = value or defaultValue

if value is nil or false, valueWithDefault will be set to defaultValue. The way this is used here has no effect because the result of == can only be true or false, and true by definition has no effect and so does or false

Your examples are odd, but and/or exclude and include when certain circumstances allow something to happen. This also comes with the use of parenthesis, as Order of Operations is utilized.

For example,

if (Char.Humanoid.Health==0 and Char.Humanoid:GetState()==Enum.HumanoidStateType.Dead) or Char:FindFirstChild'Humanoid'==false then

The above statement proceeds if the Health is 0 and the state is Dead, but also proceeds if it cannot find the humanoid.

okay I understand. Can we just do Value[i] or Value? it should be
nil or value
index or table
im not sure about what second one returns but it should be the first one which is index, right?

local Table should actually be called something like isTable because its true if Value is a table and false otherwise. This makes it so the second case gives Value[i] if Value is a table, otherwise just Value. This is a bad way of writing this though, since this could have just been an if statement.

Thanks for help guys, I would use if statement too but this takes less space I think thats why he did that. I will mark it as solution.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.