ID:268703
 
What I want to do is beable to transfer over a certain mobs variable, the reference to it so I can change the value at wim.

I just started programming back again, after a month and ahalf break and some of this is rusty again lol...

mob/verb/Attack()
spawn() Damage(src.damage)

mob/proc/Damage(var/N)
N=3

how would I make it change src.damage to 3, not just the value of the new variable in damage?


or another example

mob/verb/changevariables()
var/t
if(istype(src,mob/pee))
t=src.pee
if(istype(src,/mob/dork))
t=src.dork
t+=1


that way I could just change t and not have to individually type in src.pee+=1, src.dork +=1
Jon Snow wrote:
mob/verb/Attack()
spawn() Damage(src.damage)

mob/proc/Damage(var/N)
N=3

how would I make it change src.damage to 3, not just the value of the new variable in damage?

Instead of passing src.damage, pass src. Then you can change src's variables in the Damage() procedure.
In response to Jon88
that's what i'm trying to get around...

for instance, say you had (this is highly inefficient, but just for an example) 20 different classes of mob, and with each class you give them 3 completely unique variables, randomly.

Now since src. is already assumed when I called the damage proc, jsut using src in the damage proc would allow me to reference the original mob, and yes I could do the following -

mob/proc/Damage()
if(istype(src,mob/1)
src.var1=3
src.var2=3
src.var3=3
src.var4=3
and so on...


but doing this would be essentially less efficient if for say Damage() was going to be looped... For an entire game.

you'd want it to do the checks in the calling verb, so that way it'd check if it is that mob type in the beginning, then you can just keep sending those unique variables over and over, for instance -

mob/verb/attack()
var/reference
if(istype(src,/mob/1)
reference=src.var1
if(istype(src,/mob/2)
reference=src.var2
if(istype(src,/mob/3)
reference=src.var3
spawn() Damage(reference)

mob/proc/Damage(reference)
reference+=1
spawn() Damage(reference)


This would essentially save me from having to do if checks every time Damage is looped through, virtually saving a ton of processing power.
In response to Jon Snow
You could pass in src and the string "damage", and then access src.vars["damage"]. Like this:

proc/IncrementVariable(mob/M, varname as text)
M.vars[varname]++


Objects are passed by reference. Everything else (such as strings and numbers) are passed by value. I don't believe there's any way to change that, but you can work around it (using the vars list is one way, just be careful you don't pass in a non-existent variable name).
In response to Crispy
eh can't use that http://developer.byond.com/forum/ index.cgi?action=message_read&id=286814&forum=4&view=0

from my understanding it's not good to, so I was hoping there was another way. I quit programming for a month and a half because I have a few hundred lines of code I need to change completely unless I can find an easy switch for doing this method hehe :)

I was told to use lists and lists might work but I'd rather not have to recode everything... would just make it a pain in the arse. I don't have that much time left for programming anymore, an hour each day if that. So hopefully a response would be great :)
In response to Jon Snow
It isn't good to, but occasionally you just have to get ugly to make stuff work. Try and avoid it as much as possible though.

Lists are good. I don't know exactly how you're trying to use them, but they're generally good. =P
In response to Crispy
well the thing is like the example up above that I used, if I had a lot of mobs and a lot of individual vars, that'd be a way cleaner method so I might have to just go with vars[] when I can't really do anything else... you're right on that :(

I'll give it a few days to ponder and then I might just go with it :)