Author Topic: concatenating variables?  (Read 3565 times)

0 Members and 1 Guest are viewing this topic.

Offline Barticus

  • Newbie
  • *
  • Posts: 9
  • Karma: +0/-0
concatenating variables?
« 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

PtokaX forum

concatenating variables?
« on: 16 October, 2005, 21:12:48 »

Offline Dessamator

  • Scripter
  • Emperor
  • ******
  • Posts: 1 262
  • Karma: +13/-9
(No subject)
« Reply #1 on: 16 October, 2005, 21:43:04 »
First store ur commands in tables then access them as u wish.
Ignorance is Bliss.

Offline plop

  • Forum God
  • ****
  • Posts: 2 464
  • Karma: +37/-0
(No subject)
« Reply #2 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
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

Offline Barticus

  • Newbie
  • *
  • Posts: 9
  • Karma: +0/-0
(No subject)
« Reply #3 on: 17 October, 2005, 15:29:36 »
thanks  to you both. :D

PtokaX forum

(No subject)
« Reply #3 on: 17 October, 2005, 15:29:36 »