Jump to content

Full song walker gives error


Tattooshop
 Share

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

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

Recommended Posts

Hello! This is a full song walker script. It gives an error   "Could not find sound ''."    always while playing the last file. What could be the reason?

integer cmd_channel = -770325;
float soundVolume = 1.0;
float soundLength = 10.0;

integer gIndex = 0;
integer HUD_ATTACHED = 0;
list listWalkSounds = [];

PlayWalkSound()
{
    llSetTimerEvent(soundLength);

    if (HUD_ATTACHED) llTriggerSound(llList2Key(listWalkSounds, gIndex), soundVolume);
    else llPlaySound(llList2Key(listWalkSounds, gIndex), soundVolume);

    if ((gIndex = gIndex + 1) >= llGetListLength(listWalkSounds)) gIndex = 0;
    llPreloadSound(llList2Key(listWalkSounds, gIndex));
}

adding_files()
{
    integer iNumber;
    integer iCount = llGetInventoryNumber(INVENTORY_SOUND);
    string iName;
    while (iNumber <= iCount)
    {
        iName = llGetInventoryName(INVENTORY_SOUND, iNumber);
        listWalkSounds += iName;
        ++iNumber;
    }
}

StopWalkSound()
{
    llSetTimerEvent(0);
    llStopSound();
}

default
{
    state_entry()
    {
        if (llGetAttached()) llOwnerSay("detach and attach me again.");
        else llOwnerSay("I need to be attached in order to work.");
    }
    attach(key id)
    {
        if (id != NULL_KEY)
        {
            integer att = llGetAttached();

            if (att > 30 && att < 39) HUD_ATTACHED = 1;
            else HUD_ATTACHED = 0;
            adding_files();
            llRequestPermissions(id, PERMISSION_TAKE_CONTROLS);
            llOwnerSay("/me is ready.");
        }
    }

    run_time_permissions(integer perm)
    {
        if (perm & PERMISSION_TAKE_CONTROLS)
        {
            llTakeControls(CONTROL_FWD | CONTROL_BACK, 1, 1);
            llPreloadSound(llList2Key(listWalkSounds, gIndex));
        }
    }

    control(key id, integer level, integer edge)
    {
        if (llGetAgentInfo(id) & AGENT_IN_AIR) return;
        else if (level & edge) PlayWalkSound();
        else if (~level & edge) StopWalkSound();
    }

    timer()
    {
        PlayWalkSound();
    }

    changed(integer mask)
    {
        if (mask & CHANGED_OWNER) gIndex = 0;
    }
}

 

Link to comment
Share on other sites

Not properly woken up yet, but I think that the while test in the function adding_files is the culprit. The variable iNumber should loop through zero to one less than the number of files. If there are, say, five sound files, they are indexed 0 to 4. So the while test should read 

while (iNumber < iCount)

By testing for less than or equal to (<=)  the loop also executes when iNumber is equal to 5. There is no sound file with the index 5, so you add an empty item when you try to add that to your list.

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

1 hour ago, KT Kingsley said:

Not properly woken up yet, but I think that the while test in the function adding_files is the culprit. The variable iNumber should loop through zero to one less than the number of files. If there are, say, five sound files, they are indexed 0 to 4. So the while test should read 


while (iNumber < iCount)

By testing for less than or equal to (<=)  the loop also executes when iNumber is equal to 5. There is no sound file with the index 5, so you add an empty item when you try to add that to your list.

Thank you so very much! You are a genius! Everything works fine now! :)

 

  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1413 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...