A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: [Should be simple] shortcut / pointer

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

    [Should be simple] shortcut / pointer

    Hi guys,

    I guess that this one will be resolved in no time, but for some reason i cannot make it work, what a shame

    Basically I'm trying to write a pointer:

    example of a pointer to a Movie Clip
    code:

    Pointer = _root.xxxMC.yyyMC.zzzMC
    // Now this will trace the _x pos of the MC
    trace(Pointer._x)



    Short and easy...

    example of a pointer to an Object
    code:

    _root.xxx.yyy = {value1:"Flash", value2:"Kit"}
    Pointer = _root.xxx.yyy
    // Now this will trace "Flash"
    trace(Pointer.value1)



    Now... I'm looking for a way to have a pointer for something like this; my "real" code looks similar to:

    code:

    ArrayName["String"][Number][Number] = {value1:"Flash", value2:"Kit"}
    Pointer = ??????????
    // Now this will trace "Flash"
    trace(Pointer.value1)



    Is there a short way to write a pointer for something like that? Of course I know I would be able to write a custom function with if's and such, but I was just wondering if there's a short way, maybe a simple code I forgot (I tried using things like eval() with no luck)

    Thanks!
    Last edited by marmotte; 06-03-2007 at 06:28 PM.

  2. #2
    DOT-INVADER marmotte's Avatar
    Join Date
    May 2002
    Location
    Dot-Switzerland
    Posts
    2,601
    Hey Donnie, long time no see

    you cannot put ["String"] after an array
    Yes yes, well... I meant a way similar to:

    code:

    SomeArray = [];
    SomeArray["Player"] = {WalkSpeed:4, JumpHeight:8};
    SomeArray["Enemy"] = {WalkSpeed:3, JumpHeight:12};
    // this.will trace 4
    trace(SomeArray["Player"].WalkSpeed);



    And about the pointer: oh yes, this one is easy, but what if there's a string, mmh?

    Try to make a pointer for "SomeArray["Enemy"]"
    Last edited by marmotte; 06-03-2007 at 07:00 PM.

  3. #3
    DOT-INVADER marmotte's Avatar
    Join Date
    May 2002
    Location
    Dot-Switzerland
    Posts
    2,601
    Oh ok, i see what you mean...
    Haha until now, i thought that it was also considered like an array, but yeah, it makes sense that it's an object... (Though my code works too and traces 4 anyway)

    and a pointer of SomeObject["Player"] would be...?

  4. #4
    ism BlinkOk's Avatar
    Join Date
    Aug 2001
    Location
    , location, location
    Posts
    5,002
    Code:
    SomeArray = [];
    
    SomeArray["Player"] = {WalkSpeed:4, JumpHeight:8};
    
    SomeArray["Enemy"] = {WalkSpeed:3, JumpHeight:12};
    
    // this.will trace 4
    
    pointer = SomeArray["Enemy"];
    
    trace(SomeArray["Player"].WalkSpeed);
    trace(pointer.WalkSpeed);
    stop();
    This worked ok for me (MX). The second trace returns 3.
    It might be that (in a later version) "pointer" is reserved as a functions or something. maybe try another word like MyPointer.
    Graphics Attract, Motion Engages, Gameplay Addicts
    XP Pro | P4 2.8Ghz | 2Gb | 80Gb,40Gb | 128Mb DDR ATI Radeon 9800 Pro

  5. #5
    DOT-INVADER marmotte's Avatar
    Join Date
    May 2002
    Location
    Dot-Switzerland
    Posts
    2,601
    pointer = SomeArray["Enemy"];
    Wait, I know that perfectly too... Mmmmh, I think that I'm totally lost now, let me re-check my whole code, for some reason it was a pain to try to write a pointer... And now I'm not sure why it's a pain anymore, all I know is that I changed the structure and some functions several times already... Haaa, I'm working on it way too much, I say

    Thanks btw, I'm rechecking my original code

  6. #6
    ism BlinkOk's Avatar
    Join Date
    Aug 2001
    Location
    , location, location
    Posts
    5,002
    just remember this;


    This will save a pointer
    pointer = SomeArray["Enemy"];
    This will save the "value" that is contained within WalkSpeed NOT a pointer. So if the variable contains a VALUE then you cannot save a pointer to it.
    pointer = SomeArray["Enemy"].WalkSpeed;
    Graphics Attract, Motion Engages, Gameplay Addicts
    XP Pro | P4 2.8Ghz | 2Gb | 80Gb,40Gb | 128Mb DDR ATI Radeon 9800 Pro

  7. #7
    DOT-INVADER marmotte's Avatar
    Join Date
    May 2002
    Location
    Dot-Switzerland
    Posts
    2,601
    Ok, mmhhh... Totally my fault; I modified several functions and variable names yesterday late and today I was trying to make a pointer without considering the changes I did the day before... omg, I'm too addicted.

    I should seriously start to take some holidays I guess (not going to happen though, ugh)

    I'll delete that useless thread in several minutes, just wanted to thank you for your time before (if you read that part now, of course )

    EDIT

    code:
    pointer = SomeArray["Enemy"].WalkSpeed


    Yep, not a good pointer at all if you know that the WalkSpeed value may change during the game
    Last edited by marmotte; 06-03-2007 at 07:39 PM.

  8. #8
    DOT-INVADER marmotte's Avatar
    Join Date
    May 2002
    Location
    Dot-Switzerland
    Posts
    2,601
    Great, after 60 minutes it's not possible to edit your messages anymore, and no way to delete the thread... T_T So I'll let it die...

    Thanks jtnw, yes i can do it that way too.

    For some reason, sometimes I like to work with things like

    xxx["yyy"] = {a:1, b:2}

    more than

    xxx.yyy = {a:1, b:2}

    and more than arrays...


    Anyway: I always wanted to start a DISC thread related to the storage of the texts/dialogs in games like RPG (or at least any game with intensive dialogs); I would be very curious to see how people and developers around here work with that, because there's generally a LOT OF TEXT involved, and very often the content of the texts depends on xxx, yyy and zzz.

    xxx being for example if(Mission2Completed == true)
    yyy being for example if(HaveItemFeather == false)
    zzz being for example if(GoldCoins >= 20)

    ...etc

    I have some hints or ideas, just not the time to try or post them (and maybe they aren't ideal anyway)

  9. #9
    n00b LeechmasterB's Avatar
    Join Date
    May 2004
    Location
    Switzerland
    Posts
    1,067
    Here s my hints for pointers and dynamic variables:

    Code:
    var xxxYYY:Array = new Array({a:1, b:2}, {a:2535, b:666});
    /** store the name for the array to acess in a var for example */
    var y:String = "YYY";
    /*************/
    /** trace the array content */
    trace("xxxYYY[1]: "+this["xxx"+y][1]);
    trace("a: "+this["xxx"+y][1].a);
    trace("b: "+this["xxx"+y][1].b);
    /*************/
    /** create a pointer */
    var myPointer:Object = this["xxx"+y][0];
    trace("pointer points to first element: "+myPointer.a);
    myPointer.a++;
    trace("pointer modified a on the pointer: "+myPointer.a);
    trace("compare to original array a value: "+this["xxx"+y][0].a);
    trace("WARNING ONLY CREATE A POINTER TO THE ARRAY CONTENT, \n NOT TO THE CONTENT's CONTENT THOUGH");
    trace("Because if you point to element -> its a pointer / point to variable = copy");
    trace("example: ");
    var myPointer2:Object = this["xxx"+y][0].a;
    trace("pointer2 holds a: "+myPointer2);
    myPointer2++;
    trace("pointer2'a got modified: "+myPointer2);
    trace("but the original array value which we wanted to point to stood untouched: "+this["xxx"+y][0].a);
    Do not try this with as 3.0 though.. but it works with as 2.0.

    greets
    I do stuff that does stuff...

    J-Force

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