Now that I am a bit more comfortable with asking for help I was thinking about past errors I got that either made me mad or made me scratch my head (Mostly stuff I do in other langs that I try to convert to DM)
var/n
n/var/z
var/n/p[10]
So if that was c++ code it would read
struct n {
int z;
};
n p[10];
Now here is the problem I get:
How would I refer to z in p?
if you do:
p[1].z=1 // error
(p[1]).z=1 // error
Any ideas?
ID:178592
Apr 25 2002, 9:38 am
|
|
In response to Lummox JR
|
|
Ya thats what I did in my code but I was just hopeing I was typing something wrong (As you can prolly tell I hate declareing more vars than needed)
thanks. I wonder if I could do p[1]:z |
In response to Winbiko
|
|
nope I cant I stillg the same error.
//BEGIN CODE var/n n/var/z mob.var/n/p[10] mob.verb.test() usr:p[1]:z =1 usr << usr:p[1]:z //END CODE loading tester.dme tester.dm:7:error: :: expected end of statement tester.dm:8:error: :: expected end of statement tester.dmb - 2 errors, 0 warnings (double-click on an error to jump to it) |
In response to Winbiko
|
|
Winbiko wrote:
nope I cant I stillg the same error. Did you not read Lummox's post? He just told you you need to type cast the list item as a mob to reference its variables, and even gave you an example. Constructs such as "usr:p[1]:z" just isn't going to cut it. This barely even looks like BYOND code. |
In response to Skysaw
|
|
oh.
See : works different than . I am still trying to get that. Sorry if I offened you. |
In response to Winbiko
|
|
Winbiko wrote:
oh. No, it has nothing to do with period vs. colon. Let me try to clear this up. If p[1] contains a mob, and you want the value of z of that mob, you can't use this: p[1].z List items simply can't be used as direct references this way. You need an interim variable: var/mob/this_mob = usr.p[1] this_mob.z = 1 usr << this_mob.z sorry if I sounded harsh |
In response to Skysaw
|
|
I understood that. I was just seeing if there was another way.
|
In response to Lummox JR
|
|
How would you edit p[1].z ?
sense that halfway var isnt a pointer |
In response to Winbiko
|
|
Winbiko wrote:
How would you edit p[1].z ? Actually it is--if p[1] is a reference to a datum, then this should work: var/n/item=p[1] Where you can get tripped up, though, is with non-datums. If you use a string or a number within the list itself, changes you make to a copy won't be reflected in the list. Lummox JR |
In response to Winbiko
|
|
Winbiko wrote:
How would you edit p[1].z ? But it is! :) Actually it's a reference, which is practically the same thing as a pointer. var/mob/M = p[1] M.z = 2 Now p[1].z = 2 |
In response to Shadowdarke
|
|
so how would you make it not a reference? (just wondering) like if you wanted to copy a var but not point to it?
|
In response to Winbiko
|
|
You would need to create your own copy routine. Get the s_admin library and examine the carboncopy verb (exact verb name may vary) for an excellent example.
|
The solution here is to type cast:
Lummox JR