Jump to content

PSA: When GetSex() fails...


Recommended Posts

Posted

This is not a question, but rather something like a solution I found for a problem.

I put it here because I couldn't find the answer with any search engine, so I expect people find this post that way... and maybe some of you know why this happens?

 

GetSex() always returns 0

I wanted to do this:

bool Function IsFemale(Actor akTarget) Global
    return akTarget.GetActorBase().GetSex() == 1
EndFunction

But it was always false because GetSex() always returned 0.

 

It was quite easy to find that doesn't work. You need to use GetLeveledActorBase() because "something about leveled lists", yadda yadda. That's even the way Sexlab gets sexes.

Don't worry though, GetLeveledActorBase() works fine for the player Actor.

 

 

If GetLeveledActorBase().GetSex() always returns 0...

But this also returned 0:

bool Function IsFemale(Actor akTarget) Global
    return akTarget.GetLeveledActorBase().GetSex() == 1
EndFunction

Even worse, I was getting weird results, like getting false from comparing akTarget.GetLeveledActorBase().GetSex() == 0 even though the only thing GetSex() was ever returning was 0.

 

Turned out, I wanted to have this function inside a library script that never gets instantiated by adding it to a Quest, Magic Effect, etc. in the CK (that's why it was a Global function), but for some reason, calling GetSex() from a Global function always returns 0, while calling it from an instantiated script works the expected way.

 

So, the proper way to get an Actor sex is:

bool Function IsFemale(Actor akTarget)
    ; It seems GetSex won't work if used inside a Global function; it can't be added to a library.
    return akTarget.GetLeveledActorBase().GetSex() == 1
EndFunction

tl;dr:

Don't call GetSex() from a Global function.

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...