Changing font depending on a certain string selected

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
TheAgaures
Posts: 31
Joined: Mon Aug 16, 2021 9:34 am

Changing font depending on a certain string selected

Post by TheAgaures »

Hello !

Currently, i'm facing a major problem that I wasn't able to solve for quite a while now.
Here's the problem:

Code: Select all

script "talking" (void)
{
   str Quotes[4];
   Quotes[0] = "Quote 1."; // SMALLFONT
   Quotes[1] = "Quote 2 !"; // SMALLFONT
   Quotes[2] = "Quote... 3 ?"; // SMALLFONT
   Quotes[3] = "QUOTE 4 !"; // BIGFONT
   Delay(35);
   SetFont("SMALLFONT"); << I wanna change the font depending on the quote said
   HudMessageBold(s:Quotes[random(0, 3)]; HUDMSG_TYPEON|HUDMSG_LOG, 0, CR_WHITE, 200.0, 500.0, 3.0, 0.01, 0.2);
}


I tried a lot of ideas to get something to work, but for some reasons I can't find a solution at all.
Maybe I didn't do the script right, or i'm not seeing something obvious, but i'm still lost.
Thank you very much if you can help me out with this !
User avatar
Blue Shadow
Posts: 4901
Joined: Sun Nov 14, 2010 12:59 am
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: ATI/AMD (Modern GZDoom)

Re: Changing font depending on a certain string selected

Post by Blue Shadow »

One way to approach that is to use multi-dimenstion arrays, so you can associate each quote string with a font:

Code: Select all

script "talking" (void)
{
    str Quotes[4][2] =
    {
        { "Quote 1.",     "SMALLFONT" },
        { "Quote 2 !",    "SMALLFONT" },
        { "Quote... 3 ?", "SMALLFONT" },
        { "QUOTE 4 !",    "BIGFONT"   }
    };

    Delay(35);
    int pick = Random(0, 3);
    SetFont(Quotes[pick][1]);
    HudMessageBold(s:Quotes[pick][0]; HUDMSG_TYPEON|HUDMSG_LOG, 0, CR_WHITE, 200.0, 500.0, 3.0, 0.01, 0.2);
TheAgaures
Posts: 31
Joined: Mon Aug 16, 2021 9:34 am

Re: Changing font depending on a certain string selected

Post by TheAgaures »

Blue Shadow wrote:One way to approach that is to use multi-dimenstion arrays, so you can associate each quote string with a font:

Code: Select all

script "talking" (void)
{
    str Quotes[4][2] =
    {
        { "Quote 1.",     "SMALLFONT" },
        { "Quote 2 !",    "SMALLFONT" },
        { "Quote... 3 ?", "SMALLFONT" },
        { "QUOTE 4 !",    "BIGFONT"   }
    };

    Delay(35);
    int pick = Random(0, 3);
    SetFont(Quotes[pick][1]);
    HudMessageBold(s:Quotes[pick][0]; HUDMSG_TYPEON|HUDMSG_LOG, 0, CR_WHITE, 200.0, 500.0, 3.0, 0.01, 0.2);


This is absolutely what I was searching for, it works flawlessly thank you very much !

Return to “Scripting”