Font size

TakeluSpain
10 Aug 2022, 20:18

Hello, I am a Spanish creator and I need your help. In my country, the Quest user community is very small. It is very difficult for me to understand your explanations in this forum due to the language and my inexperience. I want the player to be able to change the font size during gameplay. The player would have to enter a command followed by a number which would be the font size. The command does not exist in Spanish and I would have to do it from scratch. Could you help me? Thank you very much!!! I need the explanation to be easy to understand...
I know how create a command to change the font size, but not to a size input by the player.


TakeluSpain
11 Aug 2022, 06:33

I have use the function get input and after setfontsize expression result, but the Quest program crashes.


Pertex
11 Aug 2022, 09:38

Quest crashes? Quest is completely terminated or an error message is displayed?


TakeluSpain
11 Aug 2022, 10:45

The game and program were frozen, no error message


Pertex
11 Aug 2022, 14:00

Could you post your code of the get input?


TakeluSpain
12 Aug 2022, 04:57
<command name="CAMBIO DE TAMAÑO DE FUENTE">
    <pattern>TAMAÑO DE FUENTE</pattern>
    <script>
      msg ("Introduce el valor del tamaño de fuente que quieras:")
      get input {
        SetFontSize (result)
      }
    </script>
  </command>

After I input de size of the font I have the problem, because when I write other thing like "look" or "inventory" the program was frozen and go out.


mrangel
12 Aug 2022, 08:28

The argument to SetFontSize has to be an int. Your result is a string.

It should be something like:

<command name="CAMBIO DE TAMAÑO DE FUENTE">
    <pattern>TAMAÑO DE FUENTE</pattern>
    <script>
      msg ("Introduce el valor del tamaño de fuente que quieras:")
      get input {
        if (IsInt (result)) {
          SetFontSize (ToInt (result))
        }
        else {
          msg ("That isn't a number")
        }
      }
    </script>
  </command>

TakeluSpain
12 Aug 2022, 13:40

It works!!!
Thank you very much mrangel!!
I didn't know that this program discriminates between numbers and text


mrangel
12 Aug 2022, 15:03

It seems to depend on the source of the function.

  • For stuff that is implemented using Javascript behind the scenes, it will convert it automatically to the type it needs. (I actually expected this to be the case with SetFontSize, because most of the style/appearance stuff is javascript).
  • Quest functions (both ones you create yourself, and ones that are included in the core libraries) don't check types. But if it isn't right, the code inside the function might trigger an error.
  • Built-in functions always check types, and may generate errors when it makes no sense. For example, the expression ToInt (ListItem (somelist, 4)) will cause an error even if the 4th item of somelist is a string – because ToInt only accepts strings, and ListItem isn't guaranteed to return a string (it returns whatever type of data is in the list).