PtokaX forum

Archive => Archived 4.0 boards => Help with Lua 4 scripts => Topic started by: Barticus on 17 October, 2005, 15:28:33

Title: array element as variable problem ..
Post by: Barticus on 17 October, 2005, 15:28:33
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

Title:
Post by: 6Marilyn6Manson6 on 17 October, 2005, 15:34:14
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
Title:
Post by: Barticus on 17 October, 2005, 15:47:59
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.
Title:
Post by: bastya_elvtars on 17 October, 2005, 17:32:08
This works for me: x="hey"
y="hi"
arr={x,y}

print(arr[1],arr[2])
Title:
Post by: Barticus on 17 October, 2005, 18:35:01
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.
Title:
Post by: bastya_elvtars on 17 October, 2005, 18:46:33
frames.frame1

This way you call it.

And notice my array declaration.
Title:
Post by: Barticus on 17 October, 2005, 19:01:32
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
Title:
Post by: plop on 17 October, 2005, 20:27:23
for index, key in ipairs(array) do

for index, key in pairs(table) do

plop
Title:
Post by: bastya_elvtars on 17 October, 2005, 22:03:03
Barticus, you might want to check this page (http://ptxwiki.psycho-chihuahua.net/doku.php/scriptinghelp/tables) out.
Title: Agree...
Post by: Markitos on 17 October, 2005, 22:16:54
QuoteOriginally posted by bastya_elvtars
Barticus, you might want to check this page (http://ptxwiki.psycho-chihuahua.net/doku.php/scriptinghelp/tables) out.
4got to tell him abt  that!