Community

SCI Programming => SCI Syntax Help => Topic started by: troflip on July 04, 2016, 02:47:14 AM

Title: More text parser tricks
Post by: troflip on July 04, 2016, 02:47:14 AM
I always though the '>' operator indicated sequence, basically sticking together two separate Said strings, so that you could do

Code: [Select]
(if (Said 'look>')
    (if (Said '/tree')
        (Print "The tree is great.")
    )
    ; ... more things to look at, and I don't need to repeat 'look' everywhere
)

But the second Said above is actually run in parallel with the first. So you can actually do the opposite too:

Code: [Select]
(if (Said '/tree>')
    (if (Said 'look')
        (Print "tree is great")
    )
    ; .... more actions on the tree
)

Basically, each / splits a part of the phrase. So the code above says if "tree" is the second part and "look" is the first part. The order of the Said statements doesn't matter.

You can have up to 3 parts to a phrase of course, so you could do the following:

Code: [Select]
(if (Said '//tree>')
(if (Said 'look>')
(if (Said '/bird')
(Print "It's giving you the bird.")
)
)
)

That will respond to things like "look at the bird in tree", since we have:
- 3rd part is tree
- 1st part is look
- 2nd part is bird

Likewise, you can leave these blank if you want anything to match. This example was from poking around in the LSL3 decompile (which is how I discovered this). They have something like this:

Code: [Select]
(if (or (Said '/tv') (Said '//tv'))
    (if (Said ('watch'))
        ; this matches "watch tv", but also "watch something on tv"
    )
)

I had some things in my game that I wanted you to be able to burn, and I want the user to be able to type "burn blah", or "put blah in fire". So now I can do:

Code: [Select]
(if (or (Said 'burn>') (Said 'put//fire>'))
    (if (Said '/blah')
        ; put the blah in the fire
    )
    (if (Said '/child')
        ; put the child in the fire, etc...
    )
)
Title: Re: More text parser tricks
Post by: gumby on July 04, 2016, 07:44:32 AM
I didn't know you could omit the match-any character.  In your example '//tree>', I would have written it as '*/*/tree>'.  Never considered writing the logic in the order you pointed out here, good to know that it's at least an option.
Title: Re: More text parser tricks
Post by: troflip on July 04, 2016, 01:22:28 PM
Just came across your text parser wiki entry, Gumby (don't know why I hadn't seen this before - probably because it's not accessible from the list of tutorials?). Nice stuff!

For anyone who's watching:
http://sciprogramming.com/tutorial.php?entry=5465
Title: Re: More text parser tricks
Post by: Collector on July 04, 2016, 07:28:29 PM
Just came across your text parser wiki entry, Gumby (don't know why I hadn't seen this before - probably because it's not accessible from the list of tutorials?). Nice stuff!

For anyone who's watching:
http://sciprogramming.com/tutorial.php?entry=5465
That can easily be included with adding a

Code: [Select]
[[Category:Tutorials]]
at the bottom of the page.