So I'm a first time game creator and I'm attempting to write a script that will, upon using a certain object on another object, remove one object from the inventory and replace it with another. I have previously written scripts that allow me to make objects (closed doors) disappear when I use other objects (keys) on them. In that spirit I wrote the script you see below. For some reason I get an error message that says:
Failed to save room room11.crm; details below
room11.asc(11): Error (line 11): '(' expected
Here's the code I wrote. ChatGPT can't find any errors. Any help would be greatly appreciated. Line 11 is the LoseInventory line.
function oObject0_UseInv()
{
if (player.ActiveInventory == iEmptyBottle) {
player.LoseInventory = iEmptyBottle;
player.AddInventory = iBlueBottle;
}
}
Please, be careful with ChatGPT, it was already proven that ChatGPT does not guarantee a valid AGS script (don't know about other languages).
LoseInventory and AddInventory are functions. The syntax of calling a function is "FunctionName(arguments)".
Therefore the code should be:
function oObject0_UseInv()
{
if (player.ActiveInventory == iEmptyBottle) {
player.LoseInventory(iEmptyBottle);
player.AddInventory(iBlueBottle);
}
}
Related topics in the manual (they contain examples!):
https://adventuregamestudio.github.io/ags-manual/Character.html#characteraddinventory
https://adventuregamestudio.github.io/ags-manual/Character.html#characterloseinventory
That worked- thanks! And yes, I agree about ChatGPT. HAL has a long way to go before he gets to 9000.
ChatGPT can't find any errors because
player.LoseInventory = iEmptyBottle;
is a valid assignment in theory, IF player.LoseInventory were a property like .ActiveInventory for instance. As the verb in the name itself suggests, it's a method (or function in general) though.