Text Processor

Is it possible to call a function or template when using the text processor for room descriptions?

I know I could use a script for complex descriptions but this in itself seems to mess things up if any objects have inroomdescriptions.

Thanks.

Edit:

Or failing the above can and/or conditions be use in the text processor?


Or failing the above can and/or conditions be use in the text processor?

The condition for {if in the text processor is a special case, and kind of weird in the way it works. It supports not, but only for some operators.

The condition for {either is a Quest expression - anything you could put in an expression for a regular if statement in a script. That means you can use and and or however you want :)

Is it possible to call a function or template when using the text processor for room descriptions?

Yes. {=NameOfFunction()} will include the output of a function in the text.

If you want to run a function that doesn't generate any output, I think it needs a return type (not 100% sure about this). If so, just change its type to 'string' and add a line return ("") at the end of the function. Then it can easily be called from within a description.

Note that in the case of functions which modify a value when they're called, this may only be run when the text is sent to the browser. So the description with the text processor commands in it could have in-room descriptions added to the end, and "You can see:" lists, before ProcessText is called to replace all text processor commands with their results. So if, for example, your function moves an object out of the room, that object's in-room description will still be shown.


Brilliant. Both the function and the either options work for me. Thanks.
I've looked at the text processor help page a gazillion times and both options didn't click. Thanks again.


If you want to run a function that doesn't generate any output, I think it needs a return type (not 100% sure about this). If so, just change its type to 'string' and add a line return ("") at the end of the function. Then it can easily be called from within a description.

Regarding this, and in general when using functions that don't generate output but need a return type. Setting as a string and using return ("") works, but generates an additional blank line in the output (as expected), is there any way of stopping this?
Thanks in advance.


I'm not sure why there would be an additional blank line. The text processor command will be replaced by its output, so returning "" should remove it entirely.

If you put the command on a line of its own, it still has line breaks before and after it. But you can put it at the end of an existing line so there's no need for an extra line break. Makes the code a little harder to read, but it should work fine.


Sorry, I should have been clearer (maybe should have been a separate topic). This is not text processor related. I have situation where a verb calls a function that may then call another command. There probably is an easier way of doing this.

So the main command is burn object with object. I have a verb burn object. The verb calls a function, passing the object.

In the function I have a few checks which may fail and return a message, exiting the function. If the checks pass the function then calls the main command using do (BurningWith, "script", tempdir), where tempdir is a dictionary with two objects. The main command does what it needs outputting the correct messages.

I'm guessing what happens now it that the command finishes, returns to the calling function which then returns ("") It is at this point I get the extra blank line.

Hope that makes sense. It's not really a major issue, I know it happens and have a hacky workaround. Thanks.


Returning an empty string will not output anything. If you're getting a blank line, there must be a msg or equivalent in there to output it.

If the function is returning a message to explain why it failed, you'd just wrap it up in:

message = SomeFunction (this)
if (not message = "") {
  msg (message)
}

So the message is only printed if there is one.


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums