Having an item peruse another item's inventory via conversation - can anyone help?

Greetings, all!
So, even when I was messing with scripting all those years ago, I never really understood it. Now I have an idea, and it has me stumped.

I want to have a placeable object hooked to a conversation (call it a Planar Console, tag of “pfc_console”), and in that conversation, the Planar Console looks to the inventory of another placeable object (call it a Planar Crystal Housing, tag of “pfc_housing”) to determine what sort of conversation options are available. The presence of a particular Focus Crystal (tag of “focus_crystal_xx” opens a particular conversation line. And there are 11 different Focus Crystals.

This is the script that I am puzzling with right now. I have it set in the “Text Appears When” tab of the Conversation Editor’s script window.

int StartingConditional()
{
// Get the possessor
object oPossessor = GetObjectByTag(“pfc_housing”);
// Get the crystal
object oCrystal = GetObjectByTag(“focus_crystal_01”);
oPossessor = GetItemPossessor(oCrystal);
{
if (oPossessor == oCrystal) return FALSE;
return TRUE;
}
}

I know I’m missing something somewhere, but I can’t figure it out, even with the help of the Lexicon, Lilac Soul’s Script Generator, and numerous tutorials. Any help is greatly appreciated!

(Oh, if I didn’t mention, I am running 1.69 Diamond with the Critical Rebuild Patch applied.)

At the moment your script returns FALSE only if the crystal is possessed by itself - so the script will return TRUE always.

You could change your script to


    int StartingConditional()
    {
        // Get the housing
        object oHousing = GetObjectByTag(“pfc_housing”);
        // Get the crystal
       object oCrystal = GetObjectByTag(“focus_crystal_01”);
       // Get the possessor
       object oPossessor = GetItemPossessor(oCrystal);
       if (oPossessor == oHousing)
       {
           return FALSE;
       }
       return TRUE;
    }

Now it will return FALSE if the crystal is possessed by the housing. Switch TRUE and FALSE if you want the script to return TRUE if the crystal is possessed by the housing.

The problem is that you’re using oPossessor to mean two things - the object with the tag pfc_housing, and the object that possesses the item. Then you’re comparing the latter with the item itself, which will always be FALSE. Try this:

int StartingConditional()
{
// Get the Housing
object oHousing = GetObjectByTag(“pfc_housing”);
// Get the crystal
object oCrystal = GetObjectByTag(“focus_crystal_01”);
// Get the possessor of the crystal
object oPossessor = GetItemPossessor(oCrystal);
{
if (oPossessor != oHousing) return FALSE;
return TRUE;
}
}

This returns TRUE when the crystal is in the housing - presumably you want it that way round?

Indeed, these both look good, but when compiled, it gives this message:

4/17/2020 10:41:06 PM: Error. ‘focus_crystal_01’ did not compile.
focus_crystal_01.nss(4): ERROR: VARIABLE DEFINED WITHOUT TYPE

Arrgh! I pound my head on teh table! What can I be doing wrong?

Apparently the error is in line 4:

object oHousing = GetObjectByTag(“pfc_housing”);

Most likely you’ve copied one of the two scripts into the toolset? Problem is that the “” are not the ones the compiler expects. Replace them and the script should compile (in case you’ve copied my script you should also correct the error it had (delete the “;” after “if (oPossessor == oHousing);”).

The odd quotations - that’s what the problem was! Weird! Now the script works like a charm, and does exactly what it should!

Thank you both, Kamiryn and Proleric, for your help! Wonderful, wonderful, wonderful!

Stay safe and be well!

Hint - when posting code here, enclose it in [code] [/code] tags.

That way, it renders correctly, with indentation. Otherwise, any strange characters in the rendering will be inherited by anyone copying and amending the code.

See this pinned thread. It tells you about ways to post code amongst loads of other things about these forums.

TR