Attract-Mode Support Forum

Attract-Mode Support => General => Topic started by: arthurvalenca on February 20, 2021, 05:48:12 AM

Title: [HELP] Function Switch Case
Post by: arthurvalenca on February 20, 2021, 05:48:12 AM
Hello, I need help basically what i would like to do and when i press the key up or down change the platform in attractmode and when change the platform the code by [DisplayName] show the background image referring to the selected platform, could someone help me with this code


Code: [Select]
function on_signal( sig ){

switch ( sig )
{
case "up":
fe.signal( "prev_display" );
return true;

case "down":
fe.signal( "next_display" );
return true;
}
return false;
}
fe.add_signal_handler(this, "on_signal");

##########################################################################################

function layout_transitions(ttype, var, ttime) {
switch(ttype)
{
case Transition.ToNewList:
            switch ([DisplayName])
            {
case "Arcade":

local ar = fe.add_image ( "images/arcade.png", flx*0.0, fly*0.0, flw, flh );

break;

case "Sega Genesis":

local sg = fe.add_image ( "images/sega genesis.png", flx*0.0, fly*0.0, flw, flh );

break;
}
}
return false;
}
Title: Re: [HELP] Function Switch Case
Post by: mahuti on February 20, 2021, 06:53:36 PM
When the display is changed, the layout is loaded/reloaded (if I recall correctly). You can use the name of the display to load a graphic with the same name as the display. In this example a display called  "Arcade" would load "Arcade.png", if named "Nintendo Entertainment System" then it would load "Nintendo Entertainment System.png".

Code: [Select]
local display = fe.list.name
local display_background = fe.add_image(display + ".png" , 0, 0, fe.layout.width, fe.layout.height)

function on_signal( sig )
{
    switch ( sig )
    {
        case "up":
            fe.signal( "prev_display" );
            return true;

        case "down":
            fe.signal( "next_display" );
            return true;
    }
    return false;
}
   
fe.add_signal_handler(this, "on_signal");
Title: Re: [HELP] Function Switch Case
Post by: arthurvalenca on February 23, 2021, 03:26:37 PM
When the display is changed, the layout is loaded/reloaded (if I recall correctly). You can use the name of the display to load a graphic with the same name as the display. In this example a display called  "Arcade" would load "Arcade.png", if named "Nintendo Entertainment System" then it would load "Nintendo Entertainment System.png".

Code: [Select]
local display = fe.list.name
local display_background = fe.add_image(display + ".png" , 0, 0, fe.layout.width, fe.layout.height)

function on_signal( sig )
{
    switch ( sig )
    {
        case "up":
            fe.signal( "prev_display" );
            return true;

        case "down":
            fe.signal( "next_display" );
            return true;
    }
    return false;
}
   
fe.add_signal_handler(this, "on_signal");

Big thanks,
this really was what I expected