|
-
DOT-INVADER
[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.
-
DOT-INVADER
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.
-
DOT-INVADER
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...?
-
ism
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
-
DOT-INVADER
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
-
ism
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
-
DOT-INVADER
-
DOT-INVADER
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)
-
n00b
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|