Altier Verwood Posted May 25, 2022 Share Posted May 25, 2022 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 More sharing options...
Love Zhaoying Posted May 25, 2022 Share Posted May 25, 2022 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". 2 3 Link to comment Share on other sites More sharing options...
Altier Verwood Posted May 25, 2022 Author Share Posted May 25, 2022 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. 2 Link to comment Share on other sites More sharing options...
Love Zhaoying Posted May 25, 2022 Share Posted May 25, 2022 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.! 1 Link to comment Share on other sites More sharing options...
Quistess Alpha Posted May 25, 2022 Share Posted May 25, 2022 (edited) 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 May 25, 2022 by Quistess Alpha 3 Link to comment Share on other sites More sharing options...
Recommended Posts
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