Author Topic: found a bug, anyone know a work-around?  (Read 1905 times)

sickle

  • Full Member
  • ***
  • Posts: 65
    • View Profile
found a bug, anyone know a work-around?
« on: May 20, 2020, 11:10:48 PM »
it seems as though the layout settings cant interact with magic tokens.

i want to change the type of players image displayed depending on which option is chosen from the layout settings, so I use the following code:
Code: [Select]
local players = fe.add_image("", 1126, 845, 120, 70);
local config = fe.get_config()
if ( config["design"] == "TurboGrafx-16" )
{
players.file_name="ui/turbo/P[Players].png"
}
else if ( config["design"] == "PC Engine" )
{
players.file_name="ui/engine/P[Players].png"
}
else if ( config["design"] == "Core Grafx" )
{
players.file_name="ui/core/P[Players].png"
}

I have used this exact code on different parts of the layout, and they all work perfectly. the only thing different is that I'm using the magic token [Players].  I tested this by replacing the variable path with a literal path, and it had no problems. is this a confirmed bug, and does anyone know a work-around?

beccobunsen

  • Jr. Member
  • **
  • Posts: 22
    • View Profile
Re: found a bug, anyone know a work-around?
« Reply #1 on: May 25, 2020, 11:31:09 AM »
you can try " fe.game_info(Info.Players) "

or you can mod this...

Code: [Select]
//TECNO CAB

/////////////////////////magic images/////////////////////////////////
local magic_image_settings = {
    genre = { path = "genre/", ext = ".png", mode = 0 } // modes: 0 = first match, 1 = last match, 2 = random,
    players = { path = "players/", ext = ".png" },
}


//return file_name for genre
function genre( offset) {
   local supported = {
      //filename : [ match1, match2 ]
      "action": [ "action" ],
      "adventure": [ "adventure" ],
      "fighter": [ "fighting", "fighter", "beat'em up" ],
      "maze": [ "maze" ],
      "paddle": [ "paddle" ],
      "pinball": [ "pinball" ],
      "platformer": [ "platformer", "platform" ],
      "puzzle": [ "puzzle" ],
      "racing": [ "racing", "driving" ],
      "rhythm": [ "rhythm" ],
      "rpg": [ "rpg", "role playing", "role playing game" ],
      "shooter": [ "shooter", "shooter scrolling", "shmup" ],
      "sports": [ "sports", "boxing", "golf", "baseball", "football", "soccer" ],
      "strategy": [ "strategy"]
   }
   local cat = " " + fe.game_info(Info.Category, offset).tolower()
   local matches = []
   foreach( key, val in supported )
      foreach( nickname in val )
         if ( cat.find(nickname, 0) ) matches.push(key)
   if ( matches.len() > 0 ) {
      if ( magic_image_settings.genre.mode == 0 ) {
         return magic_image_settings.genre.path + matches[0] + magic_image_settings.genre.ext
      } else if ( magic_image_settings.genre.mode == 1 ) {
         return magic_image_settings.genre.path + matches[matches.len() - 1] + magic_image_settings.genre.ext
      } else if ( magic_image_settings.genre.mode == 2 ) {
         local random_num = floor(((rand() % 1000 ) / 1000.0) * ((matches.len() - 1) - (0 - 1)) + 0)
         return magic_image_settings.genre.path + matches[random_num] + magic_image_settings.genre.ext
      }
   }
   return magic_image_settings.genre.path + "unknown" + magic_image_settings.genre.ext
}

//return file_name for players
function players( offset ) {
   local info = fe.game_info( Info.Players, offset ).tolower()
   if ( info.len() >= 1 ) return magic_image_settings.players.path + info.slice(0, 1) + magic_image_settings.players.ext
   return magic_image_settings.players.path + "unknown" + magic_image_settings.players.ext
}

sickle

  • Full Member
  • ***
  • Posts: 65
    • View Profile
Re: found a bug, anyone know a work-around?
« Reply #2 on: May 27, 2020, 03:25:28 PM »
I tried using fe.game_info(Info.Players), but it had the same bug

i found a way that works for me, though it doesn't really work as an alternative for this.

mainly, i used the .file_name because the "players" element needs to be modified later in the script and that was the easiest way i could think of the make an element and change what it was depending on a layout option.

when that started bugging out, I tried just moving the "players" element into the if() statement:
Code: [Select]
if ( config["design"] == "TurboGrafx-16" )
{
local players = fe.add_image("ui/turbo/P[Players].png", 1126, 845, 120, 70)
}

but that didn't allow me to change it later in the script, so finally, I just made a surface, added the "players" element inside the if() statement, and did my modifications (visibility) directly to the surface, instead of the "players" element:
Code: [Select]
local david = fe.add_surface(fe.layout.width,fe.layout.height)
david.visible=true


local config = fe.get_config()
if ( config["design"] == "TurboGrafx-16" )
{
local playersimg = david.add_image("ui/turbo/P[Players].png", 1126, 845, 120, 70)
}
...
david.visible=false