Jump to content

simple script always has syntax error


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

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

Recommended Posts

hi. im not a scripter, and can only work with scripts when they have instructions in them. i have an acquaintance who gave me this script for a build im doing that has an owl in it that i wanted to hoot every 40 seconds, but i wanted the customers to be able to touch the owl to turn the sound on/off. turning it on would play the sound every 40 seconds. 

so he sends me this script to fill out but it doesnt work. it always says syntax error(2, 0) right before "default"

first thing i did was show him how i filled in the times and names and i was told it was correct and that i should relog. 

i relogged and it still does the same thing. this is the script i was given after i filled in the information, if anyone knows why it wont work i could really use the help! thank you.

float interval = 40
//put your time after interval
default
{
    touch_start(integer total_number)
   
    {
      llPlaySound("Owl", 1);        
       //put sound file name between quotes
       llSetTimerEvent(interval);
        
    }
 
timer(40)
//put time between parenthesis 
    {
        llPlaySound("Owl", 1);
//put sound file name between between quotes        
    }
}

Link to post
Share on other sites

yes, the owl file was inside. yes left click was not doing anything. i was told i had to "run" the script, which i did, and it works. it just doesnt shut off when u touch it lol. good enough though, thank you

Link to post
Share on other sites
float interval = 40; //put your time after interval
integer switch;

default {
    touch_start(integer total_number) {
        if (switch = !switch) llSetTimerEvent(.1);
        else llSetTimerEvent(.0);
    }
 
    timer() {
        llPlaySound("Owl", 1); //put sound file name between between quotes        
        llSetTimerEvent(interval);
    }
}

Try this.

  • Like 1
Link to post
Share on other sites

This is a good illustration of the basic paradigm of LSL: a state machine. The owl has two states: hooting and silent. In each state, it's response to being touched and its response to the timer going off are different. Using states rather than a switch variable, you get a very simple set of event handlers in each state:

float interval = 40.0; // how often the sound is triggered
string hoot = "Owl";   // name of the sound in the object

default
{
    state_entry()
    {
        // you could do something here to let the user customize
        state hooting;
    }
}

hooting 
{
    state_entry()
    {
        llPlaySound(hoot, 1); // make it clear what state we're in
        llSetTimerEvent(interval);
    }

    timer()
    {
        llPlaySound(hoot, 1);
        // you could call llSetTimerEvent here to introduce some randomness
    }

    touch_start(integer total_number)
    {
        state silent;
    }
}

silent
{
    state_entry()
    {
        llSetTimerEvent(0.0); // no need for the timer so stop it
    }

    // note that there is no timer() event handler

    touch_start(integer total_number)
    {
        state hooting;
    }

}
    

 

  • Like 2
Link to post
Share on other sites
6 hours ago, Oz Linden said:

Using states rather than a switch variable, you get a very simple set of event handlers in each state:

You also consume more memory using states instead of using simple global integer checks to do the same thing.

State switching is at least good for culling most queued events, though.

Link to post
Share on other sites

Yeah, I wonder if there are "externalities" completely invisible to scripters that would favor moving the script to a state ("silent") without a timer() event handler, as opposed to simply calling llSetTimerEvent() to stop those events from ever occurring. As @Lucia Nightfire notes, we see the opposite incentive: save a little memory by using fewer states and less code overall, but for all we know that may not reflect the overhead of what the scheduler and event dispatcher does behind the scenes.

Link to post
Share on other sites
21 hours ago, Oz Linden said:

 


float interval = 40.0; // how often the sound is triggered
string hoot = "Owl";   // name of the sound in the object

default
{
    state_entry()
    {
        // you could do something here to let the user customize
        state hooting;
    }
}

hooting 
{
    state_entry()
    {
        llPlaySound(hoot, 1); // make it clear what state we're in
        llSetTimerEvent(interval);
    }

    timer()
    {
        llPlaySound(hoot, 1);
        // you could call llSetTimerEvent here to introduce some randomness
    }

    touch_start(integer total_number)
    {
        state silent;
    }
}

silent
{
    state_entry()
    {
        llSetTimerEvent(0.0); // no need for the timer so stop it
    }

    // note that there is no timer() event handler

    touch_start(integer total_number)
    {
        state hooting;
    }

}
    

or to keep the timer code together
 

hooting
{
   state entry
   {
      llPlaySound ...
      llSetTimerEvent(interval);
   }
   
   timer()
   {
      llPlaySound ...
   }

   touch_start(...)
   {
      state silent;
   }
   
   state_exit()
   {
      llSetTimerEvent(0.0);
   }
}

silent
{
   touch_start(...)
   {
      state hooting;
   }
}

 

  • Like 2
Link to post
Share on other sites
You are about to reply to a thread that has been inactive for 188 days.

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...