array element as variable problem ..
 

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

array element as variable problem ..

Started by Barticus, 17 October, 2005, 15:28:33

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Barticus

In the simplest terms, my problem is thus:

--the array:

FontStrings = { fontstring1, fontstring2 }

--the problem I'm having:

xyz = fontstring1
   xyz:SetText("hello")  --this method works (prints fontstring1)

xyz = FontStrings[1]
   xyz:SetText("hello")  --this method doesn't,  and I need it to.

Any help is appreciated.

--Bart


6Marilyn6Manson6

QuoteOriginally posted by Barticus
In the simplest terms, my problem is thus:

--the array:

FontStrings = { fontstring1, fontstring2 }

--the problem I'm having:

xyz = fontstring1
   xyz:SetText("hello")  --this method works (prints fontstring1)

xyz = FontStrings[1]
   xyz:SetText("hello")  --this method doesn't,  and I need it to.

Any help is appreciated.

--Bart



xyz = FontStrings[1]
   xyz:SetText("hello")  --this method doesn't,  and I need it to.

this not work because caps not is good.. :). c ya

Barticus

#2
hmm, I may be confused.

Do you mean I shouldn't have the table name be capitalized?

There is no mismatch in cases in the example I gave.

Here, I'll break it down even further:
z { y }
x=y --works
x = z[1] --doesn't
--where...
x:SetText("hi")
--is concerned.

I'd like to know why that is, and how to set x to = y via the array element

thanks again.

bastya_elvtars

This works for me:
x="hey"
y="hi"
arr={x,y}

print(arr[1],arr[2])
Everything could have been anything else and it would have just as much meaning.

Barticus

#4
QuoteOriginally posted by bastya_elvtars
This works for me:
x="hey"
y="hi"
arr={x,y}

print(arr[1],arr[2])

Yeah, but you'll notice that the value in my array is not a string -- in fact, I guess it registers as a key, since it's not an integer or a string.   I'm trying to call it as a variable.  I guess I can't do that?

I'm trying to put oft-repeated variables in a table to shorten things up (get rid of some clutter), and place loops in certain functions calling the elements of the array as the variables in the loop.

as in:

frames { frame1, frame2, frame3}

for i=1, 3 do
frame:Show()
end

so 3 different unique frames listed in the array called targframe pop up.

I've messed around a bit with making the table a dictionary and toying with..

for key, value in frames do

..I seem to run into the same brick wall.  I think I need some way of identifying the elements as valueless variables within the table.

I hope this clears it up again, and thanks again for the help.

bastya_elvtars

#5
frames.frame1

This way you call it.

And notice my array declaration.
Everything could have been anything else and it would have just as much meaning.

Barticus

QuoteOriginally posted by bastya_elvtars
frames.frame1

This way you call it.

And notice my array declaration.

Well, that would be a dictionary, which would be fine by me.  But even so,  how do I put it in a loop so I don't have to have this:

frames.frame1
frames.frame2
frames.frame3

etc, etc over and over in my script?

I have one function with 6 elseif statements just filled with things I'd much rather loop through using a counter.

like:

frames.frame

plop

for index, key in ipairs(array) do

for index, key in pairs(table) do

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

bastya_elvtars

Barticus, you might want to check this page out.
Everything could have been anything else and it would have just as much meaning.

Markitos

QuoteOriginally posted by bastya_elvtars
Barticus, you might want to check this page out.
4got to tell him abt  that!

SMF spam blocked by CleanTalk