Author Topic: "Magic" Tokens and weird results [ toupper() ]  (Read 246 times)

Bgoulette

  • Full Member
  • ***
  • Posts: 88
    • View Profile
"Magic" Tokens and weird results [ toupper() ]
« on: January 08, 2019, 09:18:46 PM »
This is really weird.

I want certain game details returned in uppercase text. I discovered the toupper() function, but when running magic token text through a magic token function (e.g., [!getTitle]), sometimes it looks like it works, other times it returns a bunch of weird junk: an odd mixture of "magic-less" token parts and who knows what else.

Here's what I've coded:

Code: [Select]
function getTitle () { return fe.game_info(Info.Title).toupper(); }
function getMfr () { return fe.game_info(Info.Manufacturer).toupper(); }
function getPlayedTime () { return fe.game_info(Info.PlayedTime).toupper(); }
function getName () { return fe.game_info(Info.Name).toupper(); }
function getEmu () { return fe.game_info(Info.Emulator).toupper(); }

function getStatus () {
    if (fe.game_info(Info.Status).len() < 1) {
        return "";
    }
    else {
        return "; " + fe.game_info(Info.Status).toupper();
    }
}

And here's the line where I'm trying to populate my text instance:

Code: [Select]
local _gameInfo = fe.add_text("[!getTitle]\n© [Year] [!getMfr]\n[Players] PLAYER(S)\nPLAYED FOR [!getPlayedTime]\n[!getName]; [!getEmu][!getStatus]", 228, 880, 704, 136);

I tried adjusting the line breaks, adding whitespace, etc., but the fact is, it just doesn't work as-is. I'm not sure if I'm missing something or if there's a hiccup with getting the "processed" text from the magic token function(s).

If there's a simpler way to do this, I'm all ears. I tried chaining .toupper() directly to my tokenized string, but that just returned an uppercase version of the untranslated tokens. :shrug:

Here's a pic of some of the results (attached). Thanks for any help!


zpaolo11x

  • Sr. Member
  • ****
  • Posts: 282
    • View Profile
    • My deviantart page
Re: "Magic" Tokens and weird results [ toupper() ]
« Reply #1 on: January 08, 2019, 10:25:27 PM »
I'll look into this as soon as I have some time because I'm also interested in this, but as a quick and dirty solution right now I'm using an uppercase only font for my theme, so no issues with "toupper" function :D

keilmillerjr

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 759
    • View Profile
Re: "Magic" Tokens and weird results [ toupper() ]
« Reply #2 on: January 09, 2019, 02:27:57 AM »
It looks like text from multiple functions are running into each other. Share full code that produced the results?

zpaolo11x

  • Sr. Member
  • ****
  • Posts: 282
    • View Profile
    • My deviantart page
Re: "Magic" Tokens and weird results [ toupper() ]
« Reply #3 on: January 09, 2019, 03:14:50 AM »
Something fishy is going on related to "\n" character: look at this simple layout:

Code: [Select]
function getName () {
   return fe.game_info(Info.Name)
 }
function getEmulator () {
   return fe.game_info(Info.Emulator)
 }

local gameInfo = fe.add_text("\n[!getName] [!getEmulator]", 0, 0, fe.layout.width, fe.layout.height*0.5)
gameInfo.charsize = 20
gameInfo.word_wrap = true

local gameInfo2 = fe.add_text("[!getName] [!getEmulator]", 0, fe.layout.height*0.5, fe.layout.width, fe.layout.height*0.5)
gameInfo2.charsize = 20
gameInfo2.word_wrap = true

The result is missing the space when using the custom magic tokens, while it's ok otherwise.

Bgoulette

  • Full Member
  • ***
  • Posts: 88
    • View Profile
Re: "Magic" Tokens and weird results [ toupper() ]
« Reply #4 on: January 09, 2019, 03:23:08 AM »
Something fishy is going on related to "\n" character: look at this simple layout:

I thought that, too, but even ditching the newline produces weird, arbitrary-looking results for me!

Here's the layout I'm working on. It's still a wip, but it exposes everything I'm doing, in case it's me screwing up (attached). Sometimes it looked like something in the expansion just gets tired and spits back the un-magic token. Or even just a part of it. Weird! Thanks for looking!

Oomek

  • Sr. Member
  • ****
  • Posts: 258
  • Radek Dutkiewicz
    • View Profile
    • github.com/oomek
Re: "Magic" Tokens and weird results [ toupper() ]
« Reply #5 on: January 14, 2019, 07:46:17 AM »
This should do what you need I think:

Code: [Select]
function getAll() { return fe.game_info(Info.Title).toupper() + "\n(c) [Year] " +
   fe.game_info(Info.Manufacturer).toupper() + "\n[Players] PLAYER(S)\nPLAYED FOR " +
   fe.game_info(Info.PlayedTime).toupper() }

local all = fe.add_text("[!getAll]", 0, 0, w, h)