Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: strazer on Mon 18/10/2004 05:41:54

Title: Suggestion: SetCharacterProperty returning old value (SOLVED)
Post by: strazer on Mon 18/10/2004 05:41:54
There's obviously a function name clash for the SetCharacterProperty counterpart, so how about SetCharacterProperty returning the old value of the setting, just like SetGameOption? I'd find this very useful.
Title: Re: Suggestion: SetCharacterProperty returning old value
Post by: Edwin Xie on Mon 18/10/2004 05:47:22
Hmm, can you give an example? (Trying to find in what way this would be useful)
Title: Re: Suggestion: SetCharacterProperty returning old value
Post by: strazer on Mon 18/10/2004 06:04:09
I have my own character control script, and I turn characters that are not in the current room invisible with SetCharacterTransparency(charid, 100) so they can still be moved and perform their command chains in the background.

SetCharacterTransparency retains clickability (which is a good for my rain script, but I digress), so I have to turn that and walkthrough off if they're not visible.
At the moment, I pass the nointeraction setting manually as a parameter to my ccStartExecution function and save that setting in an array.
I'd find it more convenient if I could use the character's settings from the editor instead of hardcoding the relevant settings for each character.

So it's certainly not high priority, but I assume this wouldn't be too hard to implement, hence my suggestion.
Title: Re: Suggestion: SetCharacterProperty returning old value
Post by: Edwin Xie on Mon 18/10/2004 06:22:50
Hmm, that would be a time saver.....
Title: Re: Suggestion: SetCharacterProperty returning old value
Post by: strazer on Mon 18/10/2004 23:06:59
Nevermind, I have found out how to do it myself:

function GetCharacterSetting(int charid, int property) {
  if (character[charid].reserved[0] & property) return 1; else return 0;
}


Returns 1 if setting is turned on, 0 if it is turned off.

Example:

int oldsetting = GetCharacterSetting(GUY, CHAR_NOINTERACTION);

Works with:

CHAR_IGNORESCALING           the editor 'Ignore room area scaling' checkbox
CHAR_NOINTERACTION           the editor 'No interaction' checkbox
CHAR_NODIAGONAL                the editor 'No diagonal loops' checkbox
CHAR_IGNORELIGHT                the editor 'Ignore room area lighting' checkbox
CHAR_NOTURNING                   the editor 'Do not turn before walking' checkbox
CHAR_WALKTHROUGH             the editor 'Can be walked through' checkbox
CHAR_SCALEMOVESPEED        the editor 'Adjust speed with scaling' checkbox

CHAR_IGNOREWALKBEHINDS   used by SetCharacterIgnoreWalkbehinds

NOTE: It's a bit of a cheat, so use with caution. It's not officially supported and may stop working at any time!

EDIT:

Quote from: PumamanSounds like a plan -- I'll expose the flags as a readonly variable.

AGS v2.63 Beta 1 exposes said variable. Thanks CJ!
So if you're using v2.63 (or above), just replace
  if (character[charid].reserved[0] & property) return 1; else return 0;
with
  if (character[charid].flags & property) return 1; else return 0;
Title: Re: Suggestion: SetCharacterProperty returning old value (SOLVED)
Post by: Scorpiorus on Tue 19/10/2004 09:26:12
Nice finding ;)

At first, I was wondering why this flags variable is still marked as reserved as I remember to see it as 'flags'. Then I figured out that it was the plugin API where the character struct is updated with new variable names.
Having SetCharacterProperty return the old value would be nice, but additionally, it could also be useful to be able to retrieve these flags directly. So, while GetCharacterPropery is not an option, what if script GameCharacter's reserved[ 0 ] would be renamed to flags and marked as readonly so we could access it officially? :)
[EDIT:] Ah, I'd tried SetCharacterProperty(EGO, CHAR_NOTURNING, player.reserved[ 0 ] & CHAR_NOTURNING); but got an error message. I just thought it sets a flag on not 0 but it expects 1. And passing !!(player.reserved[ 0 ] & CHAR_NOTURNING) makes things unnecessarily complicated.

Aside question:
As it appears, character array of GameCharacter type is imported as character[20] while the total number is 150.
So, does savegameindex[], being imported as short savegameindex[20];, also have more than 20 slots?
Title: Re: Suggestion: SetCharacterProperty returning old value (SOLVED)
Post by: Pumaman on Wed 03/11/2004 20:15:12
Sounds like a plan -- I'll expose the flags as a readonly variable.

As for the savegameindex -- no, it does only have 20 slots. The fact that the characters is imported like that is an error in the built-in script header, but since no array bounds checking is done it doesn't actually matter.