Aller au contenu

Photo

How does OBJECT_SELF work?


  • Veuillez vous connecter pour répondre
4 réponses à ce sujet

#1
Talisander

Talisander
  • Members
  • 173 messages
I'm stumped.  Clearly this somehow points to the object that is calling the script.  I don't understand it -- is there an explanation anywhere?  It gets used all over the Bioware scripts.  Clearly the scripting language treats this differently...  it even appears blue, so it doesn't seem like a constant.

Do I need to include any header files to use it?

If I use it in a script run off a conversation, is the conversation the object that it returns?

I'm trying to write a script that runs from a conversation, but affects the creature that the conversation was run off of-- I'm not sure if there's actually a way to do this.  Mainly I'd just like to understand OBJECT_SELF -- I can probably find a different way of doing the script.

#2
_L_o_B_o_

_L_o_B_o_
  • Members
  • 117 messages
I'll try to explain it simple, although I don't get it most of the time =]

it even appears blue, so it doesn't seem like a constant.


That's because it is a restricted identifier, like "if", "for", "string", "object"... You can't use them as names for your own functions, variables or constants, because they are already being used by the scripting language and have a certain meaning for the compiler.

Do I need to include any header files to use it?


Nop. You don't have to include any header file to use names like "string" or "object". Same goes for OBJECT_SELF.

If I use it in a script run off a conversation, is the conversation the object that it returns?


I think not. Since conversations cannot be retrieved as objects (only as resources), it returns the creature that owns the conversation.

I'm trying to write a script that runs from a conversation, but affects the creature that the conversation was run off of-- I'm not sure if there's actually a way to do this.  


You can use GetObjectByTag("object_tag_here") to retrieve your creature's object and do wathever you want with it.

Mainly I'd just like to understand OBJECT_SELF


Think of OBJECT_SELF as a shortcut to retrieve the object that is the "owner" of the script. You can try to get the same object using other functions like GetObjectByTag(), but OBJECT_SELF is simply easier.

#3
FergusM

FergusM
  • Members
  • 460 messages
To add to that, OBJECT_SELF will refer only to objects in the game world, not resources like conversations. Objects include creatures, areas, the module, placeables, sound emitters, triggers, waypoints, merchants, items, basically anything you can place in the area editor (plus items, module and the area itself).



Off the top of my head, if you are running the script from a character's line in a conversation, OBJECT_SELF should indeed refer to the creature speaking that line.



Note however that you can't really run scripts that effect the world during conversations. You can run scripts to check conditions, and you can run them at the end of conversations to do things, but you can't really script something to happen in game while a conversation is going on.

#4
Proleric

Proleric
  • Members
  • 2 355 messages
OBJECT_SELF does indeed refer to the in-game object which fired the script (so, the conversation owner, not the conversation).

I think of it as a special constant that means "the object that fired the current script". It's not the same as the object itself.

Occasionally, this distinction is important and can give rise to script errors. To avoid this pitfall, I like to assign it to a real object at the beginning of the script, and work only with that object thereafter, e.g.

object oConversationOwner = OBJECT_SELF;

This also helps to document the script.

Modifié par Proleric1, 18 juillet 2010 - 06:51 .


#5
Talisander

Talisander
  • Members
  • 173 messages
Yep, that's how I'm using it Proleric (modeled off of Bioware's Single Player scripts).

Thanks guys! Now I don't feel like I'm using it in blind faith.

Modifié par Talisander, 18 juillet 2010 - 11:45 .