|
| 07 Sep 2016 12:13 PM |
if statement???
function red() script.Parent.BrickColor = BrickColor.new("Bright red") end
red()
if red() == then -- Trying to say if the brick is red then print the brick is red print("the brick is red") else print ("the brick is not red") end
i am new to lua so just wondering. |
|
|
| Report Abuse |
|
|
|
| 07 Sep 2016 12:13 PM |
i get this error:
Workspace.Part.Script:10: unexpected symbol near 'then' |
|
|
| Report Abuse |
|
|
OzzyFin
|
  |
| Joined: 07 Jun 2011 |
| Total Posts: 3600 |
|
|
| 07 Sep 2016 12:18 PM |
For an if statement to go through, all the statements have to be true. Your red function returns nil.
local function isRed() return script.Parent.BrickColor == BrickColor.new("Bright red") end
if isRed() then print("is red") else print("is not red") end |
|
|
| Report Abuse |
|
|
|
| 07 Sep 2016 12:21 PM |
why would you add local in front of function????
why would you add return infront of script??
also when I call the function isRed() the brick does not turn red??? |
|
|
| Report Abuse |
|
|
OzzyFin
|
  |
| Joined: 07 Jun 2011 |
| Total Posts: 3600 |
|
|
| 07 Sep 2016 12:24 PM |
There is no reason to check if the brick is red if you turn it red?
local variables are just good practice
return is difficult to explain because it does what it says, returns a value |
|
|
| Report Abuse |
|
|
|
| 07 Sep 2016 12:27 PM |
| right now im just messing around. how would I make the script print "the brick is red" if its red?? |
|
|
| Report Abuse |
|
|
|
| 07 Sep 2016 12:30 PM |
| ################################################################################################################################################################################################################################################################################################################################## |
|
|
| Report Abuse |
|
|
|
| 07 Sep 2016 12:32 PM |
i updated the script but now it looks Ug1ly
local function isRed() script.Parent.BrickColor = BrickColor.new("Bright red") end
isRed()
if script.Parent.BrickColor == BrickColor.new("Bright red") == true then
print("is red") else print("is not red") end
is there anyway to clean this up??? thanks for the help |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 07 Sep 2016 12:39 PM |
--You don't need to put local infront of functions unless they are inside another function --Anyways,
local part = script.Parent
IsRed = function(part) if part.BrickColor == BrickColor.new('Bright red') then return true end end
if IsRed(part) then print('Is red') else print('Is not red') part.BrickColor = BrickColor.new('Bright red') end
|
|
|
| Report Abuse |
|
|
qqtt991
|
  |
| Joined: 14 Dec 2007 |
| Total Posts: 1387 |
|
|
| 07 Sep 2016 01:40 PM |
Kid, you clearly have no idea how programming works lmfao.
It might be in your better interest to look up programming basics to help you understand how functions and return statements work, as well as variable scopes (why you use local). I guarantee everything to do with Lua will be much more clear as soon as you understand the basics.
|
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 07 Sep 2016 01:44 PM |
This is cute. Keep crying little girl.
|
|
|
| Report Abuse |
|
|
qqtt991
|
  |
| Joined: 14 Dec 2007 |
| Total Posts: 1387 |
|
|
| 07 Sep 2016 01:45 PM |
???????Referring to OP ya sperg.
|
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
| |
|
Skellobit
|
  |
| Joined: 13 Apr 2016 |
| Total Posts: 12758 |
|
|
| 07 Sep 2016 02:09 PM |
if you're comparing a function in a conditional statement, then you're comparing whatever the function returns
Formerly ToxicDominator - add 17,509 posts |
|
|
| Report Abuse |
|
|
qqtt991
|
  |
| Joined: 14 Dec 2007 |
| Total Posts: 1387 |
|
|
| 07 Sep 2016 02:32 PM |
Here, paste this into your URL bar. It's a heavily commented little script that does what you're trying to do. I did my best to explain everything I'm doing in simple terms. If you have any questions I'll see if I can answer them.
past ebin. com/ HkfvYm1K
|
|
|
| Report Abuse |
|
|
Skellobit
|
  |
| Joined: 13 Apr 2016 |
| Total Posts: 12758 |
|
|
| 07 Sep 2016 02:34 PM |
explain to him what comparing a called function in a conditional statement does and that "if checkIfRed(script.Parent)" is the same thing as doing "if checkIfRed(script.Parent) == true" because apparently I'm not good at explaining things
Formerly ToxicDominator - add 17,509 posts |
|
|
| Report Abuse |
|
|
|
| 07 Sep 2016 02:42 PM |
"--You don't need to put local infront of functions unless they are inside another function" Then why did you add local in front of the part variable when it wasn't inside another function? Last i checked functions are firstclass values and your argument is stupid |
|
|
| Report Abuse |
|
|
qqtt991
|
  |
| Joined: 14 Dec 2007 |
| Total Posts: 1387 |
|
|
| 07 Sep 2016 02:42 PM |
| Essentially, when you call a function that returns something, the function call itself is replaced with the returned value. So if you call checkIfRed, and ############# ## red: checkIfRed(script.Parent) becomes true So following this idea: if checkIfRed(script.Parent) then -- Stuff end becomes if true then -- Stuff end So furthermore: if checkIfRed(script.Parent) == true then -- Stuff end becomes if true == true then -- Stuff end They behave exactly the same way, but one way is slightly more silly. I prefer not to use "== true" or "== false" in a conditional statement because of the redundancy. |
|
|
| Report Abuse |
|
|
qqtt991
|
  |
| Joined: 14 Dec 2007 |
| Total Posts: 1387 |
|
|
| 07 Sep 2016 02:43 PM |
LORDY LOO I hate this website.
Here's my reply in readable form:
past ebin. com/ Qq2P6G9m
|
|
|
| Report Abuse |
|
|
|
| 07 Sep 2016 03:16 PM |
--[[if statement???]]
function red() if(script.Parent.BrickColor==BrickColor.new("Bright red"))then return(true)else return(false) end;end
--[[red()]]
if red()--[[==]]then --[[-- Trying to say if the brick is red then print the brick is red]] print("the brick is red") else print ("the brick is not red") end
--[[i am new to lua so just wondering.]] |
|
|
| Report Abuse |
|
|