Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Jordanowen42 on Sun 02/07/2023 06:30:33

Title: Working script stopped working
Post by: Jordanowen42 on Sun 02/07/2023 06:30:33
Hello-

So I have a basic script for using inventory items with hotspots on the screen. It has worked before so I usually just copy/paste it into each place with the item names changed. I used it in a recent room script and it said Failed to save room room37.crm; details below
room37.asc(20): Error (line 20): Parse error in expr near 'iDeadBattery'

Here's the script in question:


function hHotspot2_UseInv()
{
if (player.ActiveInventory == iDeadBattery) {
    player.LoseInventory(iDeadBattery);
object[0].Visible = true; }
}

Any help would be greatly appreciated. I've looked at the manual, coming up empty.
Title: Re: Working script stopped working
Post by: Nahuel on Sun 02/07/2023 09:40:04
Quote from: Jordanowen42 on Sun 02/07/2023 06:30:33
function hHotspot2_UseInv()
{
  if (player.ActiveInventory == iDeadBattery)
  {
    player.LoseInventory(iDeadBattery);
    object[0].Visible = true;
  }
}


I don't see anything wrong with your code there, I would recommend to add better formatting but that's picky on my side  :-D . Are you sure you copied the lines between ~18-23?

I just literally copied and pasted your code example, and had no compilation error.

Another idea, check {} for previous code, and also check if you don't have special characters like "invisible" (‎‎U+3164) spaces with characters that are not spaces.

All the best.
Title: Re: Working script stopped working
Post by: Tomags on Sun 02/07/2023 09:57:16
On first sight I don't see anything wrong either. As Nahuel said, it is possible that there is a forgotten closing brace somewhere above in the code; or a hidden character...

You mentioned you copy-pasted the code. I'd recommend you checking whether you pasted the trigger part of the function ("function hHtospot2_UseInv()"). I think I've had problems when I've manually written or overwritten some triggers instead of generating them from the properties in the editor. If this was the case, you might as well try to re-generate the trigger properly from the editor and just paste the function "content" inside the braces and see what happens.
Title: Re: Working script stopped working
Post by: Jordanowen42 on Tue 04/07/2023 05:08:31
I used the script with the advised formatting and it worked like a charm. Guess you have the magic touch!
Title: Re: Working script stopped working
Post by: Khris on Tue 04/07/2023 06:13:05
The original code is fine, so it sounds like you had a special space character in your code that irritated the compiler and deleted it while fixing the indentation.