ID:180083
 
K, simple question.

When you tie a var to a obj, like

stupidvar = src

does the var -only- apply to that one obj?

I mean, if the user has 2 of those items, will the var distinguish between the 2?

Elorien
src.say("Yes")
In response to Lord of Water
Lord of Water wrote:
src.say("Yes")

heheheh thanks ^^; Wasnt completely sure

Elorien
Elorien wrote:
K, simple question.

When you tie a var to a obj, like

stupidvar = src

does the var -only- apply to that one obj?

Yes. Simple answer, but it underscores an important point about object-oriented programming.

I believe this type of var is called a "pointer" (someone slap me if I'm using that term wrong, I'm not a trained programmer), simply for the reason that it "points" at a particular object. In fact, using a pointer variable is the only way you can refer to an object that exists in the game... the object type (/obj/item/watermelon, for instance) means nothing in the "physical world" of the game.

Imagine you go to a party with a friend. That friend wanders off. Someone asks, "Who did you come here with?" If the person knows your friend, you can refer to the friend by name, otherwise, you can try pointing at your friend, telling them where your friend can be found at the moment, or describing your friend. Trying to describe your friend's DNA structure, or just saying "vertebrate/mammal/primate/" isn't going to get you anywhere.

What does this have to do with BYOND? When you want the program to do something with a given object (mob, obj, turf, area, whatever), you have to tell the program how to figure out exactly which thing to do it with.

If you and the program both already know that particular object by a given name, you can just call the object by that name... for instance, if you've made a mob variable called enemy, and you know src.enemy ='s the mob your proc is trying to damage, you can just call the mob src.enemy, and the program will know who you're talking about. If thinking of variables as being names given to an object confuses you, just remember, it's a "pointer variable" and think of it as a sign pointing at the object.

Also, you can try telling the computer where to find the object. For instance, if you need a proc to duplicate the food item(s) placed inside a Replicator Box, you could do it like this:

obj/replicator_box/verb/use()
for (var/obj/food/f in src)
new f.type(src.loc)
usr << "The box spits out [f]."


Finally, you can try describing the object by some unique characteristics. BYOND provides the tag variable for some special functionality in this area... read up on it if you're interested. Otherwise, though, if you know there's only one Golden Zaphroot Egg in the game, for instance, you could do this:

for (var/obj/golden_zaphroot_egg/g in world)
g.hatch()

to make the egg hatch. But to go back to the party metaphor... if you had to describe your friend, the person would have to go around to everyone at the party, look at them, and check to see if their description matches the details you gave, to figure out if they're your friend. Sounds messy and slow, doesn't it? Wouldn't it be easier if the person was already on a first-name basis with your friend?

So, let's define a variable... outside of all procs and object definitions, which makes it global (belonging to the whole game/program):

var/obj/golden_zaphroot_egg/egg

and under obj/golden_zaphroot_egg/New(), let's put this:

egg = src

Now, when we place a golden_zaphroot_egg on the map, it automatically is assigned to the variable egg. Whenever we talk about egg, the program knows we mean the last golden_zaphroot_egg created (we'll only create one of them.)

Incidentally, this is an excellent way to refer to flags in capture-the-flag games... global variables called flag1 and flag2, or redflag and yellowflag, or whatever.
In response to LexyBitch
LexyBitch wrote:
I believe this type of var is called a "pointer" (someone slap me if I'm using that term wrong, I'm not a trained programmer), simply for the reason that it "points" at a particular object.

Sort of and sort of not.

In general, Dantom would probably prefer to avoid the term altogether, as it denotes a difficult and buggy aspect of C/C++ which doesn't apply to BYOND.

A pointer points to a location in memory. Nothing is implied about what resides at that location -- it could be an object, a string, or a completely random spot. In C/C++ you frequently access things this way...and just as frequently accidentally access the wrong location and crash the program or the system.

The more accurate terminology in this case is a "reference". You are storing a reference to an object. It's more accurate because you don't know anything about the how the reference works: it is "opaque" -- the reference might itself be an object containing dereferencing data, or might be a pointer, or, quite likely, a "handle" which is a pointer to a pointer. All you know is that one way or the other it points to the object you care about in a manner you aren't involved in.

This is an important distinction -- if it were a transparent pointer, you could theoretically use "pointer arithmetic" to walk the memory tree yourself and manipulate things. Or, rather, corrupt things and crash the system. This is how the old Mac OS worked, and that's why the Mac OS crashed all the time. Mac OS X doesn't allow this, and that's one of the reasons Mac OS X doesn't crash all the time.

Anyway, I apologize for explaining this in a thread involving Elorien, since she obviously knows all this already.
In response to Deadron
Anyway, I apologize for explaining this in a thread involving Elorien, since she obviously knows all this already.

Elorien is female?

does a quick key look-up

Wow, I did not realize that. Welcome to the fold!
In response to LexyBitch
LexyBitch wrote:
Anyway, I apologize for explaining this in a thread involving Elorien, since she obviously knows all this already.

Elorien is female?

does a quick key look-up

Wow, I did not realize that. Welcome to the fold!

o.o;;; Uhm, Yea, I am *L*

*looks at Deadron* I really dont see what died in your cherrios. I never said I knew everything about byond.. Check my sig, 3/4 of the time Ill sign as 'supa-noob', cuz I am >:P

I just dont like being regarded as a child, or being talked down to as if I just fell offa the tunip wagon. Ive worked hard to get as far as I have with various programming languages, and I personally dont enjoy being treated as if I were some 'flightly blonde'. *sigh* I -do- have a brain, and a fair bit of experience with other languages, just nothing really current *shrugs*

Oh well *yawn*

Elorien, supa-n00b
In response to Elorien
Elorien wrote:
I just dont like being regarded as a child, or being talked down to as if I just fell offa the tunip wagon. \

This is strictly your own insecurity speaking, since I didn't talk to you differently than I talk to anyone else.

You did ask some basic questions, to which I provided some basic answers, and I did suggest that you not tackle really complicated stuff before thoroughly learning the system. I'd say the same to anyone, and have many times, based on my own experiences.
In response to Elorien
I just dont like being regarded as a child, or being talked down to as if I just fell offa the tunip wagon.

That's one thing you need to realize about Deadron and I... we treat everyone pretty much the same. Poorly. Actually, I'm not sure why my response was so respectful, helpful, and informative.
In response to LexyBitch
LexyBitch wrote:
I just dont like being regarded as a child, or being talked down to as if I just fell offa the tunip wagon.

That's one thing you need to realize about Deadron and I... we treat everyone pretty much the same. Poorly. Actually, I'm not sure why my response was so respectful, helpful, and informative.

wow...
is Lexy getting soft?
/me starts to crawl out of the dog house
In response to JonSnow13

/me starts to crawl out of the dog house

Maybe the reason it seems that no one likes you is because you talk baby-talk.
In response to LexyBitch
LexyBitch wrote:
Anyway, I apologize for explaining this in a thread involving Elorien, since she obviously knows all this already.

Elorien is female?

does a quick key look-up

Wow, I did not realize that. Welcome to the fold!

Wow. I learn something new every day.
In response to Deadron
Deadron wrote:
Elorien wrote:
I just dont like being regarded as a child, or being talked down to as if I just fell offa the tunip wagon. \

This is strictly your own insecurity speaking, since I didn't talk to you differently than I talk to anyone else.

You did ask some basic questions, to which I provided some basic answers, and I did suggest that you not tackle really complicated stuff before thoroughly learning the system. I'd say the same to anyone, and have many times, based on my own experiences.

*shrug* If you treat everyone like that then Im surpised that more people dont take offence.

And my problem -is- with the basics. I am -not- familiar with an object oriented language, as Ive said many times before.. Im much more used to line based scripting, so I find with byond that with puting together code Im somewhat ok, its just the basics that come with object oriented stuff that make it a problem for me.

I -am- slowly learning though. With a little more work I may have a game engine to try to beta live.. Not the game Im working towards mind you, just a live test of some aspects of its engine to make sure it works, and that it isnt too system hungry..

Anyways, time to go puter shopping! *goes to drool at the system shes thinking of getting*

Elorien
In response to Elorien
*shrug* If you treat everyone like that then Im surpised that more people dont take offence.

Just as Leftley is known for his puns, Deadron is known for his sarcasm. And, er, so is Lexy.

Me? I am pithy. Very, very, very darned pithy. And conceited.

(And, apparently, a hypocrite! Of course, that person's definition of hypocrite was "someone who thinks they are better than everyone else". But this is a pointless and unnecessary digression.)

(Like I said, pithy.)


And my problem -is- with the basics. I am -not- familiar with an object oriented language, as Ive said many times before.. Im much more used to line based scripting, so I find with byond that with puting together code Im somewhat ok, its just the basics that come with object oriented stuff that make it a problem for me.

BYOND is technically a scripting language, but it fuzzes the boundaries. Most scripting languages (read: just about every game-oriented scripting language) don't allow you to have custom procedures, variables, object types, and the like. (DM, the language of BYOND, and Java, the language of Sun Microsystems, are notable exceptions.)

Anything that generates something that is interpreted, rather than machine-code, is a scripting language.

Stupid, no?

(Pithy again!)


I -am- slowly learning though. With a little more work I may have a game engine to try to beta live.. Not the game Im working towards mind you, just a live test of some aspects of its engine to make sure it works, and that it isnt too system hungry..

Not a bad idea.

(Not pithy.)


Anyways, time to go puter shopping! *goes to drool at the system shes thinking of getting*

Get one from IPC Canada instead! They'll serve you for at least a month before kicking the bucket!

(Very pithy!)