Suggestion: SetCharacterProperty returning old value (SOLVED)

Started by strazer, Mon 18/10/2004 05:41:54

Previous topic - Next topic

strazer

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.

Edwin Xie

Hmm, can you give an example? (Trying to find in what way this would be useful)
Moving at superhigh speed getting to the planet called Earth. But it is boxed in white......thing.....

strazer

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.

Edwin Xie

Moving at superhigh speed getting to the planet called Earth. But it is boxed in white......thing.....

strazer

Nevermind, I have found out how to do it myself:

Code: ags
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:

Code: ags
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
Code: ags
  if (character[charid].reserved[0] & property) return 1; else return 0;

with
Code: ags
  if (character[charid].flags & property) return 1; else return 0;

Scorpiorus

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?

Pumaman

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.

SMF spam blocked by CleanTalk