Author Topic: If Statement using Display Name  (Read 168 times)

MACMAN

  • Newbie
  • *
  • Posts: 2
    • View Profile
If Statement using Display Name
« on: June 06, 2020, 06:17:20 AM »
Hey All - Total Noob question here that I have not been able to answer or find an answer to in the forum:

I have several Displays that all use the same layout.nut file.  The difference between the displays is each has a filter against the ROM list so that "Platform Games" are separated from "Maze Games", etc.  This way, moving the joystick right/left moves between displays and therefor between game categories.  All of this works fine. 

Here's what I'm trying to accomplish: Display a different graphic on the screen when the display "Favorite Games" is displayed.  (This graphic contains instructions informing the player which buttons to press to remove the selected game from the favorites list whereas the graphic for the other displays contains instructions informing the player which buttons to press to add the selected game to the favorites list).

Here's what I can't solve: I've constructed an IF statement to make a decision based on the name of the display - If display name is "Favorite Games" then show this graphic, if not, show the other.  I cannot figure out how to construct the IF statement that can dynamically read the CURRENT display name.  I've tried various methods to get at the current display name and while I can display the correct, current display name on the screen (both of these fe.add_text display the correct, current display name) using methods below I cannot figure out how to assign the current display name to a local or use it in an IF statement. 

These statements display the current display name but I don't know how to assign them for use in an IF statement:

   local control = fe.add_text( "Token: "+"[DisplayName]", 0, 30, 800, 15  );
   local print_display = fe.add_text( "!dname: [!dname]", 0, 45, 800, 15  );

   function dname()
   {
    local fct_current_display = fe.displays[fe.list.display_index];
    return fct_current_display.name;
   }

I'm trying to do something like this:
function disp_graphic()
 {
      local current_display_for_graphic = fe.displays[fe.list.display_index];

   if ( current_display_for_graphic.name == "Favorite Games" )
   {
    local game_type = fe.add_image( "instructions/remove.png", 0, 540, 1024, 360 );
   } else {
    local game_type = fe.add_image( "instructions/add.png", 0, 540, 1024, 360 );
   }
   return current_display_for_graphic.name;
 }

// Execute the function disp_graphic()
  local test_this_function = disp_graphic();

Everything else I've tried only brings back the name of the initial display at start up time and the IF statement above works but doesn't change when moving from display to display.  It seems like I'm struggling with two things: 1) local assignment of the string from the Token to a local variable upon which to make a decision on and/or 2) getting after the "right" thing to get the current display after the display has changed.

Any help would be appreciated.

My programming experience is super old and rusty (Think COBOL and early Client-Server, Visual Basic stuff) but I can usually muddle through!  Thanks for the help!

beccobunsen

  • Jr. Member
  • **
  • Posts: 19
    • View Profile
Re: If Statement using Display Name
« Reply #1 on: June 08, 2020, 03:07:19 PM »
http://forum.attractmode.org/index.php?topic=1362.0

Code: [Select]
//find out about the displays
print(fe.displays.len() + " displays\n")
foreach(idx, display in fe.displays )
    print( idx + ": " + display.name + "\n")

//load based on display index
function load_display(idx) {
    if ( fe.list.display_index != idx ) fe.set_display(idx)
}

//load based on display name
function load_display_name(name) {
   foreach( idx, display in fe.displays )
      if ( name == fe.displays[idx].name && name != fe.displays[fe.list.display_index].name ) fe.set_display(idx)
}

load_display_name("mame")

better if you start attract mode via console (this line >>>>>>>>>>>> print(fe.displays.len() + " displays\n")  print in the console)

Saludos!

MACMAN

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: If Statement using Display Name
« Reply #2 on: June 09, 2020, 05:16:23 AM »
Thanks for the info. 

Couple of thoughts - I'm trying to divorce having to rely on the display number (index) to load the proper graphic since I might add or take away displays at any time and I'd rather not rely on their physical order.  In addition, I'm not trying to load a display, I just need to know how to reference the current display's name so it can be evaluated.  Something like: If display name = "X", then load this graphic

I realize that accessing the token works as expected to display it on the screen but doesn't work the same way to evaluate it (or I haven't been doing it correctly!).

Any other ideas?  Can it be done?  If its buried in the example above then I missed it!

Thanks!

beccobunsen

  • Jr. Member
  • **
  • Posts: 19
    • View Profile
Re: If Statement using Display Name
« Reply #3 on: June 09, 2020, 04:06:22 PM »
try this approach instead

local b_art = fe.add_image("backgrounds/[DisplayName]", 0, 0, flw, flh );