Hello,i try to create a gamebook and i’m curious is it possible to randomize text in it.As example i have something like that in the beginning:You are in a dark forest,Its warm, sunny and you hear birds around you.
And now everytime when i start a game i want some text randomization like:You are in a dark forest,day is cold and rainy(instead of warm,sunny)
Is this possible and how i can do that?
I hope that you understand what i mean:)
You could store each possibility in a text file like:
<Option1 texte="You are in a dark forest,Its warm, sunny" />
<Option2 texte="You are in a dark forest,day is cold and rainy" />
And simply, create a random number using the Random() expression like so:
Do=Random(1) + 1 to Variable(random_number)
In this case it is Random(1) + 1 because we need 1 or 2 but Random(1) also may return 0 so we add 1 to avoid that…
And then, by using this variable, you can read the random text from the file in to a scene variable using the storage actions like so:
Read "Option" + ToString(Variable(random_number)) from file "filename.txt" and store as text in VariableString(random_text)
Finally, you can use this variable to update the text object to display the text:
Do= VariableString(random_text) to the text of textobject
In case you want to pick only random words, you can do the same way, but when you update the text object you need to use variables in place of the random words and parts:
Do = "You are in a dark forest, " + VariableString(random_text) to the text of textobject
It still depends on how you design your game.
Is it a game with pages like a paper book, or is it like a generic interactive novel, or is it a mud which may have tons of choices?
Put text bits in other files isn’t really a comfortable choice unless you also put all your stories in external files as well, because you’ll need to read both to have a clue when the game grows bigger and bigger, and it is distracting. You’ll end up writing your own script loader which is not an easy task if you are not a coder.
There are probably better tools for this genre than GD if your search for visual novel via google. If you want to try GD anyway, maybe you can try to utilize its GUI, create a layer for your scene, put your text objects in that layer, other than loading them from a file. This way, you can at least visualize the logic part of your game.