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: Where else can I use =='s and ~='s in besides if statements?

Previous Thread :: Next Thread 
myaka27too is not online. myaka27too
Joined: 20 Dec 2010
Total Posts: 31
19 Mar 2012 08:39 PM
I am wondering where can I use =='s and ~='s, excluding if statements. I have heard people saying that you can, I don't know where though.

Lolly-pop land activated.
Report Abuse
crazytomato4 is not online. crazytomato4
Joined: 09 Feb 2011
Total Posts: 1368
19 Mar 2012 08:41 PM
Anywhere that it makes sense to use them.
Report Abuse
vexStudio is not online. vexStudio
Joined: 18 Mar 2012
Total Posts: 55
19 Mar 2012 08:42 PM
As far as my knowledge of (RBX.)Lua goes, you don't use them outside of conditionals.

{ Scripting level - intermediate. }
Report Abuse
FlameTempest is not online. FlameTempest
Joined: 09 Mar 2012
Total Posts: 16
19 Mar 2012 08:50 PM
That is not true. Ternary Operators can use comparison operators, too.
Report Abuse
vexStudio is not online. vexStudio
Joined: 18 Mar 2012
Total Posts: 55
19 Mar 2012 08:53 PM
Ternary operators use the and, not, and or operators. He was asking about the equal to and not equal to operators.

{ Scripting level - intermediate. }
Report Abuse
crazytomato4 is not online. crazytomato4
Joined: 09 Feb 2011
Total Posts: 1368
19 Mar 2012 08:54 PM
Again, you can use them ANYWHERE.

Workspace.Part.CanCollide = game.Players.LocalPlayer ~= potato

(a == 1 and function(a) a:Destroy() end or print)(Workspace.Part)

And anything else you can think of that could possibly use those operators.
Report Abuse
myaka27too is not online. myaka27too
Joined: 20 Dec 2010
Total Posts: 31
19 Mar 2012 08:55 PM
Ternary operators belong into if statements, as far as I know, so technically it would be classified into being part of an if statements.

Annoying the crap out of you, one word at a time. -Says suoicodilaipxecitsaligirfilacrepus repeatedly-
Report Abuse
vexStudio is not online. vexStudio
Joined: 18 Mar 2012
Total Posts: 55
19 Mar 2012 08:55 PM
@crazytomato4

I never really thought about it that way. Interesting. Especially the first example.

{ Scripting level - intermediate. }
Report Abuse
crazytomato4 is not online. crazytomato4
Joined: 09 Feb 2011
Total Posts: 1368
19 Mar 2012 08:55 PM
Just realized that I overwrote a variable in that second line of code. Raig. :l

(a == 1 and function(b) b:Destroy() end or print)(Workspace.Part)

Even though it doesn't matter in the slightest in this case, overwritten variables are a no no. :c
Report Abuse
myaka27too is not online. myaka27too
Joined: 20 Dec 2010
Total Posts: 31
19 Mar 2012 08:56 PM
@crazypotato

That would error. You don't use ~= or == when assigning a variable.

Annoying the crap out of you, one word at a time. -Says suoicodilaipxecitsaligirfilacrepus repeatedly-
Report Abuse
SDuke524 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
19 Mar 2012 08:56 PM
Those aren't ternary operators. They just mimic the behavior of the ? and : of most other languages.
Report Abuse
FlameTempest is not online. FlameTempest
Joined: 09 Mar 2012
Total Posts: 16
19 Mar 2012 08:57 PM
@vex - Please refresh your memory before posting such things.

Ternary operators use comparison operators first, e.g.:

local number = 2+2 == 4 and 4 or 0
Report Abuse
crazytomato4 is not online. crazytomato4
Joined: 09 Feb 2011
Total Posts: 1368
19 Mar 2012 08:57 PM
@myaka: I may have not done anything using Lua for quite a while, but I'm pretty sure that nothing I wrote here would error.
Report Abuse
vexStudio is not online. vexStudio
Joined: 18 Mar 2012
Total Posts: 55
19 Mar 2012 08:58 PM
"Workspace.Part.CanCollide = game.Players.LocalPlayer ~= potato"

is the same as

Workspace.Part.CanCollide = true

Because game.Players.LocalPlayer isn't equal to a potato.

But you're still right, it would error. Potato is defined anywhere as a variable and it's not a string.

{ Scripting level - intermediate. }
Report Abuse
vexStudio is not online. vexStudio
Joined: 18 Mar 2012
Total Posts: 55
19 Mar 2012 08:59 PM
@FlameTempest

I'm very sorry that I rarely work with ternary operators.

{ Scripting level - intermediate. }
Report Abuse
crazytomato4 is not online. crazytomato4
Joined: 09 Feb 2011
Total Posts: 1368
19 Mar 2012 08:59 PM
@vexStudio: That line of code would usually be used in a context where the variable 'potato' is defined, but even if not, Lua is very flexible about that, it will just default the value to nil. If game.Players.LocalPlayer is nil (as it would be in a normal script), then that would be false.
Report Abuse
vexStudio is not online. vexStudio
Joined: 18 Mar 2012
Total Posts: 55
19 Mar 2012 09:01 PM
@crazytomato4

Ahhh.

{ Scripting level - intermediate. }
Report Abuse
DXPower is not online. DXPower
Joined: 21 Oct 2008
Total Posts: 2866
19 Mar 2012 09:20 PM
Did I just witness an argument inside an argument that is arguing with the argument that started inside the argument that started arguing with the argument that started the argument and started arguing with the argument of the arguing of the argument of the arguing?


PARADOX!

Annoying the crap out of you, one word at a time. -Says suoicodilaipxecitsaligirfilacrepus repeatedly-
Report Abuse
blueymaddog is not online. blueymaddog
Joined: 23 Sep 2009
Total Posts: 5459
20 Mar 2012 02:59 AM
'Ternary operators belong into if statements, as far as I know, so technically it would be classified into being part of an if statements.'

you don't make any sense boi.

@title, you can use them in boolean values, it just so happens that if statements run off boolean values


~would you like some butter with your late toast?
Report Abuse
eXoguti093 is not online. eXoguti093
Joined: 17 Oct 2008
Total Posts: 1786
20 Mar 2012 10:36 AM
You can use it in repeats

repeat x = x +1 until x == 5

(I have been doing anything in Roblox for about 3 months, but Im pretty sure that the x = x +1 is right :P, and x == 5 I know it's right)
Report Abuse
jobro13 is not online. jobro13
Joined: 05 Aug 2009
Total Posts: 2865
20 Mar 2012 11:03 AM
Guys, think of it.

The "if" statement only runs when true right? So this runs:

If true then
blablablba
end

Also, this works

If 1 == 1 then
blabllbla
end

Why does it work? 1 == 1 IS true, so it replaces this 1 == 1 part by true. So it runs.

Well then, we also can do the following by calculating and returning if the AREA is bigger than the 1st area;

function area(a,b,c,d)
local a1 = a*b
local a2 = c*d
r = a1 => a2
return r
end

--Now say we have 2 rectangles: 10*8 and 9*9. Im a dumb math user and cant see what is bigger.

function main(e,f,g,h)
area(e,f,g,h)
if r then
print("The second one is bigger or equal!")
else
print("The second one is smaller!")
end
end

main(10,8,9,9)



So? :)
Report Abuse
iCookieNL is not online. iCookieNL
Joined: 24 May 2009
Total Posts: 1103
20 Mar 2012 02:16 PM
a = "a"
b = "a"
c = (a == b)
d = (a ~= b)


@jobro


if false then else
bla
end

is same as

if true then
end

IF REACTS ON FALSE TOO.
Report Abuse
vexStudio is not online. vexStudio
Joined: 18 Mar 2012
Total Posts: 55
20 Mar 2012 03:19 PM
@eXoguti093

That's a conditional statement.

{ Scripting level - intermediate. }
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