I'm having issues with the room_AfterFadeIn script.

Started by The_Fonz, Sat 07/05/2022 05:13:34

Previous topic - Next topic

The_Fonz

I am new to the AGS community, and I've been creating a King's Quest styled game, up till a few hours ago it was functioning completely fine. I've been looking through the manual and various tutorials nonstop, But I can't find the solution., I think I might have deleted a line of code on accident.
Everything was fine until I added a second room, I followed this tutorial on YouTube by Densming: https://www.youtube.com/watch?v=eCo0CZzKTPk
I was using regions instead of edges because the door I was trying to use was in an odd area, and there are 4 other doors also. Now when I try to test my game it gives me the "error: prepare_script: error -18(no such function in script) trying to run 'room_afterFadeIn' (Room 1)
This was the code I was using in the first room script for my door.

function region6_WalksOnto()
{
cEgo.ChangeRoom(2);
}

I couldn't get it to work so I deleted it and went back to the manual, I think this is when I deleted the other line, because when I came back to test something else that was previously working I could no longer play the game at all. (game will open and play for about 3 seconds, then is interrupted with the error)

This is the script from my first room, I didn't mess with the Global script during this session.
I don't know how to fix this, I've been staring at it for hours with different forums pulled up and videos, but I don't know what to do. Thank you :(

Code: ags

// room script file

function hDoorRoomOne_Look()
{
Display("The sign above the door says 'Tavern'.");
}

function hDoorTwoRoomOne_Look()
{
Display("The sign above the door says 'Inn'.");
}

function hInnWindowRoomOne_Look()
{
Display("Hmm, Looks like an inn to me.");
}

function hDoorRoomOne_Interact()
{
Display("This must be the Tavern entrance..");
}

function hDoorTwoRoomOne_Interact()
{
Display("The door appears to be locked. Perhaps I should return at a more reasonable time.");
}

function hInnWindowRoomOne_Interact()
{
Display("The room is dark, Looks like everyone is asleep.");
}

function oKey_Interact()
{
player.Walk(230, 184, eBlock);
oKey.Visible = false;
player.AddInventory(iKey);
GiveScore (5);
}

function room_Load()
{
AudioChannel* chan = aMusic1.Play();
chan.Volume = 100;

}

Snarky

Welcome to AGS!

I'm not 100% sure exactly what the problem is, but I suspect it has to do with linking events to functions.

When you created the region6_WalksOnto() function, remember how you had to do it from the events tab (lightning bolt) of the region in the room editor? When you do that, it creates a link from the event to the function (which is often called the event handler), which tells AGS to run that function when the event happens. Even if you delete the function from the script, the link still remains, but now it's pointing to something that no longer exists. So it will break, either when you compile, when you try to run the game/enter the room, or when you walk onto that region.

So you have to go back to the events tab for the region and delete the link from that event.

BTW: The thread is titled "I'm having issues with the room_AfterFadeIn script", but there is no room_AfterFadeIn() function in the room script you posted. (room_AfterFadeIn() is a function that is an event handler; it's the default name of the function that runs once immediately after the room has fully loaded and the screen has faded in. The script as a whole, with all the different events and functions, is just called the "room script.") Did you also create and link room_AfterFadeIn() at one time? If so, you'll need to delete that link as well, in the room events.

heltenjon

Snarky's solution is the most professional, but I believe when I did the same error you did, I could solve it by adding the function again by typing it into the room script file and leaving it open or commenting out what was supposed to happen. Basically, you can't erase stuff you make with the buttons in the editor by simply deleting the lines in the room script.

SMF spam blocked by CleanTalk