hallo,
my charakter has several keys, everytime using any key on a certain door a text should be displayed, how to avoid repetitions like
if (player.ActiveInventory == inventory[2] || player.ActiveInventory == inventory[7],....) Display("say what");
what I'm looking for is a list of numbers appropriate to apply in the square brackets of inventory[]
I would be grateful for any clues
Several options, but the easiest is to write a helper function:
bool isKey(this InventoryItem*)
{
if(this == inventory[2] || this == inventory[7] || ...)
return true;
else
return false;
}
You can put this in the global script or its own script module, importing it in the corresponding header file:
import bool isKey(this InventoryItem*);
And now you can just write:
if(player.ActiveInventory.isKey())
Display("say what");
Alternatively, if you want to do it from the editor, make a new boolean Property for InventoryItems called "IsKey", and set it to true for each key in your game. Then, you can go:
if (player.ActiveInventory.GetProperty ("IsKey")) Display ("Say what");
Regardless of the amount of different keys your game has.
thank you very much, it works pretty well