Jump to content

llGetSubString not working?


Altier Verwood
 Share

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

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

Recommended Posts

Hello forums, I have a simple collision detection script looking for.

    collision_start(integer hit)
    {
        //from here        
        string name = llDetectedName(0);
        if(llGetSubString(name, 0, 12) == "CG Col-Viper")
        {
        Strike_count = Strike_count+1;
        llWhisper(0,"Viper docked repairs underway");
        }
        // to here

 

And I have an object that collides with it named. 

CG Col-Viper (Mk V)

I do not understand, nothing happens, unless it is named exactly

CG Col-Viper

and have the object name exactly the name in the brackets, not the length of my substring? I'm really lost here. 

Link to comment
Share on other sites

llGetSubString() uses the "end" for the last parameter, not the "length".

So, the "13th" character is what is meant by "12" in your code.

0=first character

12=13th character

Your string only has 12 characters, so the "end" is 11.  Try using "11" instead of "12".

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

45 minutes ago, Altier Verwood said:

Geeze, I could have sworn I tried that already, it worked, wow... I guess no coding can be done after 2 AM.
thank you for the reply. 

You're welcome.

Most of us had the same exact issue at one time or another!

Hard to keep track of whether strings are 0-based or 1-based, etc. etc. etc.!

  • Thanks 1
Link to comment
Share on other sites

If you don't ~need your special string to be at the very beginning, something like

if(~llSubStringIndex(name,"CG Col-Viper")){ /*...*/ }

is less prone to indexing errors.

Even better, making things case-insensitive can often solve a few headaches:

if(~llSubStringIndex(llToLower(name),"cg col-viper")){ /*...*/ }

If you're only wanting to remove possible spaces before or after the name, check out llStringTrim

Edited by Quistess Alpha
  • Like 3
Link to comment
Share on other sites

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