Text Appears When

Trying to get this to work right. The text is suppose to appear when the player has only 1 of the items (not both). Would this be correct? It’s being skipped in my conversation…

#include “nw_i0_tool”
int StartingConditional()
{
if(!HasItem(GetPCSpeaker(), “quest001”))
return FALSE;
return TRUE;

if(!HasItem(GetPCSpeaker(), "quest002"))
return FALSE;
return TRUE;

}

code flows sequentially … so what you’ve got there is:

int StartingConditional()
{
    if (!HasItem(GetPCSpeaker(), "quest001"))
    {
        return FALSE;
    }
    else
    {
        return TRUE;
    }

    // this never runs because all conditions above gave a return

    if (!HasItem(GetPCSpeaker(), "quest002"))
    {
        return FALSE;
    }
    else
    {
        return TRUE;
    }
}

here’s a way to do it (notice the sub-brackets in the condition statement)

int StartingConditional()
{
    object oPcSpeaker = GetPCSpeaker();

    int bHasItem1 = HasItem(oPcSpeaker, "quest001");
    int bHasItem2 = HasItem(oPcSpeaker, "quest002");

    if (   ( bHasItem1 && !bHasItem2)
        || (!bHasItem1 &&  bHasItem2))
    {
        return TRUE;
    }
    return FALSE;
}
2 Likes

and if you want to get fancy …

int StartingConditional()
{
    object oPcSpeaker = GetPCSpeaker();
    return (HasItem(oPcSpeaker, "quest001") ^ HasItem(oPcSpeaker, "quest002"));
}

/untested

2 Likes

It’s kind of off-topic, I know, but maybe you know, KevL, if there’s a way in NWScript to print a string with the double quotation mark (") inside that string (without using a TLK file)?

@Aqvilinus Depends. 1.69, I don’t think so. However with the last patch for EE (8168 patch notes on here) you can now use an extra escape code in a string just for double quotes - \" is the escape code. Don’t know about NwN2.

In theory that might work but you are using the bitwise XOR operator. Probably better (and easier to understand would be -

	return (HasItem(oPcSpeaker, "quest001") != HasItem(oPcSpeaker, "quest002"));

Which returns a boolean.

TR

4 Likes

i don’t think there is, Aqv. But then i shy away from even trying it (in NwScript). Typically you should be able to escape it with a preceeding backslash … but escapes don’t seem to be fully implemented … maybe by using Skywing’s compiler with extensions enabled or something.

It may also depend on whether it’s Nwn1 or 2. Maybe it’s possible w/ NWNx …

1 Like

Thanks so much!