Posts ID:157273 Creations
ID:157273

well, some things about arguments for a proc is really bugging me.

for instance
 ```proc/AddVar(var/a,var/b) a+=b // does this change the actual value of a? return a//consider that proc in mindproc/TestAdd() var/x=10 var/y=20 //AddVar(x,y) // wat will this result into? 10 or 30 ? //x=AddVar(x,y) this will result in 30 world << "Yay x variable has the value [x]" ```

Run it and see.

But I'll spare you the effort: var/x will have the value 10, a will have the value 30. Values in DM are passed 'by value' - that means that they're copied into the arguments. So the 'var/a' in proc/AddVar() is a variable specific to AddVar, and it's just set to the same value as var/x when AddVar is called.

Important caveat: Objects in DM are references to that object. So a var/obj/o isn't the actual object, it's a pointer to that object. When that is passed by value, the same object is being referenced. So this:

 ```testobj var/aproc/AddTest(var/testobj/k) k.a+=10proc/Test() var/testobj/test test.a = 0 AddTest(test) world << test.a ```

will output 10.
 #2 Apr 10 2010, 9:57 am In response to Jp (#1) Thank You :) The reason I asked that was to know if there was any difference between AddVar(var/a,var/b) and AddVar(a,b) ? because your previous ' Values in DM are passed 'by value' ' does not seem applicable to in AddVar(a,b).
In response to Quixotic (#2)
Those are the same procedure definitions.

 ```proc/AddVar(var/a, var/b)proc/AddVar(a, b) //These are the same! ```

It's just syntactic sugar that lets you leave out the 'var' statement
In response to Jp (#3)
o.O
Are you also right about lists?
 ```ListRem() // verb var/list/K=list("J","p") // ru wrong here ? ListRemoveAll("p",K,1) src<<"/----------" for(var/L in K) src<<"-[L]-" src<<"----------\\"ListRemoveAll(Object,list/List) // removes all var/Objects in list if(isnull(List)) return null for(var/K in List) if(K==Object) List.Remove(K) return List ```

I dont get this right.If it was passing values only, it should ListRemoveAll not remove it from the list.But running that - it does remove.
so the output is only "-J-".
 #5 Apr 11 2010, 7:11 pm In response to Quixotic (#4) Only strings and numerical values are passed by value. Everything else is passed by reference.
 #6 Apr 11 2010, 11:07 pm In response to Garthor (#5) Thank You