Printing using random fonts?

Hiya,

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.

Hello.

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.

Enable 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!")

wow. impressive.


K.V.

It is impressive, Cheese! (You don't mind if I call you "Cheese"; do you?)

Keep those ideas coming!


Wow 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!


One 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.

Each 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
}

Oh the joy of it all!
Thanks K.V. you're my hero!


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

Support

Forums