A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: syntax question: track an array using variable values

  1. #1
    DOT-INVADER marmotte's Avatar
    Join Date
    May 2002
    Location
    Dot-Switzerland
    Posts
    2,601

    syntax question: track an array using variable values

    hello everyone ^^

    i'm just optimising the dialogs engine in my game, but here's my current problem: for now, i have:

    > an array that contains all in-game texts:
    Code:
    dialog = new Array();
    dialog[0] = "hello, my name is...";
    dialog[1] = "goodbye, i'm leaving.";
    > now, when a popup window appear, the dialog is called in a dynamic text field:
    Code:
    this.dynamic_text = dialog[1];
    > you guessed it, "goodbye, i'm leaving" is the text that appears (my actual engine is a bit more complicated, but the idea is the same).

    now
    imagine that the previous array is named differently:
    Code:
    dialog_pox2_poy4 = new Array();
    dialog_pox2_poy4[0] = "hello, my name is...";
    dialog_pox2_poy4[1] = "goodbye, i'm leaving.";
    here are also two variables
    Code:
    popo=2
    pipi=4
    my question
    how to call the array "dialog_pox2_poy4" using the variables values? (i mean, how to replace "2" and "4" in the array with the variables)...

    > example that is not working, but to show you what i mean:
    Code:
    this.dynamic_text = this["dialog_pox"+popo+"_poy"+pipi+"[1]"];
    thanks for your answers

  2. #2
    this.dynamic_text=dialog_pox2_poy4[popo]

    like this?

  3. #3
    DOT-INVADER marmotte's Avatar
    Join Date
    May 2002
    Location
    Dot-Switzerland
    Posts
    2,601
    oh no, not at all ^^

    > change the bold part
    this.dynamic_text = dialog_pox2_poy4[1];
    > using the variables values popo and pipi
    Code:
    popo = 2
    pipi = 4

  4. #4
    ism BlinkOk's Avatar
    Join Date
    Aug 2001
    Location
    , location, location
    Posts
    5,002
    Code:
    eval("dialog_pox"+popo+"poy"+pipi)[0] = value;
    Graphics Attract, Motion Engages, Gameplay Addicts
    XP Pro | P4 2.8Ghz | 2Gb | 80Gb,40Gb | 128Mb DDR ATI Radeon 9800 Pro

  5. #5
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    Blink, didnt you forget "_" infront of "poy"?

    eval("dialog_pox"+popo+"_poy"+pipi)[0] = value;

  6. #6
    ism BlinkOk's Avatar
    Join Date
    Aug 2001
    Location
    , location, location
    Posts
    5,002
    i do believe i did
    Graphics Attract, Motion Engages, Gameplay Addicts
    XP Pro | P4 2.8Ghz | 2Gb | 80Gb,40Gb | 128Mb DDR ATI Radeon 9800 Pro

  7. #7
    Senior Member
    Join Date
    Apr 2001
    Location
    Candyland
    Posts
    423

    Re: syntax question: track an array using variable values

    Code:
    this.dynamic_text = this["dialog_pox"+popo+"_poy"+pipi][1];
    this should work.
    k.

  8. #8
    DOT-INVADER marmotte's Avatar
    Join Date
    May 2002
    Location
    Dot-Switzerland
    Posts
    2,601
    thanks guys, it's working like a charm ^^

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center