Author Topic: Need help squirrel function "file exist" working only on f.e. startup  (Read 4224 times)

qqplayer

  • Sr. Member
  • ****
  • Posts: 301
    • View Profile
I made this function , the final goal is to show a "pdfIcon" when you have the game manual on the selected folder "pdffilepath"

Code: [Select]
// pdfIcon

local pdffilepath="H://Attract//layouts//Basic//pdf//";
local game_name = fe.game_info(Info.Name);
local pdffile = pdffilepath + game_name + config["extension"];

local littlepngicon = fe.add_image( "manual.png", 0, 0, 200, 200);

fe.load_module("file");
function file_exist(pdffile)
   {
   print(pdffilepath + game_name + config["extension"]);
   try {file(pdffile, "r" );return true;}catch(e){return false;}
   }

if (file_exist(pdffile)) littlepngicon.visible=true
else  littlepngicon.visible=false;

Thanks to Daimon , Oomek and the other people who helped with the code.

As I said , only works when I start the frontend, If I start AM and the last selected game has the pdf manual the icon shows.
But when I move between the diferent games it doesnt change.
I mean if appears when I start the f.e. keeps showing all the time and if I selected a game who doesnt have the pdf manual - close A.M. - and open it again the icon is gone and doesnt shows anymore even if I move to a game who has the pdf manual.

Any help?

Arcadefan1

  • Full Member
  • ***
  • Posts: 27
    • View Profile
Re: Need help squirrel function "file exist" working only on f.e. startup
« Reply #1 on: March 25, 2018, 01:06:02 PM »
I am not a pro, but don't you need to use a transition callback? Something like "to new selection"?

qqplayer

  • Sr. Member
  • ****
  • Posts: 301
    • View Profile
Re: Need help squirrel function "file exist" working only on f.e. startup
« Reply #2 on: March 27, 2018, 09:56:26 AM »
I am not a pro, but don't you need to use a transition callback? Something like "to new selection"?

I made the transition callback but doesnt work , just to test:

Code: [Select]
//pdfIcon

local pdffilepath="H://Attract//layouts//Basic//pdf//";

local littlepngicon = fe.add_image( "manual.png", 0, 0, 200, 200);
littlepngicon.visible=false;

function file_exist( ttype, var, ttime ) {
 switch ( ttype ) {
  case Transition.ToNewSelection|Transition.ToNewList|Transition.EndNavigation:
  local game_name = fe.game_info(Info.Name);
  local pdffile = pdffilepath + game_name + config["extension"];
  print(pdffilepath + game_name + config["extension"])
  break;
  }
 return false;
}

fe.add_transition_callback( "file_exist" );

Is "printing" the right selected game but every attemp to check the "file exists" is broken the f.e.

Code: [Select]
fe.load_module("file");

function catch_file()
   {
   try {file(pdffile, "r" );return true;}
   catch(e){return false;}
   }

if (file_exist(pdffile)) littlepngicon.visible=true;

catch_file();

Quote
Code: [Select]
AN ERROR HAS OCCURED [the index 'pdffile' does not exist]

CALLSTACK
*FUNCTION [main()] H:\Attract\layouts\Basic\pdf\/layout.nut line [95]

LOCALS
[littlepngicon] INSTANCE
[pdffilepath] "H://Attract//layouts//Basic//pdf//pdf//"
[l] INSTANCE
[lb] INSTANCE
[t] INSTANCE
[config] TABLE
[vargv] ARRAY
[this] TABLE
Script Error in H:\Attract\layouts\Basic\pdf\/layout.nut - the index 'pdffile' does not exist
« Last Edit: March 27, 2018, 09:58:31 AM by qqplayer »

Daimon

  • Jr. Member
  • **
  • Posts: 13
    • View Profile
Re: Need help squirrel function "file exist" working only on f.e. startup
« Reply #3 on: March 27, 2018, 11:24:57 AM »
You are almost there, see:

//pdfIcon

fe.load_module("file");

function file_exist()
   {
   try {file(pdffile, "r" );return true;}
   catch(e){return false;}
   }

local pdffilepath="H://Attract//layouts//Basic//pdf//";

local littlepngicon = fe.add_image( "manual.png", 0, 0, 200, 200);
littlepngicon.visible=false;

function mytransition( ttype, var, ttime ) {
 switch ( ttype ) {
  case Transition.ToNewSelection|Transition.ToNewList|Transition.EndNavigation:
       local game_name = fe.game_info(Info.Name);
       local pdffile = pdffilepath + game_name + config["extension"];
       //print(pdffilepath + game_name + config["extension"])
       if (file_exist(pdffile)) littlepngicon.visible=true
       else  littlepngicon.visible=false;
       break;
  }
 return false;
}

fe.add_transition_callback( "mytransition" );

qqplayer

  • Sr. Member
  • ****
  • Posts: 301
    • View Profile
Re: Need help squirrel function "file exist" working only on f.e. startup
« Reply #4 on: March 27, 2018, 12:02:33 PM »
You are almost there, see:

//pdfIcon

fe.load_module("file");

function file_exist()
   {
   try {file(pdffile, "r" );return true;}
   catch(e){return false;}
   }

local pdffilepath="H://Attract//layouts//Basic//pdf//";

local littlepngicon = fe.add_image( "manual.png", 0, 0, 200, 200);
littlepngicon.visible=false;

function mytransition( ttype, var, ttime ) {
 switch ( ttype ) {
  case Transition.ToNewSelection|Transition.ToNewList|Transition.EndNavigation:
       local game_name = fe.game_info(Info.Name);
       local pdffile = pdffilepath + game_name + config["extension"];
       //print(pdffilepath + game_name + config["extension"])
       if (file_exist(pdffile)) littlepngicon.visible=true
       else  littlepngicon.visible=false;
       break;
  }
 return false;
}

fe.add_transition_callback( "mytransition" );

 :(

Code: [Select]
Starting Attract-Mode v2.2.1 (Windows)
Config: Y:\AM_HyperpiePC\Attract\attract.cfg

*** Initializing display: 'Sega Master System'
 - Loaded master romlist 'Sega Master System' in 14 ms (334 entries kept, 0 disc
arded)
 - Constructed 16 filters in 0 ms (5344 comparisons)
 - Loaded layout: Y:\AM_HyperpiePC\Attract\layouts/Basic/ (layout.nut)

AN ERROR HAS OCCURED [wrong number of parameters]

CALLSTACK
*FUNCTION [mytransition()] Y:\AM_HyperpiePC\Attract\layouts/Basic/layout.nut lin
e [89]

LOCALS
[pdffilepath] "Y://AM_HyperpiePC//Attract//layouts//Basic//pdf//"
[config] TABLE
[littlepngicon] INSTANCE
[pdffile] "Y://AM_HyperpiePC//Attract//layouts//Basic//pdf//Ace of Aces (Europe)
.pdf"
[game_name] "Ace of Aces (Europe)"
[ttime] 0
[var] 0
[ttype] 7
[this] TABLE
Script Error in transition function: mytransition - wrong number of parameters

AN ERROR HAS OCCURED [wrong number of parameters]

CALLSTACK
*FUNCTION [mytransition()] Y:\AM_HyperpiePC\Attract\layouts/Basic/layout.nut lin
e [89]

LOCALS
[pdffilepath] "Y://AM_HyperpiePC//Attract//layouts//Basic//pdf//"
[config] TABLE
[littlepngicon] INSTANCE
[pdffile] "Y://AM_HyperpiePC//Attract//layouts//Basic//pdf//4 PAK All Action (Au
stralia).pdf"
[game_name] "4 PAK All Action (Australia)"
[ttime] 0
[var] 0
[ttype] 7
[this] TABLE
Script Error in transition function: mytransition - wrong number of parameters

AN ERROR HAS OCCURED [wrong number of parameters]

CALLSTACK
*FUNCTION [mytransition()] Y:\AM_HyperpiePC\Attract\layouts/Basic/layout.nut lin
e [89]

LOCALS
[pdffilepath] "Y://AM_HyperpiePC//Attract//layouts//Basic//pdf//"
[config] TABLE
[littlepngicon] INSTANCE
[pdffile] "Y://AM_HyperpiePC//Attract//layouts//Basic//pdf//20 em 1 (Brazil).pdf
"
[game_name] "20 em 1 (Brazil)"
[ttime] 0
[var] 0
[ttype] 7
[this] TABLE
Script Error in transition function: mytransition - wrong number of parameters

This is the "line 89"

Code: [Select]
       if (file_exist(pdffile)) littlepngicon.visible=true
Thanks , again I think is close but...

Daimon

  • Jr. Member
  • **
  • Posts: 13
    • View Profile
Re: Need help squirrel function "file exist" working only on f.e. startup
« Reply #5 on: March 27, 2018, 01:33:29 PM »
fixed: AN ERROR HAS OCCURED [wrong number of parameters] -> copy/paste error in function file_exist(pdffile)

//pdfIcon

fe.load_module("file");

function file_exist(pdffile)
   {
   try {file(pdffile, "r" );return true;}
   catch(e){return false;}
   }

local pdffilepath="H://Attract//layouts//Basic//pdf//";

local littlepngicon = fe.add_image( "manual.png", 0, 0, 200, 200);
littlepngicon.visible=false;

function mytransition( ttype, var, ttime ) {
 switch ( ttype ) {
  case Transition.ToNewSelection|Transition.ToNewList|Transition.EndNavigation:
       local game_name = fe.game_info(Info.Name);
       local pdffile = pdffilepath + game_name + config["extension"];
       //print(pdffilepath + game_name + config["extension"])
       if (file_exist(pdffile)) littlepngicon.visible=true
       else  littlepngicon.visible=false;
       break;
  }
 return false;
}

fe.add_transition_callback( "mytransition" );

qqplayer

  • Sr. Member
  • ****
  • Posts: 301
    • View Profile
Re: Need help squirrel function "file exist" working only on f.e. startup
« Reply #6 on: March 28, 2018, 03:09:07 AM »
fixed: AN ERROR HAS OCCURED [wrong number of parameters] -> copy/paste error in function file_exist(pdffile)

//pdfIcon

fe.load_module("file");

function file_exist(pdffile)
   {
   try {file(pdffile, "r" );return true;}
   catch(e){return false;}
   }

local pdffilepath="H://Attract//layouts//Basic//pdf//";

local littlepngicon = fe.add_image( "manual.png", 0, 0, 200, 200);
littlepngicon.visible=false;

function mytransition( ttype, var, ttime ) {
 switch ( ttype ) {
  case Transition.ToNewSelection|Transition.ToNewList|Transition.EndNavigation:
       local game_name = fe.game_info(Info.Name);
       local pdffile = pdffilepath + game_name + config["extension"];
       //print(pdffilepath + game_name + config["extension"])
       if (file_exist(pdffile)) littlepngicon.visible=true
       else  littlepngicon.visible=false;
       break;
  }
 return false;
}

fe.add_transition_callback( "mytransition" );

Thank you so much!!!!  is working ;)