Jump to content

ERROR: Syntax on function


You are about to reply to a thread that has been inactive for 144 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hey guys, 

I tried a lot but I can't seem to get around this issue, I am not an LSL expert but I can't find a syntax error here:

So i am trying to create a Health-bar for Roleplay purposes and sending llRegionSay events from a HUD attached object on touch_start

Here's a button example:

// Plus Button Script

default
{
    touch_start(integer total_number)
    {
        llSay(0, "Sending PlusButtonClicked message...");
        llRegionSay(88, "PlusButtonClicked");
    }
}

 

And Here's the Health-bar:

integer MAX_HEARTS = 4; // Maximum number of hearts
integer currentHearts = MAX_HEARTS; // Initial number of hearts

default
{
    state_entry()
    {
        // Display initial health bar
        updateHealthBar();
        
        // Listen for button events
        llListen(88, "", "", "");
    }
    
    touch_start(integer total_number)
    {
        // Reduce the number of hearts when clicked
        if (currentHearts > 0)
        {
            currentHearts--;
            // Update the displayed hearts
            updateHealthBar();
        }
        else
        {
            llSetText("Bewusstlos", <1.0, 1.0, 1.0>, 1.0);
            llResetScript(); // Reset the script if all hearts are gone
        }
    }

    listen(integer channel, string name, key id, string message)
    {
        if (message == "PlusButtonClicked")
        {
            if (currentHearts < MAX_HEARTS)
            {
                currentHearts++;
                // Update the displayed hearts
                updateHealthBar();
            }
        }
        else if (message == "MinusButtonClicked")
        {
            if (currentHearts > 0)
            {
                currentHearts--;
                // Update the displayed hearts
                updateHealthBar();
            }
        }
    }

    // Function to update the health bar display
    updateHealthBar()
    {
        string displayText = "";
        integer i;
        
        // Check if hearts are all gone
        if (currentHearts <= 0)
        {
            llSetText("Bewusstlos", <1.0, 1.0, 1.0>, 1.0);
            return;
        }

        // Construct the display text with hearts
        for (i = 0; i < currentHearts; i++)
        {
            displayText += "<3>"; // Use the heart symbol
        }

        // Display the hearts on the object
        llSetText(displayText, <1.0, 1.0, 1.0>, 1.0);
    } // End of updateHealthBar function
} // End of default state

 

Line 53 keeps giving me the Syntax error for updateHealthBar()

 

Hope anyone can help, thank you in advanced!!

Link to comment
Share on other sites

Your function "updateHealthBar()" is a "user function".

Only "events" are allowed inside of the State.

Try moving your function "updateHealthBar()" outside of the "default {" block.   For example, move it right after the line where you define "currentHearts":

integer currentHearts = MAX_HEARTS; // Initial number of hearts

This will make it part of the "global" code, where it should compile if you don't have other errors.

  • Like 1
Link to comment
Share on other sites

Thank you for the quick reply, really appreciated.  That did indeed fix the syntax error, unfortunately it looks like the object is not listening properly to the events, nothing happens.  But glad I got passed the syntax, now there is something else going on.

  • Thanks 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 144 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...