Thread Tools Display Modes
09-03-10, 05:54 AM   #1
dr_AllCOM3
A Cyclonian
 
dr_AllCOM3's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 40
Variables problem

Code:
local a = {}
a[1] = 1
a[2] = 2
Goal:
Code:
a[1] = 2
a[2] = 1
I want those two to switch their values, but it seems like I always end up with references and both having the same value.
What is the correct way to do it?

Thanks
  Reply With Quote
09-03-10, 07:24 AM   #2
Sekrin
A Chromatic Dragonspawn
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 150
Code:
local tempVar = a[1];
a[1] = a[2];
a[2] = tempVar;
As far as I'm aware there's no command in Lua to say "switch the contents of these two variables", so you have to use a temporary holding variable to do it.
__________________
  Reply With Quote
09-03-10, 07:35 AM   #3
yj589794
A Rage Talon Dragon Guard
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 314
Are you trying to do a sort, or just to swap the values?
  Reply With Quote
09-03-10, 07:45 AM   #4
dr_AllCOM3
A Cyclonian
 
dr_AllCOM3's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 40
What I'm trying to do is swapping two statusbars, but I seem to fail.
  Reply With Quote
09-03-10, 08:10 AM   #5
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
Code:
a[1], a[2] = a[2], a[1]
will work fine, no need for a temporary variable.
__________________
「貴方は1人じゃないよ」
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Variables problem

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off