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 » Scripting Helpers
Home Search
 

Re: Boolean Logic help

Previous Thread :: Next Thread 
StealthKing95 is not online. StealthKing95
Joined: 13 Dec 2008
Total Posts: 4263
07 Oct 2013 02:51 PM
if right ~= nil and left ~= nil and front ~= nil and back ~= nil and above ~= nil then



how do i change that line so only 3 of them instead of 4 needs to be true
Report Abuse
bballer13sn is not online. bballer13sn
Joined: 03 Jun 2009
Total Posts: 2490
07 Oct 2013 02:54 PM
Like this:

areTrue = 0
sides = {right,left,front,back}
for i,v in ipairs(sides) do
if v then areTrue = areTrue + 1 end
end

if areTrue >= 3 then
Report Abuse
StealthKing95 is not online. StealthKing95
Joined: 13 Dec 2008
Total Posts: 4263
07 Oct 2013 02:55 PM
Yeah I was gonna do that I hoped there was a clean way of doing it on one line :P
Report Abuse
bballer13sn is not online. bballer13sn
Joined: 03 Jun 2009
Total Posts: 2490
07 Oct 2013 02:55 PM
Not that I can think of, no. I'm sorry.
Report Abuse
breuning is not online. breuning
Joined: 30 Oct 2008
Total Posts: 4268
07 Oct 2013 03:00 PM

function GetTrueCount() -- im tired, so its very very inefficient but well ok
local count = 0
local a
local b
local c
local d

if right == true then
a = right
count = count+1
end

if left == true then
if a== nil then
a = left
else
b= left
end
count = count +1
end

if front == true then
if a== nil then
a = front
elseif b == nil then
b= front
else
c = front
end
count = count +1
end

if above== true then
if a== nil then
a = above
elseif b == nil then
b= above
elseif c==nil then
c = above
else
d = above
end
count = count +1
end

return count,a,b,c,d

end



if GetTrueCount() >= 3 then
Report Abuse
bballer13sn is not online. bballer13sn
Joined: 03 Jun 2009
Total Posts: 2490
07 Oct 2013 03:01 PM
Hmmm...I like his idea! Here, this would be my guess for the easiest way possible:

function atLeastThreeSides()
areTrue = 0
sides = {right,left,front,back}
for i,v in ipairs(sides) do
if v then areTrue = areTrue + 1 end
end

return areTrue >= 3
end

if atLeastThreeSides() then
Report Abuse
MutualSacrifice is not online. MutualSacrifice
Joined: 05 Oct 2013
Total Posts: 48
07 Oct 2013 03:01 PM
No loop. I don't like loops:

areTrue = 0
bump = function() areTrue = areTrue + 1 end
if right then bump() end
if left then bump() end
if front then bump() end
if back then bump() end

if areTrue >= 3 then
Report Abuse
bballer13sn is not online. bballer13sn
Joined: 03 Jun 2009
Total Posts: 2490
07 Oct 2013 03:02 PM
Loops are a million times more efficient than what you just posted... :/
Report Abuse
breuning is not online. breuning
Joined: 30 Oct 2008
Total Posts: 4268
07 Oct 2013 03:03 PM
stop bragging, mine is most ineffiecient.
Report Abuse
bballer13sn is not online. bballer13sn
Joined: 03 Jun 2009
Total Posts: 2490
07 Oct 2013 03:04 PM
I will admit...Yours is by far the least efficient. :P
Report Abuse
breuning is not online. breuning
Joined: 30 Oct 2008
Total Posts: 4268
07 Oct 2013 03:04 PM
yes, i am the king of ineffieciency

go to hell generic for loops!
Report Abuse
MutualSacrifice is not online. MutualSacrifice
Joined: 05 Oct 2013
Total Posts: 48
07 Oct 2013 03:08 PM
More code

function wat(flu,xa,xb,xc,xd,xe,xf)
return flu<=(xa and 1 or 0)+(xb and 1 or 0)+(xc and 1 or 0)+(xd and 1 or 0)+(xe and 1 or 0)+(xf and 1 or 0) and true or false
end


ThisIsWhatOPWants = wat(3,right,left,front,back,top)
Report Abuse
JoshuaKempfert is not online. JoshuaKempfert
Joined: 16 Feb 2013
Total Posts: 2407
07 Oct 2013 03:19 PM
@BBaller
I really don't think you know the difference between efficiency and inefficiency.
Report Abuse
bballer13sn is not online. bballer13sn
Joined: 03 Jun 2009
Total Posts: 2490
07 Oct 2013 03:20 PM
My version is the most efficient as it reuses variables rather than creating new ones for every single check... :/
Report Abuse
JoshuaKempfert is not online. JoshuaKempfert
Joined: 16 Feb 2013
Total Posts: 2407
07 Oct 2013 03:23 PM
I wasn't talking about you're script, it just seems with how you use the word efficient that you don't really know the real meaning.
Report Abuse
digpoe is not online. digpoe
Joined: 02 Nov 2008
Total Posts: 9092
07 Oct 2013 03:24 PM
if a and b and c and d then

One line? acomplished.
Report Abuse
bballer13sn is not online. bballer13sn
Joined: 03 Jun 2009
Total Posts: 2490
07 Oct 2013 03:24 PM
Well what do you define the word as?
Report Abuse
bballer13sn is not online. bballer13sn
Joined: 03 Jun 2009
Total Posts: 2490
07 Oct 2013 03:25 PM
@digpoe: He wanted to find a way to do it so that only three of the four had to be true.
Report Abuse
digpoe is not online. digpoe
Joined: 02 Nov 2008
Total Posts: 9092
07 Oct 2013 03:26 PM
Also, here's what you were looking for:

if (function(...) local ret = 0 for _, v in pairs{...} do if v then ret = ret + 1 end end return ret end)(a, b, c, d) >= 3 then
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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