Attract-Mode Support Forum

Attract-Mode Support => Scripting => Topic started by: 8bitsdeep on January 29, 2017, 09:28:33 AM

Title: Detect which system is being displayed?
Post by: 8bitsdeep 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?
Title: Re: Detect which system is being displayed?
Post by: liquid8d 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.
Title: Re: Detect which system is being displayed?
Post by: 8bitsdeep 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?
Title: Re: Detect which system is being displayed?
Post by: liquid8d 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
}
Title: Re: Detect which system is being displayed?
Post by: 8bitsdeep on January 30, 2017, 07:00:22 AM
Perfect!  Works like a charm now. Thanks much!   :D