generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
We use cookies to offer you a better experience. By using Roblox.com, you are agreeing to our Privacy and Cookie Policy.
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: can you call on a function in a

Previous Thread :: Next Thread 
egginatormc is not online. egginatormc
Joined: 13 Jul 2015
Total Posts: 87
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
egginatormc is not online. egginatormc
Joined: 13 Jul 2015
Total Posts: 87
07 Sep 2016 12:13 PM
i get this error:


Workspace.Part.Script:10: unexpected symbol near 'then'
Report Abuse
OzzyFin is not online. 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
egginatormc is not online. egginatormc
Joined: 13 Jul 2015
Total Posts: 87
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 is not online. 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
egginatormc is not online. egginatormc
Joined: 13 Jul 2015
Total Posts: 87
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
egginatormc is not online. egginatormc
Joined: 13 Jul 2015
Total Posts: 87
07 Sep 2016 12:30 PM
##################################################################################################################################################################################################################################################################################################################################
Report Abuse
egginatormc is not online. egginatormc
Joined: 13 Jul 2015
Total Posts: 87
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 is not online. 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 is not online. 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 is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
07 Sep 2016 01:44 PM
This is cute. Keep crying little girl.


Report Abuse
qqtt991 is not online. qqtt991
Joined: 14 Dec 2007
Total Posts: 1387
07 Sep 2016 01:45 PM
???????Referring to OP ya sperg.


Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
07 Sep 2016 01:46 PM
@OP *


Report Abuse
Skellobit is not online. 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 is not online. 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 is not online. 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
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
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 is not online. 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 is not online. 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
Milenveliki is not online. Milenveliki
Joined: 14 Aug 2013
Total Posts: 1097
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image