Author Topic: Detect which system is being displayed?  (Read 3804 times)

8bitsdeep

  • Full Member
  • ***
  • Posts: 49
    • View Profile
Detect which system is being displayed?
« on: January 29, 2017, 09:28:33 AM »
I'd like to change some colors used in my layout based on which system's games are currently displayed.

I tried:
Code: [Select]
switch("[System]")
{
    case "NES":
        t.set_rgb(255,0,0);
break;
}

"[System]" outputs the text "NES" as expected when used in an add_text call, but doesn't seem to work in a conditional. I also tried removing the quotes around [System].

Is there a way to do this?

liquid8d

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 442
    • View Profile
Re: Detect which system is being displayed?
« Reply #1 on: January 29, 2017, 07:21:52 PM »
You are correct, magic tokens don't work directly in code, only as parameters for certain AM functions.

You want fe.list, which is the current list (Display) instance:
https://github.com/mickelson/attract/blob/master/Layouts.md#CurrentList

fe.list.name should get what you want.

8bitsdeep

  • Full Member
  • ***
  • Posts: 49
    • View Profile
Re: Detect which system is being displayed?
« Reply #2 on: January 29, 2017, 08:50:39 PM »
Thanks!

That works.  Only issue is, when switching directly between lists with left/right, the value doesn't change. If I back out to the Displays Menu and select a console that way, then it updates fe.list.name.

Is there some way to force an update on transistion?

liquid8d

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 442
    • View Profile
Re: Detect which system is being displayed?
« Reply #3 on: January 30, 2017, 04:19:10 AM »
Yep :)

https://github.com/mickelson/attract/blob/master/Layouts.md#add_transition_callback

Code: [Select]
fe.add_transition_callback(this, "on_transition")

function on_transition(ttype, var, ttime) {
   if ( ttype == Transition.ToNewList ) {
      local name = fe.list.name
      //...
   }
   return false
}
« Last Edit: January 30, 2017, 04:25:23 AM by liquid8d »

8bitsdeep

  • Full Member
  • ***
  • Posts: 49
    • View Profile
Re: Detect which system is being displayed?
« Reply #4 on: January 30, 2017, 07:00:22 AM »
Perfect!  Works like a charm now. Thanks much!   :D