Attract-Mode Support Forum

Attract-Mode Support => Scripting => Topic started by: kent79 on May 07, 2018, 06:23:58 AM

Title: How to write a script to return msg while empty value of catalog
Post by: kent79 on May 07, 2018, 06:23:58 AM
Hi All,

Just make a new theme  and there is some question.

I would like to display "Category" info and write as below script. It is OK.
Code: [Select]
gridc.cate =  fe.add_text( "|  [Category]", 375, 430, 420, fe.layout.height / 38 );
But I would like to show "No Category information" msg while "Category" info is empty.

I know a concept and don't know exactly scrip. Anyone can teach me? Thanks.

Create a function and check fe.game_info( Info.Category)
if Info.Category > 0, then return  fe.game_info( Info.Category)
if Info.Category =0 , then return  "No Category information" message

http://forum.attractmode.org/index.php?topic=2237.0
Title: Re: How to write a script to return msg while empty value of catalog
Post by: keilmillerjr on May 07, 2018, 10:00:06 AM
Use a magic function and test string length on category.
Title: Re: How to write a script to return msg while empty value of catalog
Post by: kent79 on May 07, 2018, 10:02:24 AM
Use a magic function and test string length on category.

My coding skill is limited. Could you provide the real code? Thanks.  :P
Title: Re: How to write a script to return msg while empty value of catalog
Post by: keilmillerjr on May 07, 2018, 12:35:39 PM
Use a magic function and test string length on category.

My coding skill is limited. Could you provide the real code? Thanks.  :P

I can’t. I’ve been working 85 hour work weeks and took today off to catch up on crap I can’t do working every day of the week.

Read -
https://github.com/mickelson/attract/blob/master/Layouts.md#magic

Look at -
https://github.com/keilmillerjr/mvscomplete/blob/master/layout.nut#L76

Your function will be similar to mine, except add an if/else statement for length. You can’t use magic functions within a magic function, so you have to look at layouts.md for correct variable and format/return it within your function.

Title: Re: How to write a script to return msg while empty value of catalog
Post by: qqplayer on May 07, 2018, 01:40:00 PM
Code: [Select]
// Add a text if no manufacturer found
function no_manufacturer()
{
local m = fe.game_info( Info.Manufacturer );

if (( m.len() <= 0 ))
return "No Manufacturer ";

return m;
}
fe.add_text( "[!no_manufacturer]", 0, 0 , 400, 18);

Just change for "Info.Category" , or whatever you want ;)

Code: [Select]
Parameters:

    id - id of the information attribute to get. Can be one of the following values:
        Info.Name
        Info.Title
        Info.Emulator
        Info.CloneOf
        Info.Year
        Info.Manufacturer
        Info.Category
        Info.Players
        Info.Rotation
        Info.Control
        Info.Status
        Info.DisplayCount
        Info.DisplayType
        Info.AltRomname
        Info.AltTitle
        Info.Extra
        Info.Favourite
        Info.Tags
        Info.PlayedCount
        Info.PlayedTime
        Info.FileIsAvailable
        Info.System
        Info.Overview
Title: Re: How to write a script to return msg while empty value of catalog
Post by: kent79 on May 07, 2018, 04:48:56 PM
Thank you qqplayer. It works  :)