![]() |
array[0].name, not working?
I know there is a way but I can't seem to remember how I accomplished it before. What I am trying to do is something like this:
NPC Code:array[0].name = "test"; But, it keeps returning 0. Any thoughts would be nice. |
Quick guess:
I suppose "name" is a reserved word/var name. Try to use something else. |
Nope. Doesn't work.
I know this is possible. I think Devenio (sp?) helped me the first time about a year and a half ago maybe. *sigh* Sometimes it does work tho. Like if I keep updating my script and changing stuff around then chaning it back to this it works.. No explination for why, but it doe, but not for long. THen it breaks again. The only thing I think I can remember is something similar to this. NPC Code: |
PHP Code:
|
I tried this, and it works, even if I use "name". Are you doing this server- or clientside?
Edit: Twinny, it works with "name" as well. I just ran into something similar before, that's why I thought it wouldn't work (: |
Quote:
NPC Code: I am trying this for an array of a size that is unknown. So I need to be able to add to the array as needed. Could I just reset the size each time I add a value? I think I got it now. PHP Code:
|
If temp.array[0] doesn't even exist yet, temp.array[0].name can't exist either.
Edit: Yea, static vars are your best shot I guess. |
What do you mean by reset the size?
PHP Code:
PHP Code:
|
What I am trying to do is. Skip the need for
NPC Code: And just do: PHP Code:
Here is what I mean, kinda: PHP Code:
|
Sort of like,
PHP Code:
[Edit] Confirmed PHP Code:
|
Kinda but not really.
This might help. Instead of: PHP Code:
PHP Code:
As for the easily copy of the data I can worry about a function to do that if needed. But, do you see what I am saying? |
Let's try to find a different solution then :p What are you trying to achieve? There are surely more ways to do what you want to do.
|
Basically.
Instead of: PHP Code:
PHP Code:
I dont even know if you can use my first example and try and copy array[0] to newarray[0].. Possible? dunno. But you can see here I am looking at the array as the object. And giving info about it names rather then numbers in a multi demensional array. Think of it as, when you hold something in your hand. That item has details about it.. Height, width, weight, color, smell... etc Would it make sence to say this items 0 value is 100 px.. its 1 value is 120px to explain to someone that its demensions are 100x120 ? |
Well, associative arrays would be a nice thing to have, eh? You are not bound to arrays though. Why don't you just use multiple static vars? You could even combine them in a bigger one, like this:
PHP Code:
|
Basically. I want to make a simple inventory.
array[i].name to be the item. Were i represents the index of the item in inventory. Each appending name after it to represent that detail about the item. This, however, works. But is there any simpler way to do such a task? I mean I dont see why I must assign a value using add(). =/ PHP Code:
NPC Code:temp.obj = new TStaticVar(); Reset the array??? Also, this does not work. Any thoughts? PHP Code:
|
I'm sure that this..
PHP Code:
Edit: Your last script doesn't work because you are trying to use the add() function although it does not exist. Careful, this only works on arrays. Neither temp.obj nor temp.obj2 is an array in your script. |
Add is working fine. I need temp.obj2 to point to the data I assign it to form temp.obj and i need this value in temp.obj2 to stay that data if I were to putnpc2.. =/
|
Hey, back again. Here is what I got so far. But is there any way to use a function instead of having to use the 2 lines under //copy?
PHP Code:
|
| All times are GMT +2. The time now is 09:44 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.