Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Guyserman82 on Fri 11/02/2011 21:01:10

Title: Character-specific scripts
Post by: Guyserman82 on Fri 11/02/2011 21:01:10
I've been thinking about/ writing a JRPG , and I think that I could keep my code less messy if I could have a script associated with a single character. Is it possible to create a new script for a single character?
Title: Re: Character-specific scripts
Post by: monkey0506 on Fri 11/02/2011 22:03:18
Currently this isn't possible, but since the AGS Editor is now open-sourced, it might be possible to change this. I guess it would depend on whether the compiler itself would be capable of linking the functions in other scripts.

It's a feature that has been brought up before.
Title: Re: Character-specific scripts
Post by: Guyserman82 on Tue 22/02/2011 20:54:59
That would be nice, but I'm looking for a solution. How about a way to create multiple Global Scripts, or add pages to the Global Script?
Title: Re: Character-specific scripts
Post by: Khris on Tue 22/02/2011 21:42:59
You can add scripts by right-clicking the script node and selecting "New script".

Now, while the function that's triggered by the event (e.g. "Interact with character") must be in Global.asc, you can move the bulk of the code lines into the new script.

Global.asc:
function cVillager1_Interact() {
  CharacterInteract(cVillager1);
}

function cVillager2_Interact() {
  CharacterInteract(cVillager2);
}


Now you'd have this in the module script:
Header:
import function CharacterInteract(Character*c);

Main script:
function CharacterInteract(Character*c) {

  if (c == cVillager1) c.Say("Hi there!");
  if (c == cVillager2) c.Say("Go to the cave!");
}


Not sure how useful it is to use a new script for every character; I'd put all character interactions in a single script.
Title: Re: Character-specific scripts
Post by: Guyserman82 on Tue 22/02/2011 21:49:55
Thanks, Khris.

Actually, what I want with character specific scripts has to do with the Attribute variables more than character interaction.
Title: Re: Character-specific scripts
Post by: Khris on Tue 22/02/2011 23:31:32
What do you mean by attribute variables? Custom properties?

If you need additional help, please explain what you're after.

(I can't imagine how having a separate script for every character is useful in any way, so I'm curious :))