WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Variables problem (https://www.wowinterface.com/forums/showthread.php?t=34759)

dr_AllCOM3 09-03-10 05:54 AM

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

Sekrin 09-03-10 07:24 AM

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.

yj589794 09-03-10 07:35 AM

Are you trying to do a sort, or just to swap the values?

dr_AllCOM3 09-03-10 07:45 AM

What I'm trying to do is swapping two statusbars, but I seem to fail.

haste 09-03-10 08:10 AM

Code:

a[1], a[2] = a[2], a[1]
will work fine, no need for a temporary variable.


All times are GMT -6. The time now is 02:47 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI