Character Scripts for Different Rooms

Started by Samwise, Sun 18/03/2007 08:35:14

Previous topic - Next topic

Samwise

Hi all,

In my game there are about 10 NPCs that appear in more than one room.  Every time the NPC is being interacted in a specific room, he supposed to react differently.

I guess it'll be possible to define the different reactions in the character scripts using the "if character[NPC].Room =..." function, but isn't there an easier way to do this other than adding more and more variables to every interaction?

Please note that my game includes voice speech only - therefore no use of texts at all (I don't use the "dialogs" pane).

By the way, is there a way to use variables that aren't global variables in the character scripts?  I've succeeded to access only global scripts from the character scripts, not room scripts of the room the character's presently in.

Thanks,

Jonathan


Ashen

#1
Short answers: 'No', and 'Huh?'

Single long answer, that hopefully adresses both issues:
Character interactions go in the Global script, so obviously you can only access variables, etc, defined there (or in Modules) from Character interactions - Room-based variables can't be used. However, there IS the CallRoomScript function that'll allow you to run a block of Room-based code from the Global Script.
So, you could have your NPC interactions run:
Code: ags

CallRoomScript(NPCID); // Replace NPCID with the actual character number


Then, in your Room Scripts:
Code: ags

function on_call (int value) {
  if (value == cNpc1.ID) {
    // First NPC code for current room
  }
  else if (value == cNpc2.ID) {
    // Second NPC code for current room
  }
  // Etc
}


I'm not sure if that's easier that the way you're using -  you'll still have the same number of conditions (one per NPC per Room) but having the room specific stuff in the room it's for might be a little clearer than lumping it all in Global, and you won't need to make all the variables involved Global just to get it working.

On a slightly irrelevant note:
Quote
my game includes voice speech only - therefore no use of texts at all
Please don't do this, or at least make it optional (SetVoiceMode). Maybe I'm just very impatient, but I'd like to be able to progress at the speed I can read, not wait for the lines to be read every time. (Especially when replaying an interaction for the Nth time...)
I know what you're thinking ... Don't think that.

Samwise

Ashen, thank you very much for your (consistent) help.

Well, I think I'll stick to using global variables for characters.  I don't have a problem that they're on the global script, I just was worried that too much global variables (100-200, I assume) will slow up the game.  Will they do that, and will importing them only to the relevant room scripts might help in such a case?

I didn't understand your response to the first question.  Must I use the "if character[NPC].Room =..." function to manage characters that switch rooms?  This seems a little too complicated for such a basic function - I would think that most of AGS games have NPCs that switch rooms.

(As for the slightly irrelevant note  :)  Believe me, I thought about it a lot before choosing to do it this way.  That's because the speech lines are very short, you can always skip them with the mouse click if you want, and the language uses a lot of slang that will be  less appropriate for reading. Furthermore, I think that texts are more important for games in English, because they can help non-English players understanding the voice speech.  This is not the case with my game).


Ashen

Quote
I just was worried that too much global variables (100-200, I assume) will slow up the game.  Will they do that, and will importing them only to the relevant room scripts might help in such a case?

No, and no. There might be a slow-down issue if you were constantly checking/changing a couple hundred variables in repeatedly_execute, but if they just exist and aren't being used most of the time, it won't be a problem.

Quote
Must I use the "if character[NPC].Room =..." function to manage characters that switch rooms? This seems a little too complicated for such a basic function

It's really not a major thing - it looks a little messy if you've got lots of characters moving between multiple rooms, and depending on how much the interaction changes between rooms, but it's really not that complicated. (I don't really see how it could be much simpler, to be honest - "If in one room, do something; if in another, do something else".)
The CallRoomScript / on_call method will have the room specific interactions will be in the appropriate room, which might make it a little easier to keep track of in your head (and unless all the NPCs can be in all the rooms, the individual on_call functions will probably be less unwheldy than the Character interaction functions would be), but there'll be just as many conditions to manage overall.
I know what you're thinking ... Don't think that.

Samwise

#4
Great, so I'll just import all the variables used in the character scripts to the global header.

Thank you!


SMF spam blocked by CleanTalk