Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Jordanowen42 on Sun 21/05/2023 04:11:23

Title: Strange ( error, no visible problems in code
Post by: Jordanowen42 on Sun 21/05/2023 04:11:23
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;
    }
}


Title: Re: Strange ( error, no visible problems in code
Post by: Crimson Wizard on Sun 21/05/2023 04:41:10
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:

Code (ags) Select
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
Title: Re: Strange ( error, no visible problems in code
Post by: Jordanowen42 on Mon 22/05/2023 00:24:31
That worked- thanks! And yes, I agree about ChatGPT. HAL has a long way to go before he gets to 9000.
Title: Re: Strange ( error, no visible problems in code
Post by: Khris on Mon 22/05/2023 11:44:29
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.