Parse error

Started by SebastianEl, Fri 26/04/2024 11:56:22

Previous topic - Next topic

SebastianEl

Hi! I'm trying to play a sound, I've imported it to: Audio/Sounds and I've added to room script line:


Code: ags
// room script file

aSound1.Play();

function hLadder_AnyClick(Hotspot *theHotspot, CursorMode mode)
{
cEgo.Say("These are falling apart..shame..");
}

function hHotspot2_AnyClick(Hotspot *theHotspot, CursorMode mode)
{
cEgo.Say("Some old mining machinery. Dead since ages");
}

function oObject0_Look(Object *theObject, CursorMode mode)
{
cEgo.Say("What's that?");
}


(I've pasted whole room code)

Hovever I'm recieving an Parse error: unexpected 'aSound1' line 3

What am I doing wrong? :/



Khris

Like @Snarky explained, commands like that always go inside functions so AGS knows when to play the sound.

AGS scripting is event-based, which means when certain events occur (a room loads, hLadder is clicked, etc.) AGS checks if a function is linked to the event, then runs the function. Which means the code inside the function is executed.

SebastianEl

Ok...I'm grasping the idea (sort of.. ;) ), but how to set this up? Coud you please give me an example? :)

SebastianEl

I've tried chat GPT but still no luck..

Code: ags
// room script file

function room_Load() {
    // Kod do odtworzenia dźwięku
    aSound1.Play();
}

function hLadder_AnyClick(Hotspot *theHotspot, CursorMode mode)
{
cEgo.Say("These are falling apart..shame..");
}

function hHotspot2_AnyClick(Hotspot *theHotspot, CursorMode mode)
{
cEgo.Say("Some old mining machinery. Dead since ages");
}

function oObject0_Look(Object *theObject, CursorMode mode)
{
cEgo.Say("What's that?");
}

Khris

Do NOT use ChatGPT for this.

I explained how here:
https://www.adventuregamestudio.co.uk/forums/beginners-technical-questions/resize-player-character/msg636662736/#msg636662736

Just typing out the function is not enough, it needs to be linked to the event.

This is also explained here:
https://adventuregamestudio.github.io/ags-manual/acintro3.html

And judging from the rest of your room script, you've already done this.

SebastianEl

Thank you, it worked!

SMF spam blocked by CleanTalk