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
 

Can someone explain this?

Previous Thread :: Next Thread 
R3dclaw is not online. R3dclaw
Joined: 28 Nov 2014
Total Posts: 14
06 Oct 2016 01:55 AM
Just started learning Lua, and I stumbled upon this: x=y==x
Report Abuse
Refactorize is not online. Refactorize
Joined: 02 Oct 2016
Total Posts: 172
06 Oct 2016 01:59 AM
Sure.

Before anything, x and y are both nil

"y == x"

This uses the equality operator (double equals sign). Now, since y and x are both nil, the statement y == x is true.

Now we are setting x to the value of y == x, x becomes true, and y is nil.

This is very confusing and nobody should ever use this in real code.
Report Abuse
cntkillme123 is not online. cntkillme123
Joined: 10 Feb 2013
Total Posts: 539
06 Oct 2016 02:01 AM
how is it confusing?
all relational operators (==, >=, <=, ~=, <, >) return a boolean, it's very simple

local x = 5
local y = 6
local isequal = x == y

The `x == y` is evaluated first and returns false, thus `isequal` is set to false
Report Abuse
R3dclaw is not online. R3dclaw
Joined: 28 Nov 2014
Total Posts: 14
06 Oct 2016 02:10 AM
It is pretty confusing actually, despite being slightly faster. Not as much non understandable as much as it looks weird at first glance.
Report Abuse
cntkillme123 is not online. cntkillme123
Joined: 10 Feb 2013
Total Posts: 539
06 Oct 2016 02:18 AM
faster than what, exactly?
Report Abuse
R3dclaw is not online. R3dclaw
Joined: 28 Nov 2014
Total Posts: 14
06 Oct 2016 02:21 AM
Using an if statement.
Report Abuse
cntkillme123 is not online. cntkillme123
Joined: 10 Feb 2013
Total Posts: 539
06 Oct 2016 02:28 AM
not by much, very insignificantly. just an extra jump most likely
Report Abuse
R3dclaw is not online. R3dclaw
Joined: 28 Nov 2014
Total Posts: 14
06 Oct 2016 02:43 AM
Still is considerable when in loops that repeat many times.
Report Abuse
cntkillme123 is not online. cntkillme123
Joined: 10 Feb 2013
Total Posts: 539
06 Oct 2016 02:44 AM
Not really considering why would you ever have to continuously set a variable to true/false depending on whether or not it's equal? Mostly you're just checking it is't non-falsey (i.e. if x then)
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