okay, i have this:
mob/player/proc
thing()
world << "thing"
how do i call thing from within a global proc? i tried, usr.thing(), src.thing(), and thing(). but none of em will work. i understan dwhy, but is there a way to call it?
btw, these aren't real proc names and the such in my game. just a demo.
ID:150846
![]() Jul 18 2001, 11:26 am
|
|
On 7/18/01 2:31 pm Skysaw wrote:
On 7/18/01 2:26 pm XgavinX wrote: okay, thanks. i'll see what i can do. |
On 7/18/01 2:26 pm XgavinX wrote:
mob/player/proc You have to have a mob/player variable, or instance, to call it on. For example: proc/Dummy() var/mob/player/myplayer = new myplayer.thing() Probably not what you wanted to do, though, because that creates a whole new player mob. But the principle is the same. You probably can't call usr.thing() because by default, usr is of type /mob, which doesn't have a proc/thing() defined. There are two ways to get around this (looks like Skysaw already beat me to it on this point, heh):
Additionally, if you want to keep track of a certain player globally, and that player happens to be a /mob/player, you can call thing() on that variable. For example: var/mob/player/kewlplayer proc/KewlThing() if (kewlplayer) kewlplayer.thing() mob/player/verb/getkewl() src << "You are the kewlplayer!" kewlplayer = src And so on. I hope that made a little sense! |
On 7/18/01 2:40 pm Air Mapster wrote:
On 7/18/01 2:26 pm XgavinX wrote:
Additionally, if you want to keep track of a certain player globally, and that player happens to be a /mob/player, you can call thing() on that variable. For example: usr:thing() seems to be working alright for me. thanks. |
On 7/18/01 2:44 pm XgavinX wrote:
usr:thing() seems to be working alright for me. thanks. usr and the colon operator in one statement...Air, you have done a bad thing here! |
On 7/18/01 5:37 pm Deadron wrote:
On 7/18/01 2:44 pm XgavinX wrote: Yes, perhaps I should have emphasized the danger a little more (but I did mention it). Bad Me. By the way, is there a FAQ or tutorial on such perils? I see a section on usr in the FAQ which discusses alternatives and avoidance, but nothing on colon. Perhaps that's my cue to write something up in my copious (cough) amounts of free time... It would be nice to have something to point to, though. |
On 7/18/01 5:51 pm Air Mapster wrote:
By the way, is there a FAQ or tutorial on such perils? I see a section on usr in the FAQ which discusses alternatives and avoidance, but nothing on colon. Perhaps that's my cue to write something up in my copious (cough) amounts of free time... It would be nice to have something to point to, though. Go for it! If there is a discussion of colon operators that isn't filled with swear-words, I must not have written it. |
On 7/18/01 5:51 pm Air Mapster wrote:
By the way, is there a FAQ or tutorial on such perils? I see a section on usr in the FAQ which discusses alternatives and avoidance, but nothing on colon. Perhaps that's my cue to write something up in my copious (cough) amounts of free time... It would be nice to have something to point to, though. Ooh, I believe at one point I wrote a little expose on the dangers of using the colon. Perhaps I should email it to Deadron so he can stick it in the FAQ. |
The problem here is that the compiler is not certain that the proc thing() will always be available for a given usr.
There are two ways to approach this. You can make sure there is a thing() proc defined directly under mob/ (just define it with no instructions in it), and override the definition under mob/player. The other approach is to use usr:thing() [note the colon in place of a period]. This way the compiler only checks to see if any type of usr has that proc, and allows it, leaving potential errors for misuse in the programmer's hands.