Conversation starting conditional
TheTinman
Member Posts: 74
Can a starting conditional script be in case or switch format so that one script can open multiple "text appears when" options?
0
Comments
I haven't used the conversation parameter function yet, so I'm not sure if there's an opportunity there to extend how far you can go with a single case statement. Maybe someone familiar with that will weigh in.
TR
A conditional script can contain a switch with multiple cases of ExecuteScript() so that the "action taken" varies according to the parameters or other conditions. The ActionTaken script in the conversation can than be omitted.
Alternatively, since both the Conditional and the ActionTaken scripts can access the same parameters / conditions, the Conditional can simply focus on whether the line should be spoken, true or false. The switch can be in the ActionTaken script, with each case executing a different snippet or function. This eliminates the need for lots of scripts, and allows the use of common code for related cases, so it's quicker to write, and less error-prone.
No, you don't need breaks when there are returns. Once you hit case 1 you either return TRUE or FALSE. You will never get to the break statement so it's not needed.
//PC and Item to check for
int GetNumItems(object oPC,string sItem)
{
//Number of items
int nNumItems = 0;
//Check for items
object oItem = GetFirstItemInInventory(oPC);
//Is the item in the inventory
while (GetIsObjectValid(oItem) == TRUE)
{
if (GetTag(oItem) == sItem)
{
//Get number of items in the inventory
nNumItems = nNumItems + GetNumStackedItems(oItem);
}
//Loop through inventory
oItem = GetNextItemInInventory(oPC);
}
return nNumItems;
}
int StartingConditional()
{
object oPC = GetPCSpeaker();
if (GetNumItems(oPC, "Stone") >= 1)
return TRUE;
return FALSE;
{
}
if (GetNumItems(oPC, "Stone") >= 2)
return TRUE;
return FALSE;
{
}
if (GetNumItems(oPC, "Stone") >=3)
return TRUE;
return FALSE;
}
To use the same script for each case, you need to pass a parameter in the conversation lines, specifying the number of stones required to trigger that line. They need to be in the order 3, 2, 1, because if 3 is true, 2 and 1 are also.
For example, if the parameter in the conversation is called StoneCount,
Incidentally, scripts are easier to read when you use the [code] BBCode.
Should I have used == instead of >=
BTW, In order to get your code into a code box you need to use a slightly hidden feature of the editor in here. In the editing tools above the box you type in there are a number of tools which have an inverted triangle next to them. These have drop down menus. The one you want is immediately to the left of the smiley/emoji. In there you will find one that says code. Simply highlight your code and then select that menu option.
FWIW if you are unfamiliar with the compound += operator see my tutorial (shameless plug) - TR's Basics - Mostly Operators.
Hope you find this useful.
TR