Printing using random fonts?

CheeseMyBaby
28 Mar 2018, 12:57Hiya,
Is there a way of randomizing which fonts text from a message will be printed in?
Super quick example:
If I want
THIS TEXT
... to have different fonts i've used < font face> tags like so
<font face=arial>THIS</font> <font face=garamond>TEXT</font>
. But now I need to apply it to a large piece of text and would love to not have to do that to every single word.
I'd very much love if I could randomize all the webfonts when printing a message.
Is it possible or am I just being stupid?
(both arguments may apply)

K.V.
28 Mar 2018, 23:58Hello.
Are you sure you want to randomize ALL the web fonts?
Either way, I strongly advise pre-loading any web fonts you plan to use. Otherwise, I think each font would have to download when you switched to it the first time, which would make game-play seem buggy.
(Code coming (very) soon!)

K.V.
29 Mar 2018, 00:23Enable the advance scripts feature in your game (if you haven't already done so).
In "User Interface Initialisation", add this:
// Edit this list to include/exclude any font from fonts.google.com.
// Mind your capitalization and spacing!!!
game.webfonts = Split("Chicle;Indie Flower;Anton;Lobster;Press Start 2P")
foreach (font, game.webfonts) {
SetWebFontName (font)
}
// Assuming your initial font is the default font, and not a web font. If not, change the next line.
SetFontName (game.defaultfont)
// If your initial font is a web font, and you set it up in the editor (or before this script), uncomment the next line.
//SetWebFontName(game.defaultwebfont)
This needs to be in the User Interface Initialisation script because this will load your fonts any time the game is loaded, whether it is a saved game or a new game.
If you were to put this script anywhere else (like the start script), the fonts would not preload when loading a saved game.
Add this function to your game in full code view:
<function name="RandomFontMsg" parameters="txt"><![CDATA[
textarray = Split(txt, " ")
foreach (s, textarray) {
OutputTextNoBr ("<span style='font-family:" + PickOneString (game.webfonts) + ";'>" + s + " </span>")
}
]]></function>
The function will split the text you feed it at each space, and print each item from the list with a random font, which is selected from game.webfonts
(from your User Interface Initialisation script).
To use it:
RandomFontMsg ("No! I am your father!")

XanMag
29 Mar 2018, 00:58wow. impressive.

K.V.
29 Mar 2018, 02:57It is impressive, Cheese! (You don't mind if I call you "Cheese"; do you?)
Keep those ideas coming!

CheeseMyBaby
29 Mar 2018, 11:31Wow indeed. You just saved me an incredible amount of time!
And yes, I'd prefer "Cheese" over "my baby" any day heehee.
This was very helpful.
(I'm really struggling with getting into the syntax thinking and I've noticed I learn the most when in scenarios like this when I know beforehand what the code actually do)
Thanks a lot!

CheeseMyBaby
29 Mar 2018, 12:25One more question;
I've set up a notebook in which my main character has his contacts, password hints, lists of great cheese etc and other important things. Doing this I've used your booklib K.V. (thanks again for that!)
But how do I use the random fonts in one of those books?

K.V.
29 Mar 2018, 15:29Each page in a book has this script for 'read':
if ((this.parent = game.pov) or this.parent.parent = game.pov) {
msg (this.pagetext)
if (HasAttribute(this,"nextpage")) {
msg ("{command:read "+GetDisplayAlias(this.nextpage)+":Next Page}")
}
}
else {
msg ("You have to be holding something to read it.")
}
I think you can just change it to:
if ((this.parent = game.pov) or this.parent.parent = game.pov) {
RandomFontMsg (this.pagetext)
if (HasAttribute(this,"nextpage")) {
msg ("{command:read "+GetDisplayAlias(this.nextpage)+":Next Page}")
}
}
else {
msg ("You have to be holding something to read it.")
}
That would need to be done to each page in the book.
If the book has numerous pages, you could add an initialisation script to the book:
newscript => {
if ((this.parent = game.pov) or this.parent.parent = game.pov) {
RandomFontMsg (this.pagetext)
if (HasAttribute(this,"nextpage")) {
msg ("{command:read "+GetDisplayAlias(this.nextpage)+":Next Page}")
}
}
else {
msg ("You have to be holding something to read it.")
}
}
foreach (o, GetDirectChildren(this)){
this.read = newscript
}

CheeseMyBaby
29 Mar 2018, 19:30Oh the joy of it all!
Thanks K.V. you're my hero!