Author Topic: array element as variable problem ..  (Read 5024 times)

0 Members and 1 Guest are viewing this topic.

Offline Barticus

  • Newbie
  • *
  • Posts: 9
  • Karma: +0/-0
array element as variable problem ..
« 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


PtokaX forum

array element as variable problem ..
« on: 17 October, 2005, 15:28:33 »

Offline 6Marilyn6Manson6

  • Scripter
  • King
  • ******
  • Posts: 869
  • Karma: +47/-35
    • http://www.marilynmanson986.altervista.org
(No subject)
« Reply #1 on: 17 October, 2005, 15:34:14 »
Quote
Originally 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



Code: [Select]
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

Offline Barticus

  • Newbie
  • *
  • Posts: 9
  • Karma: +0/-0
(No subject)
« Reply #2 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.
« Last Edit: 17 October, 2005, 15:58:04 by Barticus »

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 752
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
(No subject)
« Reply #3 on: 17 October, 2005, 17:32:08 »
This works for me:
Code: [Select]
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.

Offline Barticus

  • Newbie
  • *
  • Posts: 9
  • Karma: +0/-0
(No subject)
« Reply #4 on: 17 October, 2005, 18:35:01 »
Quote
Originally posted by bastya_elvtars
This works for me:
Code: [Select]
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.
« Last Edit: 17 October, 2005, 18:44:43 by Barticus »

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 752
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
(No subject)
« Reply #5 on: 17 October, 2005, 18:46:33 »
frames.frame1

This way you call it.

And notice my array declaration.
« Last Edit: 17 October, 2005, 18:48:22 by bastya_elvtars »
Everything could have been anything else and it would have just as much meaning.

Offline Barticus

  • Newbie
  • *
  • Posts: 9
  • Karma: +0/-0
(No subject)
« Reply #6 on: 17 October, 2005, 19:01:32 »
Quote
Originally 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

Offline plop

  • Forum God
  • ****
  • Posts: 2 464
  • Karma: +37/-0
(No subject)
« Reply #7 on: 17 October, 2005, 20:27:23 »
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 <----<<

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 752
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
(No subject)
« Reply #8 on: 17 October, 2005, 22:03:03 »
Barticus, you might want to check this page out.
Everything could have been anything else and it would have just as much meaning.

Markitos

  • Guest
Agree...
« Reply #9 on: 17 October, 2005, 22:16:54 »
Quote
Originally posted by bastya_elvtars
Barticus, you might want to check this page out.
4got to tell him abt  that!

PtokaX forum

Agree...
« Reply #9 on: 17 October, 2005, 22:16:54 »