It is currently March 28th, 2024, 8:21 pm

[Solved]ua how to set an ENTIRE array to another?

Discuss the use of Lua in Script measures.
User avatar
revolt4peace
Posts: 83
Joined: February 3rd, 2015, 4:36 pm

[Solved]ua how to set an ENTIRE array to another?

Post by revolt4peace »

With lua, how do I do something like

Code: Select all

function Initialize()
   a={}
   for i=1,100 do
      a[i] = ''
   end
   a = SetValues()
end

function Update()
end

function SetValues()
   b = {}
   for i=1,100 do
      b[i] = i
   end
   return b
end
to where I can set an entire table/array to another using a return??! I have no idea why this isn't working, it seems like it should.
Last edited by revolt4peace on March 2nd, 2015, 8:13 pm, edited 1 time in total.
-__--__-- Explodingcreeperssss --__--__-
Click Me! - My Algebra Solver for Rainmeter!
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Lua how to set an ENTIRE array to another?

Post by balala »

It works very well! Maybe try restarting Rainmeter? But your code is ok.
User avatar
revolt4peace
Posts: 83
Joined: February 3rd, 2015, 4:36 pm

Re: Lua how to set an ENTIRE array to another?

Post by revolt4peace »

Really?! Well it's not working for me :'(

Whelp, i found another way to do it, so that's okay. My only problem now is that the original array seems to become a constant or something; every time it changes it messes up the code. Any idea?
-__--__-- Explodingcreeperssss --__--__-
Click Me! - My Algebra Solver for Rainmeter!
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Lua how to set an ENTIRE array to another?

Post by balala »

Maybe try to move the code from the Initialize() to the Update() function. The Initialize() is executed just once on skin refresh, while the Update() is executed on every update of the skin.
User avatar
revolt4peace
Posts: 83
Joined: February 3rd, 2015, 4:36 pm

Re: Lua how to set an ENTIRE array to another?

Post by revolt4peace »

Here's what I did:

function Initialize()
a={}
for i=1,100 do
a = ''
end
for i=1,100 do
a = SetValues(i)
end
end

function Update()
end


Seems to work in my code, so it's all good
function SetValues(i)
b = {}
for j=1,100 do
b[j] = j
end
return b
end
-__--__-- Explodingcreeperssss --__--__-
Click Me! - My Algebra Solver for Rainmeter!
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Lua how to set an ENTIRE array to another?

Post by balala »

revolt4peace wrote:function Initialize()
a={}
for i=1,100 do
a = ''
end
for i=1,100 do
a = SetValues(i)
end
end

I think that in the for cycle of this function you should use a[i] = SetValues(i), instead of a = SetValues(i), isn't it?
MikeG621
Posts: 87
Joined: March 18th, 2013, 1:59 pm

Re: Lua how to set an ENTIRE array to another?

Post by MikeG621 »

revolt4peace wrote:

Code: Select all

function SetValues(i)
   b = {}
   for j=1,100 do
      b[j] = j
   end
   return b[i]
end
In addition to what balala said, that's also horribly inefficient. By the time Initialize() is done, you'd have completely repopulated 'b' 100 times exactly the same way each time to return only a single value each time (10,000 assignments to return 100 values). I realize that this is a very basic framework so I can't tell what your end-purpose is, but generally that's not a good way to do it. If you're going to hard-code the values for 'b', put that in Initialize first so you can just assign a=b directly when you need it.