Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting var-names out of a list.. howto? 1

Status
Not open for further replies.

YaBokke

Programmer
Jan 4, 2006
10
NL
Hi all, please help :D

I have a list called "food" that contains 4 strings.
What a want is to take those strings one by one and turn them into a list-variable of there own.
So that each property in het list "food" has his own list-var with the same name.

I know how to do this in Acionscript, but lingo is a bit diferent :p

I was thinking of something like this:
//////////////////////////////////////

on exitFrame me

food = ["bread", "meat", "soup", "fish"]
repeat with i=1 to food.count
value(food) = ["some"]
end repeat

trace(bread[1])

end
//////////////////////////////////////

But of course this isnt realy working....
Is there a way to do something like this ?
 
You can create a global variable dynamically:

[tt]--
on exitFrame me
food = ["bread", "meat", "soup", "fish"]
repeat with i = 1 to food.count
(the globals)[food] = ["some"]
end repeat
global bread
trace(bread[1])
end
--[/tt]

However, it's more common to use a property list:

[tt]--
on exitFrame me
food = ["bread", "meat", "soup", "fish"]
newFoodList = [:]
repeat with i = 1 to food.count
newFoodList.addProp(food, ["some"])
end repeat
trace(newFoodList.bread[1])
end
--[/tt]

Kenneth Kawamoto
 
Wow, thanks Kenneth!

I still have some questions ^^

So in your second solution, you store every single string of the list "food" as a new list in the property-list "newFoodList" right?

Is it possible to access those lists dynamicly?
I mean, If this 4 buttons where on the stage: bread, meat, soup, fish.
And when I clicked meat, could a script find the list "meat" from "newFoodList" by its property-name ??

must i make a repeat like such or is there a easyer way ?
//////////////////////////////////////

on exitFrame me

global currentFoodList

repeat with i=1 to newFoodList.count
if newFoodList.name = currentFood then
currentFoodList = newFoodList
exit repeat
go "label"
end if
end repeat

end

//////////////////////////////////////

thanks again ;)
 
With property lists, you can access the data using its property - that's the whole point of it!

For example, if you have a property list "newFoodList" and it is ["bread":"Ciabatta", "meat":"Beef", "soup":"Consommé", "fish":"Tuna"], you can just do:

trace(newFoodList.bread)
-- "Ciabatta"

trace(newFoodList.meat)
-- "Beef"

trace(newFoodList.soup)
-- "Consommé"

trace(newFoodList.fish)
-- "Tuna"

Kenneth Kawamoto
 
Yeah I understand that part thanks!
I tryed to explain my problem, but sorry english is not my mother language ;)

Oke, maybe this is a little too much info but i hope i can explane a bit better what i mean. Let me sketch the situation:

----------------------------
My goal is build a association-based navigation structure.
In this situation, the user starts with a word/subject.
Then 6 buttons appear.. each button has its own word that has a link to the current subject.
Now the user has to choose with of those 6 buttons suits best with the current subject.

then he clicks one and then his "association" (his choozen word) becomes the subject. And again 6 button apear with again words that have a link to the current subject.

example: boat > water > cloud > sky > plane > engine > gas... en so on...
----------------------------

----------------------------
still with me? nice! ..next thing to do is scripting the structure.

So how to create such a navigation ?? Well, I was thinking of a start array (list in lingo) with 6 values (the buttons)
Once a button is clicked, the script takes the value that the button was representing, and starts searching for the array with that name. (there will be a lot of arrays)
If ist found, that array will be de subject and its 6 values will be put into those buttons.
----------------------------

----------------------------
Ive done it already in flash, and the next step is director. And becouse lingo is a bit different from acionscript, i need lists!

So i need a list with 6 names.
A script must take the choozen name and find him as a propertie(NAME not value(with will be a list also)) in a propertyList.
----------------------------

WOW, I hope someone is gonna read this ^^
 
If I understood you correctly, you're talking about huge amount of data.

boat > water > cloud > sky > plane > engine > gas

6 x 6 x 6 x 6 x 6 x 6 x 6 = 279,936

Surely Flash can't handle that amount of data, can it?

Perhaps you'd better using a database for this type of work. For a database millions of records are next to nothing, and Director/Flash can talk to a database happily.

Anyway, you can place all of 279,936 data in one property list if you wish, using nesting property list.
[#boat : [#water : [#cloud : [#sky : [#plane : [#engine : ["gas"]]]]]]]

It's just like an XML:
<boat>
<water>
<cloud>
<sky>
<plane>
<engine>
<gas />
...

[#boat:
[#water:
[#cloud:
[#sky:
[#plane:
[#engine:
["gas" ...

Kenneth Kawamoto
 
Yeah, its gonna be a lot of data indeed!
but i can use a association multiple times;

like this: ( two 'ways' with some associations used twice)

--------------------------------------------------
1: [purple]boat[/purple] > [blue]water[/blue] > [red]cloud[/red] > sky > plane > engine > gas

2: sand > dust > [red]cloud[/red] > rain > [blue]water[/blue] > ocean > [purple]boat[/purple]
--------------------------------------------------

And no, I dont think its wise to store all that dat in the projector itself. But becouse the product will be a interactive CD-rom, database isnt gonna work becouse some people dont have a (fast)internet-connection.

So a thought, i make a XML-file with all of those 'association-data' an put it with the projector on the CD-rom.

wat do ya think ? can this be done ??
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top