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: Finding differences in different tables

Previous Thread :: Next Thread 
KAMIKAZEPOLO is not online. KAMIKAZEPOLO
Joined: 14 Mar 2012
Total Posts: 1049
03 Oct 2015 09:46 PM
Is there a way to find a difference in tables and identify which index/value it is?
For example:

table1 = {"cat", "dog"}
table2 = {"cat", "dog", "catdog"}

if table1 ~= table2 then
blah blah
end

Any replies are appreciated :D.
Report Abuse
cntkillme123 is not online. cntkillme123
Joined: 10 Feb 2013
Total Posts: 539
03 Oct 2015 09:48 PM
You can do something like:

local function compareArrays(tbl1, tb2)
if #tbl1 ~= #tbl2 then return false; end
for key = 1, #tbl1 do
if tbl1[key] ~= tbl2[key] then return false; end
end
return true;
end
Report Abuse
KAMIKAZEPOLO is not online. KAMIKAZEPOLO
Joined: 14 Mar 2012
Total Posts: 1049
03 Oct 2015 09:53 PM
Thanks for the reply!

What is the purpose of putting local behind function? I understand scopes of variables, but I don't really understand the reasoning behind local functions.

Also what's up with the semi-colons?
Report Abuse
bosswalrus is not online. bosswalrus
Joined: 04 Jan 2013
Total Posts: 5430
03 Oct 2015 09:55 PM
it is the same thing like local variables I assume
Report Abuse
cntkillme123 is not online. cntkillme123
Joined: 10 Feb 2013
Total Posts: 539
03 Oct 2015 10:04 PM
'What is the purpose of putting local behind function? I understand scopes of variables, but I don't really understand the reasoning behind local functions.'
In Lua, references to functions are held by variables.

So: function a() end
Is the same as: a = function() end;

Whereas: local function a()
Is the same as: local a; a = function() end;



Also I use semi-colons for no reason, you don't need them.
Report Abuse
KAMIKAZEPOLO is not online. KAMIKAZEPOLO
Joined: 14 Mar 2012
Total Posts: 1049
03 Oct 2015 10:24 PM
Alright, but what is the difference that local makes? I mean, I can see that a variable has a different value based on where you put inside of a function, if it's local.
Report Abuse
cntkillme123 is not online. cntkillme123
Joined: 10 Feb 2013
Total Posts: 539
03 Oct 2015 10:26 PM
It can only be accessed within that scope, so for example:

do -- create a new scope
local function abc()
print("hi");
end
abc(); abc(); -- print hi twice
end

abc(); -- error, abc is nil ehre
Report Abuse
KAMIKAZEPOLO is not online. KAMIKAZEPOLO
Joined: 14 Mar 2012
Total Posts: 1049
03 Oct 2015 10:34 PM
You put semicolons because you used java, right? I know it's not required for LUA, but that's why you use them, right?
Report Abuse
BusyCityGuy is not online. BusyCityGuy
Joined: 17 Aug 2012
Total Posts: 2144
03 Oct 2015 10:35 PM
What, what is LUA again?

-The [Guy]
Report Abuse
cntkillme123 is not online. cntkillme123
Joined: 10 Feb 2013
Total Posts: 539
03 Oct 2015 10:35 PM
Not because of Java, also woops I read what you wanted wrong.
Mine gives you whether there were any differences at all or not, not all the differences.

All you really need to do though is create a table, for every difference insert the key (remove the return in the loop) and return that table.
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