PtokaX forum

Archive => Archived 4.0 boards => Help with Lua 4 scripts => Topic started by: Barticus on 16 October, 2005, 21:12:48

Title: concatenating variables?
Post by: Barticus on 16 October, 2005, 21:12:48
I'm having a great time working on a very complicated mod, and everything is runing smoothly.

The problem I am having is with some major, major clutter, simply because I can't seem to figure out how concatenate, or append, a variable to the another variable.  Here's an example of my clutter, and hopefully someone here can tell me how to clean it up.

function MT_RightClick()
   if MT_FrameClick==1 then
      TargName1=""
      TargFrame1:Hide()
   elseif MT_FrameClick==2 then
      TargName2=""
      TargFrame2:Hide()
   elseif MT_FrameClick==3 then
      TargName3=""
      TargFrame3:Hide()
   elseif MT_FrameClick==4 then
      TargName4=""
      TargFrame4:Hide()
   elseif MT_FrameClick==5 then
      TargName5=""
      TargFrame5:Hide()
   elseif MT_FrameClick==6 then
      TargName6=""
      TargFrame6:Hide()
   end
end

I know some looping would be involved here.  What I can't seem to get is how to put two variables together (One from the loop, and the other from local/globals), to piece togeher a single variable I can use in an if statement within the loop.

Any help is very much appreciated, as my project is getting a bit out of hand with all the messy lists of commands like the one above.

Thanks in advanced.

-Bart
Title:
Post by: Dessamator on 16 October, 2005, 21:43:04
First store ur commands in tables then access them as u wish.
Title:
Post by: plop on 16 October, 2005, 23:20:28
lua can only make a new var from other vars.
var_total = var1..var2
but you can re-use 1 of the old offcourse
var1 = var1..var2

other example of what dessamator ment.
Code: [Select]
-- this table stores all the functions, indexed by number MT_RightClick
tClick = {
[1] = function()
TargName1=""
TargFrame1:Hide()
end,
[2] = function()
TargName2=""
TargFrame2:Hide()
end,
[3] = function()
TargName3=""
TargFrame3:Hide()
end,
[4] = function()
TargName4=""
TargFrame4:Hide()
end,
[5] = function()
TargName5=""
TargFrame5:Hide()
end,
[6] = function()
TargName6=""
TargFrame6:Hide()
end,
}

function MT_RightClick(var)
if tClick[MT_FrameClick] then
-- code in the function is allready executed by the above call if it excisted.
end
end

plop
Title:
Post by: Barticus on 17 October, 2005, 15:29:36
thanks  to you both. :D