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
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: if and or

Previous Thread :: Next Thread 
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
20 May 2016 10:19 AM
I need to do something like this:
x = 1
y = 2

if x == 1 and y == 2 then
-- do something
elseif x == 1 and y == 2 or y == 3 then
-- do something
end

So, I'm assuming something like this wouldn't work because 'or' wouldn't know whether to use the initial 'if' or the 'and'.
I want to say something like

elseif x==1 and (y==2 or y ==3) then
-- do something
end

...if that makes sense.
Report Abuse
Isaac020717 is online. Isaac020717
Joined: 20 Jun 2014
Total Posts: 66
20 May 2016 10:29 AM
I think your

elseif x == 1 and y == 2 or y == 3 then
-- do something
end

would work, just make a new game and try it though, but I'm pretty sure that will work.
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
20 May 2016 10:29 AM
and takes precedence over or

(a and b or c) is equivalent to ((a and b) or c)

What this means for you is that sticking brackets around your code does exactly what you think it does.
Report Abuse
guges is not online. guges
Joined: 07 May 2016
Total Posts: 1515
20 May 2016 10:30 AM
yeah just stick that ho in some parentheses
Report Abuse
Isaac020717 is online. Isaac020717
Joined: 20 Jun 2014
Total Posts: 66
20 May 2016 10:38 AM
hmm.. cool, didn't know that.
Report Abuse
BJCarpenter is online. BJCarpenter
Joined: 04 Nov 2008
Total Posts: 4416
20 May 2016 10:49 AM
Maybe, you only wanted an explaination of precedence, but your original code was kind of silly:

if x == 1 and y == 2 then
-- do something
elseif x == 1 and (y == 2 or y == 3) then -- y will never be 2 here, because that was already handeled above.
-- do something
end


your OP was simply redundant:

if x == 1 and y == 2 then
-- do something
elseif (x == 1 and y == 2) or y == 3 then -- again, the stuff in brackets has already been handled, and will never be true.
-- do something
end

Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
20 May 2016 01:07 PM
@BJ, This code was conceptual. In my real code, there are many factors that determine the value of y.
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