Attract-Mode Support > Scripting

Need help squirrel function "file exist" working only on f.e. startup

(1/2) > >>

qqplayer:
I made this function , the final goal is to show a "pdfIcon" when you have the game manual on the selected folder "pdffilepath"


--- Code: ---// 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;
--- End code ---

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:
I am not a pro, but don't you need to use a transition callback? Something like "to new selection"?

qqplayer:

--- Quote from: Arcadefan1 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"?

--- End quote ---

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


--- Code: ---//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" );
--- End code ---

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


--- Code: ---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();
--- End code ---


--- Quote ---
--- Code: ---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
--- End code ---

--- End quote ---

Daimon:
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:

--- Quote from: Daimon 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" );

--- End quote ---

 :(


--- Code: ---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

--- End code ---

This is the "line 89"


--- Code: ---       if (file_exist(pdffile)) littlepngicon.visible=true
--- End code ---

Thanks , again I think is close but...

Navigation

[0] Message Index

[#] Next page

Go to full version