concatenating variables?
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

concatenating variables?

Started by Barticus, 16 October, 2005, 21:12:48

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Barticus

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

Dessamator

First store ur commands in tables then access them as u wish.
Ignorance is Bliss.

plop

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.
-- 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 <----<<

Barticus

thanks  to you both. :D

SMF spam blocked by CleanTalk