Basically I'm trying to reduce the lines of code I have to type to accomplish various tasks, to make development simpler as we put together the room logic for our game. In fact I got that example down to one line by creating a function which returns a Comment object. The following example shows how this object could be used in a game:
// ====== Initialize Comments ======
// This part happens within the Init script(s) for Sammy.
// These comments will be said if Sammy is looked at
self.cLook = newComment ("That's my archnemesis Sammy the Pirate! He's got an ill-favored look.", "actor_sammy_look1.ogg");
var Temp1 = self.cLook;
Temp1.Add ("It's mean ol' Sammy the Pirate.", "actor_sammy_look2.ogg");
// These are comments that Sammy himself will make.
self.cGrowl = newComment ("Arrgh!", "sammy_growl1");
var Temp2 = self.cGrowl;
Temp2.Add ("Grrrr!", "sammy_growl2");
// ============================
// ====== Event: Look At Sammy ======
// - This occurs in the event handler part of the
// Sammy script(s).
// Have the actor comment on Sammy
Temp1 = self.cLook;
Temp1.Say (actor);
// Have sammy respond with a growl
Temp2 = self.cGrowl;
Temp2.Say (self);
// ============================
The purpose of creating this object is to be able to add any number of comments to one object, as in the example above, and then loop through them as the Say method is called. But I'm still stuck with the same problem.
I should probably ask whether objects are passed by reference or value. But I also need advice. Can anyone help me clean up this code, so it doesn't take so much extraneous junk?
Edit: Correction -- in most cases, its actually the object being talked about that stores the comment object, not the speaker; unless the speaker is just talking in response to something. I've corrected the code sample above accordingly.
In case its not obvious, the whole reason for doing this is to separate the comments by their entities, rather than hard coding them into the game logic. If I add an entity to a room, I shouldn't have to modify any code but the script for that entity. There's probably a simpler way to do this -- there usually is -- but this is the best I've been able to think of yet.