Character-specific scripts

Started by Guyserman82, Fri 11/02/2011 21:01:10

Previous topic - Next topic

Guyserman82

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?

monkey0506

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.

Guyserman82

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?

Khris

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:
Code: ags
function cVillager1_Interact() {
  CharacterInteract(cVillager1);
}

function cVillager2_Interact() {
  CharacterInteract(cVillager2);
}


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


Main script:
Code: ags
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.

Guyserman82

Thanks, Khris.

Actually, what I want with character specific scripts has to do with the Attribute variables more than character interaction.

Khris

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 :))

SMF spam blocked by CleanTalk