Jump to content

Syntax check please? :') [Solved!]


Dragon Hijinks
 Share

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

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

Recommended Posts

Hey there all. I'm not really a scripter. I mostly try to Frankenstein stuff together until it works.

Right now I'm trying to mash together a script that plays a random inventory sound and single animation once chat has been sent

I've alllllmost got it. Only the animation is giving me trouble, and it's mostly because I'm allergic to syntax and simply can't figure out what SL is yelling at me about.

 

integer listener;
integer channel = 0;
string msg = "play";
key ownerid;


default
{
    state_entry()
    {
        ownerid = llGetOwner();
        listener = llListen(channel, "", ownerid, "");
        llRequestPermissions(llDetectedKey(0), PERMISSION_TRIGGER_ANIMATION);
    }
    run_time_permissions(integer perm)
    {
        if (perm & PERMISSION_TRIGGER_ANIMATION)
        {
            llStartAnimation("wolf_bark");
    }

listen(integer channel, string name, key id, string message)

{
    
    llSetSoundQueueing(TRUE);
            llPlaySound(llGetInventoryName(INVENTORY_SOUND,llRound(llFrand(llGetInventoryNumber(INVENTORY_SOUND) - 1))),1.0);


}
 }
 }

 

 

It's saying there's something wrong at the beginning of the "listen" but I don't know what. ;u;''

Please laugh at my spaghetti code and lend a hand if you don't mind.

Edited by Dragon Hijinks
Link to comment
Share on other sites

7 minutes ago, Dragon Hijinks said:

Thank you! That got rid of the error.

Now to figure out why it won't request permissions like I've told it to. 😅

That's because the llDetectedKey() command needs to be in an event that actually detects something (like the listen or touch or sensor events).  Assuming you want the animation to be triggered on the owner of the script then you could replace llDetectedKey(0) with ownerid, if not then you're going to need to use a sensor or some other method to obtain the uuid key for the avatar you want to trigger the animation on before trying to request permissions from them.

Link to comment
Share on other sites

Just now, Dragon Hijinks said:

Nada. :')

The script isn't giving me any errors, but it's also doing nothing. Not even the sounds are playing now.

yes the result is nada but you are on the right path

change llListen to listen for the 'msg' from you the owner.  So that when you type 'play' into the open chat box the listen event will hear it, nd the listener will ignore anything else you type in the public chat box

llListen(channel, "", ownerid, msg);

http://wiki.secondlife.com/wiki/LlListen

then in the listen event: play the sound and start the animation

Link to comment
Share on other sites

1 minute ago, Mollymews said:

yes the result is nada but you are on the right path

change llListen to listen for the 'msg' from you the owner.  So that when you type 'play' into the open chat box the listen event will hear it, nd the listener will ignore anything else you type in the public chat box

llListen(channel, "", ownerid, msg);

http://wiki.secondlife.com/wiki/LlListen

then in the listen event: play the sound and start the animation

Aye but what I'm trying to do is have it play a sound on everything I type. Like a typer sound effect, but it plays after I send rather than as I'm typing.

I got the sounds fixed up, but it's still not asking for permission to animate and therefore not animating. This is what I've got now--

 

integer listener;
integer channel = 0;
string msg = "play";


default
{
    state_entry()
    {
        key owner = llGetOwner();
        listener = llListen(channel, "", owner, "");
        llRequestPermissions(owner, PERMISSION_TRIGGER_ANIMATION);
    }
    run_time_permissions(integer perm)
    {
        if (perm & PERMISSION_TRIGGER_ANIMATION)
        {
            llStartAnimation("wolf_bark"); }
    }

listen(integer channel, string name, key owner, string message)

{
    
    llSetSoundQueueing(TRUE);
            llPlaySound(llGetInventoryName(INVENTORY_SOUND,llRound(llFrand(llGetInventoryNumber(INVENTORY_SOUND) - 1))),1.0);


}
 }

Link to comment
Share on other sites

oh! a typer, they are cool

in this case delete 'string msg = "play" bcause is not needed

then in the listen event add a llStartAnimation to play the wolf_bark animation

to be clean there should be a permissions condition check in the listen event before you attempt to llStartAnimation

http://wiki.secondlife.com/wiki/LlGetPermissions

if (llGetPermissions() & PERMISSION_TRIGGER_ANIMATION) ... start animation

  • Like 1
Link to comment
Share on other sites

9 minutes ago, Fluffy Sharkfin said:

Just tested it in-world and for me it requests permissions as soon as the script is saved/compiled.

I decided to "remake" it as a new script and it did the same for me.

It played the animation immediately though, not on chat. I think I've got a bit of switching around to do with this..

Link to comment
Share on other sites

3 minutes ago, Dragon Hijinks said:

It played the animation immediately though, not on chat. I think I've got a bit of switching around to do with this..

It's playing the animation as soon as the permissions are granted because the llStartAnimation command is located in the run_time_permissions event, which is triggered when permissions are granted to the script.  Moving the llStartAnimation command to the listen event will work fine. 

As I pointed out above, PERMISSION_TRIGGER_ANIMATION is granted automatically upon request if the script is running in an attachment, so you don't technically need to check that they've been granted using llGetPermissions, but it's still good practice to do so.

If you're using this script in an attachment then I'd recommend using the attach event rather than state_entry, since it's triggered every time the object is attached rather than only when the script is compiled.

Link to comment
Share on other sites

3 minutes ago, Dragon Hijinks said:

Right so I think I need something in 

 if (perm & PERMISSION_TRIGGER_ANIMATION)
        {
            llStartAnimation("wolf_bark"); }
    }

to make sure the animation only triggers after the owner's chat has been detected on Channel 0. So it would be &...what? 

 

I'd suggest something like this, which will play the animation if the script has the appropriate permissions, and if not will re-request them.

integer perm = llGetPermissions();
if(perm & PERMISSION_TRIGGER_ANIMATION) {
    llStartAnimation("wolf_bark");
} else {
    llRequestPermissions(owner, PERMISSION_TRIGGER_ANIMATION);
}

 

Link to comment
Share on other sites

One more syntax error and maybe I've got this. Thanks so much for your patience. The way code is laid out makes is really hard for me to tell where brackets begin and end. ^^;

 

integer listener;
integer channel = 0;


default
{
    attach(key id)
    {
       integer perm = llGetPermissions();
        key owner = llGetOwner();
        listener = llListen(channel, "", owner, "");
        llRequestPermissions(owner, PERMISSION_TRIGGER_ANIMATION);
    }

listen(integer channel, string name, key owner, string message)
 
   {
       if(perm & PERMISSION_TRIGGER_ANIMATION) {
    llStartAnimation("wolf_bark");
} else {
    llRequestPermissions(owner, PERMISSION_TRIGGER_ANIMATION);

{
    
    llSetSoundQueueing(TRUE);
            llPlaySound(llGetInventoryName(INVENTORY_SOUND,llRound(llFrand(llGetInventoryNumber(INVENTORY_SOUND) - 1))),1.0); }

}
 

Link to comment
Share on other sites

1 minute ago, Dragon Hijinks said:

One more syntax error and maybe I've got this. Thanks so much for your patience. The way code is laid out makes is really hard for me to tell where brackets begin and end. ^^;

That's why properly formatting your code is a habit well worth getting into.

integer listener;
integer channel = 0;

default
{
    attach(key id)
    {
        key owner = llGetOwner();
        listener = llListen(channel, "", owner, "");
        llRequestPermissions(owner, PERMISSION_TRIGGER_ANIMATION);
    }

    listen(integer channel, string name, key owner, string message)
    {
        integer perm = llGetPermissions();
        if(perm & PERMISSION_TRIGGER_ANIMATION) {
            llStartAnimation("wolf_bark");
        } else {
            llRequestPermissions(owner, PERMISSION_TRIGGER_ANIMATION);
        } 
        llSetSoundQueueing(TRUE);
        llPlaySound(llGetInventoryName(INVENTORY_SOUND,llRound(llFrand(llGetInventoryNumber(INVENTORY_SOUND) - 1))),1.0); 
    }
}

You had a couple of additional { } around the llSetSoundQueueing and llPlaySound commands, also you had the integer perm = llGetPermissions(); line in the wrong place, it was at the start of the attach event before you've requested any permissions whereas it should be in the listen event prior to checking the permissions using if (perm & PERMISSION_TRIGGER_ANIMATION).

  • Like 1
Link to comment
Share on other sites

  • Dragon Hijinks changed the title to Syntax check please? :') [Solved!]
You are about to reply to a thread that has been inactive for 903 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...