Indigo Rose Software

Professional Software Development Tools

 
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2003
    Posts
    26

    Associative tables

    The help file says you can do this:
    Code:
    food{};
    food.veggie = "Carrot";
    food.fruit = "Apple";
    drink = food.fruit.." cider";
    but what if my index is in a variable? Like this:
    Code:
    foodtype = "fruit";
    Is there a way to use that variable to access the appropriate table element?

    Possibly like these?
    Code:
    drink1 = food.foodtype.." cider";
    drink2 = food[foodtype].." cider";
    Thanks!
    Last edited by Tipperton; 05-28-2005 at 09:27 AM.

  2. #2
    Corey is offline Indigo Rose Staff Alumni
    Join Date
    Aug 2002
    Posts
    9,746
    Hi Tipperton. Hope all is well, please don't replace your sig, the reason it got removed is that we wish to keep this forum extremely neutral and occasionally references, even literary ones, can be misunderstood by others. I hope you can appreciate our position. It's nothing to do with you personally, it's just the way we've defaulted to managing the forum.

    Anyhow OK onto your question:

    Is there a way to use that variable to access the appropriate table element?

    Possibly like these?
    Code:
    drink1 = food.foodtype.." cider";
    drink2 = food[foodtype].." cider";
    Here's a couple ways to access elements of an associative table for example:

    Code:
    table={name="John", age="32"}
    Dialog.Message("Name is: ", table["name"]);
    Dialog.Message("Age is : ", table.age);
    You could also do that using a variable to store your index value like this:

    Code:
    table={name="John", age="32"}
    item="name";
    Dialog.Message("Name is: ", table[item]);
    Not sure if that answers your question but I hope it helps.

  3. #3
    Join Date
    Oct 2003
    Posts
    26
    That explains how it got truncated to just the name (I was sure I put the whole thing in). Now even the name is gone...

    Yes that answers my question, thanks.

  4. #4
    Corey is offline Indigo Rose Staff Alumni
    Join Date
    Aug 2002
    Posts
    9,746
    Glad to help, feel free to put your name back, sorry for deleting it.

Similar Threads

  1. How to programmatically set elements of associative array
    By Ken Gartner in forum TrueUpdate 2.0
    Replies: 1
    Last Post: 04-18-2005, 07:17 AM
  2. Using Tables and Memory resources handling
    By SUF6NEWBIE in forum AutoPlay Media Studio 5.0
    Replies: 3
    Last Post: 04-19-2004, 12:11 PM
  3. Always confusing with tables
    By arnaud in forum AutoPlay Media Studio 5.0
    Replies: 3
    Last Post: 01-25-2004, 06:33 PM
  4. Working with Tables and Files
    By Desmond in forum AutoPlay Media Studio 5.0 Examples
    Replies: 0
    Last Post: 12-23-2003, 08:22 AM
  5. Associative Table Question
    By Worm in forum AutoPlay Media Studio 5.0
    Replies: 4
    Last Post: 12-09-2003, 06:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts