Starting Conditional Help

Okay I’m missing something on the text appears condition when determining whether the pc has an item in their inventory. I have, for the sake of this example, 5 different tagged items. “cat” “dog” “mouse” “lion” “dragon”. Now the script wizard makes all 5 items necessary in the pc’s inventory to start the text. What I’m looking for is anyone of the 5 items is okay to start the text.

I feel like I should know this, but something escapes me. I’ve tried LS Generator too. I could write 5 different text appears dialogs but there are a lot more items in the project. I feel like I’m missing something so obvious.
Thanks guys in advance!

Set a local variable on the PC when they get any of the items, and update it with each new acquisition. Then check for that local.

ie OnAcquire for each item on list, Mouse, Lion, etc., first check for the local. If it exists, increment it by 1. If it doesn’t exist (they haven’t got any of them yet), set it to 1.

Something like that?

-JFK

If you have NWN Lexicon, look under the bitwise operators for a way to store the completed acquisition of any of the objects into a single variable that you could store on the player locally if no persistence,then put a check into your conditional for any particular item to open whatever conversation or branch of conversation. make sure the conditional script returns a “1” to enable the conversation or branch.

Thank you guys for your advice. Looks like I will have to go the ‘SetLocalInt’ route.

You could also use logical OR (||):
if(GetItemPosessedBy(oPC, “cat”)!=OBJECT_INVALID||GetItemPosessedBy(oPC, “dog”)!=OBJECT_INVALID||GetItemPosessedBy(oPC, “mouse”)!=OBJECT_INVALID)
{
return TRUE;
}
return FALSE;

1 Like

Strictly speaking, @Mannast’s solution is the only one so far that fulfils the OP requirement.

With the flag solution, the condition will always be true once the player has acquired one of the items, even if it’s no longer in inventory.

That could be fixed when items are unacquired, of course, but that’s a lot of extra work, which still involves the logical OR, either explicitly, or as bit switches.

As a rule of thumb, it’s often simpler and more robust to check the current situation directly (i.e. what is in inventory here and now) than to rely on variables set by events.

3 Likes

Thanks for your reply and I think this will work nicely but I keep getting an Error: No right bracket on expression

if(GetItemPosessedBy(oPC, “cat”)!=OBJECT_INVALID||GetItemPosessedBy(oPC, “dog”)!=OBJECT_INVALID||GetItemPosessedBy(oPC, “mouse”)!=OBJECT_INVALID)
{
return TRUE;
}
return FALSE;

One more thought, why not just give each item the same tag, so just run one search for the first itm you find insteadof searching over an dover since you want a pc to have any of them. Do a findSubstring for the tag if you should want to differentiate the items for a specific search in the future if needed. This would simplify you search required for your idea now while leaving the option open for later expansion

I think I get what you’re suggesting, however there are different dialogs the pc says when the items are removed

I use something like this in one of my conversations.

Here’s how I have it set up:

#include “nw_i0_tool”
int StartingConditional()
{
object oPC = GetPCSpeaker();
return (HasItem(oPC, “cat”) !=
HasItem(oPC, “dog”) !=
HasItem(oPC, “mouse”) !=
HasItem(oPC, “lion”) !=
HasItem(oPC, “dragon”));
}

object oPC = GetPCSpeaker();
if(GetItemPossessedBy(oPC, "cat")!= OBJECT_INVALID||GetItemPossessedBy(oPC, "dog")!= 
 OBJECT_INVALID || GetItemPossessedBy(oPC, "mouse")!= OBJECT_INVALID|| 
GetItemPossessedBy(oPC, "lion")!= OBJECT_INVALID || GetItemPossessedBy(oPC, "dragon")!= 
OBJECT_INVALID)
{
return TRUE;
}
return FALSE;

I wrote the earlier post without the toolset, so it used stupid versions of the characters. This compiled

Be aware that result of this operation depends on which items oPC currently has due to selected boolean comparison order and WILL lead to the worst kind of problems to debug - runtime ones which happen only sometimes. See table below.

//cat != dog != mouse != lion != dragon => condition result
0 != 0 != 0 != 0 != 0 => result is FALSE
0 != 0 != 0 != 0 != 1 => result is TRUE
0 != 0 != 0 != 1 != 0 => result is TRUE
0 != 0 != 0 != 1 != 1 => result is FALSE
0 != 0 != 1 != 0 != 0 => result is TRUE
0 != 0 != 1 != 0 != 1 => result is FALSE
0 != 0 != 1 != 1 != 0 => result is FALSE
0 != 0 != 1 != 1 != 1 => result is TRUE
0 != 1 != 0 != 0 != 0 => result is TRUE
0 != 1 != 0 != 0 != 1 => result is FALSE
0 != 1 != 0 != 1 != 0 => result is FALSE
0 != 1 != 0 != 1 != 1 => result is TRUE
0 != 1 != 1 != 0 != 0 => result is FALSE
0 != 1 != 1 != 0 != 1 => result is TRUE
0 != 1 != 1 != 1 != 0 => result is TRUE
0 != 1 != 1 != 1 != 1 => result is FALSE
1 != 0 != 0 != 0 != 0 => result is TRUE
1 != 0 != 0 != 0 != 1 => result is FALSE
1 != 0 != 0 != 1 != 0 => result is FALSE
1 != 0 != 0 != 1 != 1 => result is TRUE
1 != 0 != 1 != 0 != 0 => result is FALSE
1 != 0 != 1 != 0 != 1 => result is TRUE
1 != 0 != 1 != 1 != 0 => result is TRUE
1 != 0 != 1 != 1 != 1 => result is FALSE
1 != 1 != 0 != 0 != 0 => result is FALSE
1 != 1 != 0 != 0 != 1 => result is TRUE
1 != 1 != 0 != 1 != 0 => result is TRUE
1 != 1 != 0 != 1 != 1 => result is FALSE
1 != 1 != 1 != 0 != 0 => result is TRUE
1 != 1 != 1 != 0 != 1 => result is FALSE
1 != 1 != 1 != 1 != 0 => result is FALSE
1 != 1 != 1 != 1 != 1 => result is TRUE
3 Likes

This one also failed to compile for me with an ERROR: return and function type mismatched.
Hi Mannast, okay I think i solved it and I got it to compile, now to test it!
Hi once again, this doesn’t work. it goes to the default npc conversation automatically even if I have all items in the pc inventory.

Guys Thank you so much for your replies and help. I sure do appreciate the advice and tutoring I get from you all! Greatly appreciate all who responded. I’m going to go with an individual conversation npc line to ensure it plays out correctly. Thanks again all! Best Holiday wishes to everyone as well!

So sorry it didn’t work out. best of holidays to you!

First thing first. Any code you post in here must be posted as code otherwise you run the risk of it not being able to be compiled because otherwise your quotation marks will be prettified to 66 & 99 style quotes or 6 & 9 single quotes. If you don’t know how to post code look at this thread.

Now on to my two penn’orth on the topic at hand.

Either I haven’t read the problem right, the right question hasn’t been asked or the op didn’t supply the necessary answer. So what is the missing question? That would be “Does it have to be that the conversation branch in question is only activated if and only if they have any one but only one of the list of items supplied?”. If the answer is yes then the only simple solution I can think of that will actually work is

#include "nw_i0_tool"

int StartingConditional()
{
	object oPC = GetPCSpeaker();
	int iReturnMe = FALSE, iTestMe = 0;
	
	if(HasItem(oPC, "cat"))
		iTestMe++;
		
	if(HasItem(oPC, "dog"))
		iTestMe++;
		
	if(HasItem(oPC, "mouse"))
		iTestMe++;
		
	if(HasItem(oPC, "lion"))
		iTestMe++;
		
	if(HasItem(oPC, "dragon"))
		iTestMe++;
	
	if(iTestMe == 1)
		iReturnMe = TRUE;
	
	return iReturnMe;
}

If on the other hand it only requires that at least one (but could be more) be possessed then the answer is simpler -

#include "nw_i0_tool"

int StartingConditional()
{
	object oPC = GetPCSpeaker();
	return (HasItem(oPC, "cat") || HasItem(oPC, "dog") || HasItem(oPC, "mouse") || HasItem(oPC, "lion") || HasItem(oPC, "dragon"));
}

TR

Thanks TR for your response. I may have been at fault from the beginning as I had the npc default line as the first line of conversation. ( if none of the items, mouse ,cat, dog, etc.) were not found. I have since re- written dialog to accommodate HasItems starting condition. So… to my mistake, your example, along with tacticalERK and Mannast may have worked initially. Don’t you just hate newby coders? Anyway, with the extra work, the dialog and scripts now works perfectly.

Appreciate your response too as always, you’ve helped me before! Would like to know if my theory is correct on why I couldn’t get Mannast’s and the other’s to run.

Well apart from the “fancy pants” (66 & 99) quotes, I’m not too sure. What I tend to do is to copy and paste code into notepad++. That way I can edit the code so that it looks like my personal preferences for code layout. It also has a nice feature in that if you put your cursor next to a bracket ‘(’ or ‘)’ or a brace ‘{’ or ‘}’, it highlights that symbol and the matching one. Great for finding missing ones.

TR

1 Like