Capitalization, or lack thereof

The wiki lists two ways to capitalize text variable values. Is there a way to do the reverse? An equivalent to JavaScript’s String.toLowerCase() method? I realize this is a needlessly specific use case, but I’m going to get Remarks and also Comments if I fail to capitalize courtesy titles correctly.

If there’s no programmatic way to do it, I may be reduced to changing the original value, and then scanning my game files for every other use of that variable, to apply $!{}. I’d like to avoid that, naturally.

1 Like

Unfortunately, I think your only option is to write a chunk of code that iterates through the word(s) you want cast to lowercase and manually rebuild them one letter at a time. I might actually write up a function that does this on my break just for giggles.

You could just create a second variable with lowercase variants of whatever word is in the first one.

2 Likes

You could just ignore said Rs and Cs. (He said, from experience.) :smile:

3 Likes

Boom:

*label str_to_lower

*params in_str

*temp out_str ""

*temp len length(in_str)
*temp idx 1
*temp curr ""

*label s2l_loop

*set curr in_str#idx
*gosub get_lower curr
*set out_str &return
*set idx +1

*if (idx <= len)
    *goto s2l_loop

*set return out_str
*return

*label get_lower

*params char

*if (char = "A")
    *set return "a"
    *return
*if (char = "B")
    *set return "b"
    *return
*if (char = "C")
    *set return "c"
    *return
*if (char = "D")
    *set return "d"
    *return
*if (char = "E")
    *set return "e"
    *return

*if (char = "F")
    *set return "f"
    *return
*if (char = "G")
    *set return "g"
    *return
*if (char = "H")
    *set return "h"
    *return
*if (char = "I")
    *set return "i"
    *return
*if (char = "J")
    *set return "j"
    *return
*if (char = "K")
    *set return "k"
    *return
*if (char = "L")
    *set return "l"
    *return
*if (char = "M")
    *set return "m"
    *return
*if (char = "N")
    *set return "n"
    *return
*if (char = "O")
    *set return "o"
    *return

*if (char = "P")
    *set return "p"
    *return
*if (char = "Q")
    *set return "q"
    *return
*if (char = "R")
    *set return "r"
    *return
*if (char = "S")
    *set return "s"
    *return
*if (char = "T")
    *set return "t"
    *return
*if (char = "U")
    *set return "u"
    *return
*if (char = "V")
    *set return "v"
    *return
*if (char = "W")
    *set return "w"
    *return
*if (char = "X")
    *set return "x"
    *return
*if (char = "Y")
    *set return "y"
    *return

*if (char = "Z")
    *set return "z"
    *return

*set return char
*return

Usage:

*create return ""

*temp string "Hello World!"

*gosub str_to_lower string
*comment : Should show "hello world!"
${return}
2 Likes

I remember reading on a thread that it’s possible to modify CS files to add a feature like this. Someone added $!!! and $!!!! (uncapitalize first letter and uncapitalize all letters respectively).

However, the solution above by @stainedofmind pretty much already covers it.

I searched around a bit but I can’t find the post unfortunately.

1 Like

Games with modified Javascript files can’t be submitted as a HG.

Ah, unfortunately it’s as I thought. But again, it’s a rather esoteric need that I can get around. Especially if I plan my variables and values more carefully in the future.

What I would do is just bite the bullet and open all the text files in notepad++. That has a global search/replace function that you can use to replace all instances in all files. You’ll have to do the variables one at a time, of course, but it’ll save a lot of messing about as your scripts grow to sizes that become a chore to edit! That way, you avoid having to change the javascript which is always a bit of a can of worms.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.