Non-threaded

Forums » Advanced Editor Forum » Read Thread

Get help from the experts on variables, scripts, items, and other scary things.

Change Default Font Size Depending On Variable

2 years ago
Okay. So essentially I want to give the player the ability to change the font size of the game in the "Settings" menu/page. I was trying to use the tags in the Global Page script in conjunction with the %FONT variable (which is the variable players can change using the links on the Settings page), but the links don't seem to be changing the font size at all, regardless of what the value of the %FONT variable is. All I want is to set it up so that the default font size of the text changes to match the value of the %FONT variable whenever the player changes that variable via the Settings menu. Is this even possible, or am I missing something? Thanks in advance!

Change Default Font Size Depending On Variable

2 years ago
What exactly did you have in the global script? I don't see anything related to fonts there now.

Change Default Font Size Depending On Variable

2 years ago
That's because I deleted it to clean up the area (I try to keep not functioning scripts out of the game until it works, to isolate problems)

What I had was something like this (brackets being replaced with <> of course):

$PAGETEXT := "[style] {font-size = %FONT} [/style]" + $PAGETEXT

I'm very rusty in my HTML so this is all I could think of, but instead of changing the font size, it displays the HTML code itself at the top of the page.

Change Default Font Size Depending On Variable

2 years ago
If that's exactly what you had, you're missing the specifier.

In other words, inside the style tag, the first think you need is what you're applying the style to. You'd need something like a p between the style tag and the squiggly bracket.

Change Default Font Size Depending On Variable

2 years ago
Got it! Lemme try that!

Change Default Font Size Depending On Variable

2 years ago
Also, they may want to keep in mind that most browsers already let you change the size of any text you're reading.

Change Default Font Size Depending On Variable

2 years ago
True, true. It's still a good thing to know though, for other projects in other engines/sites.

Change Default Font Size Depending On Variable

2 years ago
Alright I specified the body of the document to be affected by the font size change.

This is what I have now:

$PAGETEXT := "[style]body{font size: '%FONT';}[/style]" + $PAGETEXT

But it's still not working. What else am I missing?

Change Default Font Size Depending On Variable

2 years ago
Spaces are nice.

Font Size is not a legal category. Every one of those is required to NOT have spaces. So font-size is legal, but font size is not.

Also, are you seeing this rendered on the page? It should be, but one way to help troubleshoot issues like this is to view the source of the pages so you can see exactly what the engine has interpreted.

Change Default Font Size Depending On Variable

2 years ago
Got it lol, lemme try fixing that

Change Default Font Size Depending On Variable

2 years ago
Okay, added the hyphen and cleaned up the script. It now looks something like this:

$PAGETEXT := "[style] body {font-size: '%FONT';} [/style]" + $PAGETEXT

I have it so that the FONT variable is displayed, and that changes just fine, but the actual size of the font on the page still doesn't change... am I missing some more spaces or is there something else going on here? Reminder that all of this is in the Global Page Script.

Edit: Tried adding the font-size to my other body setting for the background. Now the entire GP script looks like this:

$PAGETEXT := "[center]" + $PAGETEXT + "[/center]"
## Centers the body text

$PAGETEXT := "[style]
ul {
list-style-type: none;
padding: 0;
text-align: center;
}
[/style]" + $PAGETEXT
## Deletes the bullet points and centers the links

$PAGETEXT := "[style]
body {
background: url('https://chooseyourstory.com/resources/images/user/58838?58838') center/cover fixed;
font-size: '%FONT';
}
[/style]" + $PAGETEXT
## Sets the background image and changes the font size depending on the variable

Does this help figure out the problem? All of these scripts work perfectly like this EXCEPT the change font size one.

Change Default Font Size Depending On Variable

2 years ago
Does all that show up on the page rendered when you view the source? (I'm trying to remember the order of processing and the answer to that will tell me if it works)

Change Default Font Size Depending On Variable

2 years ago
I was wondering if all these different $PAGETEXTS might be overriding each other too.

Change Default Font Size Depending On Variable

2 years ago
As long as there's a + $PAGETEXT in every one, it should be adding to it

Change Default Font Size Depending On Variable

2 years ago
The script shows up in the source, yes, but isn't... colored like the other scripts. The beginning and ending style tags are colored, but the script in between in plain black text... I said I was rusty in my HTML, and by that I mean I'm a Novice so I can't even begin to tell what's going on in the source.

I edited the code a little to group everything together neatly, and everything still works as intended except for the font size script. I thought the initial problem was that I had my FONT variable set too high (apparently the limit is 3 to 7) so I changed the min and max to fit within this and edited the links so that the value of the variable never went outside those parameters. But it still doesn't work! Here's what I have now, all cleaned up and neatly divided:

$PAGETEXT := "[style]
ul {
list-style-type: none;
padding: 0;
text-align: center;
}
body {
background: url('https://chooseyourstory.com/resources/images/user/58838?58838') center/cover fixed;
font-size: '%FONT';
} [/style]" + "[center]" + $PAGETEXT × "[/center]"

Everything works perfectly EXCEPT the font size script, and again, this script shows up as plain black text in the source code.

Change Default Font Size Depending On Variable

2 years ago
Can you see the value of FONT in the source when you view the source of the final page where it doesn't work?

In other words, when you read the story and you're looking at the actual page where it doesn't work, when you view the source of that page, does it actually show "font-size: '3';" ?

Change Default Font Size Depending On Variable

2 years ago
Just checked and no it doesn't translate the variable. It just says "{font-size: '%FONT';}" instead. So at least we know the problem is with the variable not working properly in that sense. Is there a way to fix it?

Change Default Font Size Depending On Variable

2 years ago
That's what I suspected.

No, you cannot fix that because of the order the variables are translated. Well, you can fix it, but not with a simple fix.

You can, if you really, really want to, use a bunch of IF statements like:

IF %FONT = 3 THEN
(insert stuff about setting font-size to 3)
If %FONT = 4 THEN
(insert set about setting font-size to 4)

and so on

Change Default Font Size Depending On Variable

2 years ago
That's what I was afraid of. Eh, it's only 5 numbers, I fan plug that in easily, and remove the entire feature later if I change my mind. Thanks for the help, everyone!

Change Default Font Size Depending On Variable

2 years ago
Good luck with it!

Change Default Font Size Depending On Variable

2 years ago
If that's the, then it might work to use the more tedious method of something like,

IF %FONT = 3
THEN
[your html manually setting the font size to 3] + $PAGETEXT

And so on for the other sizes it can be set to.

....I personally would've passed the point much earlier where I just decided letting font sizes be changed wasn't that important after all, but I suppose if you've made it this far it's worth continuing on for science.

Edit: whoops, too slow

Change Default Font Size Depending On Variable

2 years ago
Yeah that's what I did... or tried to do anyway, by which I mean I finally gave up and scrapped the concept. Was still a good experiment though and got me more experience with the scripting, so there's that at least.

I swear if Bradin finds a way to pull this off like the madlad scripting God he is, Imma be so done! XD

Change Default Font Size Depending On Variable

2 years ago

Yeah, it all boils down to that not quite being the way variables are interpolated. All you need to do is split the string there and splice the variable in. Just change that line to:

font-size: " + %FONT + ";

Change Default Font Size Depending On Variable

2 years ago
Oh okay got it! Thanks!