Function: string right

Creating scripts
Post Reply
User avatar
JoJo Dreamer
Posts: 11
Joined: Tue Apr 19, 2022 12:22 pm
Has thanked: 11 times
Been thanked: 8 times

Function: string right

Post by JoJo Dreamer »

Hello, anyone that could give me some help how to use the function String Right (at least i *think* that is what i should use)?

At present my NPCs listen to local chat, and for instance if i ask them about 'tours' or 'people' they give some information, like this:

else if (cmd1 == "tours")
{
osNpcSay(uNPC, "info about tours.");

else if (cmd1 == "people")
{
osNpcSay(uNPC, "info about people.");

But this only works if i ONLY ask for instance 'tours' and nothing else... Now, what id like, is to rather check if the most RIGHT written word is (in this case) 'tours', so i would get the response also if writing something like 'tell me about tours', 'give me info about tours', 'blabla bla tours'.. I'm sure you get it :)

I look here https://wiki.secondlife.com/wiki/Right but i dont understand how to implement that in the code above... any help or suggestions of other solutions is very appretiated.

Have a nice day!
Jojo
These users thanked the author JoJo Dreamer for the post (total 3):
Ilan TochnerGregg LegendaryVeritas McMaster
Graham Mills
Posts: 1314
Joined: Sun Dec 23, 2012 2:26 pm
Has thanked: 1134 times
Been thanked: 1141 times

Re: Function: string right

Post by Graham Mills »

As that's a user-created function you just include the code under Specification before the start of your default state and then call it as per the Example given, e.g.

string cmd1 = right(userinput, " ");
... your code continues

Note that it only returns the substring to the right of the first divider so isn't necessarily a complete solution to your needs. Simpler to convert input to a list and retrieve the last element (no error handling included, only spaces recognised as dividers).

Code: Select all

string right(string userinput)
{
    list words = llParseString2List(userinput, [" "], []);
    return llList2String(words, -1);
}
    
default
{
    touch_start(integer n)
    {
        string userinput = "have a nice day";
        llOwnerSay(right(userinput));
    }
}
These users thanked the author Graham Mills for the post (total 4):
Ilan TochnerJoJo DreamerGregg LegendaryVeritas McMaster
User avatar
JoJo Dreamer
Posts: 11
Joined: Tue Apr 19, 2022 12:22 pm
Has thanked: 11 times
Been thanked: 8 times

Re: Function: string right

Post by JoJo Dreamer »

Thank you Graham! I'll look into that when im back at my computer!
Post Reply