Can I add a Script in the middle of the text body?

If this question sounds odd, I apologize.

I have a partial answer, but, I am not certain how to follow it (it involves flags).

Essentially, I am looking for a way to add some flexibility in the game. For instance, if the player answers "cat" to the question of "What’s your favourite animal?", that at some point in the game, for instance, going to a pet store, the game adds something like "You are looking in the cat toys for the kittens."


I think what you're looking for is the text processor. Text processor directives get executed by the msg() command which sends text to the user.

In this case, if you've set a flag called likescats, then you could do something like:

You walk into the pet store. {if likescats:This would be a good place to get some treats for your kittens.}

(That's assuming that the flag is saved as an attribute of the game element. For any other object, you'd have to specify the object name too. For example, player.likescats)

If when you asked the player their favourite animal, you stored the result in a string attribute, you might end up writing something like this:

You walk into the pet store. {if player.favanimal=cat:You could get some treats for your kittens.}{if player.favanimal=dog:Some other line for if they picked a dog.}

And so on.

That's not actually running a script, but it does allow you to pick different bits of text based on a flag or other attribute. You can use this text in descriptions and just about anywhere else that prints a message to the screen (but not in TextFX, I think).


Mmm’kay. Thanks for the reply. I am new to Quest's coding environment, and I thought that I needed to use a Script. I am going to give this solution a try.


There are some things that can only be done with scripting, but most of them can be replicated using the text processor.

If you want to do something that the TP doesn't seem to be capable of, there are two main ways to go about it:

  1. Replace your text with a script. Use msg ("Whatever text you want to display.") for the static bits, and then you can use whatever code you want to generate the bits that vary.
  2. Put your script in a function, and make that function return a string. Then you can call it within a text section by doing {=FunctionName()}. Its return value will be included in the text.

The nice thing about programming...
9 people can give you 12 ways to do something...
and you will end up using #13...
(And... all 13 ways will still do the same thing.)


Out of curiosity, I am working on a Gamebook. Is the procedure the same for setting a flag?


Out of curiosity, I am working on a Gamebook. Is the procedure the same for setting a flag?

Yes, it is.

There are some TP functions that only work in TA or Gamebook mode, but you can safely import the libraries for them as long as you do nothing invalid with them (like trying to use an exit in gamebook mode). This way you can use popups, for example.


Ok. Thanks.


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

Support

Forums