Working script stopped working

Started by Jordanowen42, Sun 02/07/2023 06:30:33

Previous topic - Next topic

Jordanowen42

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:

Code: ags

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.

Nahuel

Quote from: Jordanowen42 on Sun 02/07/2023 06:30:33
Code: ags

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.
Life isn't a game. Let's develop a life-like-game.

Tomags

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.

Jordanowen42

I used the script with the advised formatting and it worked like a charm. Guess you have the magic touch!

Khris

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.

SMF spam blocked by CleanTalk