Author Topic: More text parser tricks  (Read 7452 times)

0 Members and 1 Guest are viewing this topic.

Offline troflip

More text parser tricks
« 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...
    )
)


Check out my website: http://icefallgames.com
Groundhog Day Competition

Offline gumby

Re: More text parser tricks
« Reply #1 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.
In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition

Offline troflip

Re: More text parser tricks
« Reply #2 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
« Last Edit: July 04, 2016, 01:59:25 PM by troflip »
Check out my website: http://icefallgames.com
Groundhog Day Competition

Offline Collector

Re: More text parser tricks
« Reply #3 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.
KQII Remake Pic


SMF 2.0.19 | SMF © 2021, Simple Machines
Simple Audio Video Embedder

Page created in 0.031 seconds with 18 queries.