Author Topic: How to write a script to return msg while empty value of catalog  (Read 3205 times)

kent79

  • Hero Member
  • *****
  • Posts: 842
    • View Profile
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
« Last Edit: May 07, 2018, 07:27:22 AM by kent79 »

keilmillerjr

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1167
    • View Profile
Re: How to write a script to return msg while empty value of catalog
« Reply #1 on: May 07, 2018, 10:00:06 AM »
Use a magic function and test string length on category.

kent79

  • Hero Member
  • *****
  • Posts: 842
    • View Profile
Re: How to write a script to return msg while empty value of catalog
« Reply #2 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

keilmillerjr

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1167
    • View Profile
Re: How to write a script to return msg while empty value of catalog
« Reply #3 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.


qqplayer

  • Sr. Member
  • ****
  • Posts: 301
    • View Profile
Re: How to write a script to return msg while empty value of catalog
« Reply #4 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
« Last Edit: May 07, 2018, 01:42:01 PM by qqplayer »

kent79

  • Hero Member
  • *****
  • Posts: 842
    • View Profile
Re: How to write a script to return msg while empty value of catalog
« Reply #5 on: May 07, 2018, 04:48:56 PM »
Thank you qqplayer. It works  :)