Author Topic: Getting Magic Tokens to work with fe.do_nut  (Read 10685 times)

BadFurDay

  • Full Member
  • ***
  • Posts: 82
    • View Profile
Getting Magic Tokens to work with fe.do_nut
« on: November 15, 2017, 05:30:39 PM »
Hi everyone,

I'm wanting to use magic tokens with the command fe.do_nut so it will load a .nut file based on the display name.  Is there anyway to do it as the way I thought would work doesn't, or even is there any workarounds to get it to do this?

Thanks for any help.

keilmillerjr

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1167
    • View Profile
Re: Getting Magic Tokens to work with fe.do_nut
« Reply #1 on: November 15, 2017, 07:51:06 PM »
No. Look at layouts.md file on github. Magic tokens may only be used where explicitly stated. However, there are functions that will return the same data as a magic function. Browse through the markdown file, find the function you need, and include it within your file param within fe.do_nut(whatever_function_wil_return_your_info() + ".nut").

BadFurDay

  • Full Member
  • ***
  • Posts: 82
    • View Profile
Re: Getting Magic Tokens to work with fe.do_nut
« Reply #2 on: November 16, 2017, 04:07:43 PM »
No. Look at layouts.md file on github. Magic tokens may only be used where explicitly stated. However, there are functions that will return the same data as a magic function. Browse through the markdown file, find the function you need, and include it within your file param within fe.do_nut(whatever_function_wil_return_your_info() + ".nut").

I'm sorry but can you point me in the right direction?  Can't find this markdown file at all, where do I find it?

keilmillerjr

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1167
    • View Profile
Re: Getting Magic Tokens to work with fe.do_nut
« Reply #3 on: November 16, 2017, 09:28:28 PM »
No. Look at layouts.md file on github. Magic tokens may only be used where explicitly stated. However, there are functions that will return the same data as a magic function. Browse through the markdown file, find the function you need, and include it within your file param within fe.do_nut(whatever_function_wil_return_your_info() + ".nut").

I'm sorry but can you point me in the right direction?  Can't find this markdown file at all, where do I find it?

https://github.com/mickelson/attract/blob/master/Layouts.md

BadFurDay

  • Full Member
  • ***
  • Posts: 82
    • View Profile
Re: Getting Magic Tokens to work with fe.do_nut
« Reply #4 on: November 17, 2017, 03:46:05 AM »
No. Look at layouts.md file on github. Magic tokens may only be used where explicitly stated. However, there are functions that will return the same data as a magic function. Browse through the markdown file, find the function you need, and include it within your file param within fe.do_nut(whatever_function_wil_return_your_info() + ".nut").

I'm sorry but can you point me in the right direction?  Can't find this markdown file at all, where do I find it?

https://github.com/mickelson/attract/blob/master/Layouts.md

Thanks for your help so far. Looking through the layouts.md it would appear, to me at least, that both "fe.Display(name)" or "fe.game_info(Info.Emulator)" should return the information. Both just end up in the default layout that shows when something in the coding is completely wrong. Am I on the right track?

BadFurDay

  • Full Member
  • ***
  • Posts: 82
    • View Profile
Re: Getting Magic Tokens to work with fe.do_nut
« Reply #5 on: November 17, 2017, 05:10:48 PM »
I've tried different variations of fe.do_nut(fe.game_info(Info.Emulator) + ".nut") and fe.do_nut(fe.Display(name) + ".nut") including fe.displays and neither work. My knowledge of coding this stuff is minimal and I usually just copy and paste previous work tweaking it to my liking. Unfortunately with this I am totally stumped, I don't know why or how it works so I can't get my head around it. Really no clue hoping someone can just show me how this is done please.

keilmillerjr

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1167
    • View Profile
Re: Getting Magic Tokens to work with fe.do_nut
« Reply #6 on: November 17, 2017, 06:43:19 PM »
I've tried different variations of fe.do_nut(fe.game_info(Info.Emulator) + ".nut") and fe.do_nut(fe.Display(name) + ".nut") including fe.displays and neither work. My knowledge of coding this stuff is minimal and I usually just copy and paste previous work tweaking it to my liking. Unfortunately with this I am totally stumped, I don't know why or how it works so I can't get my head around it. Really no clue hoping someone can just show me how this is done please.

Try fe.do_nut(fe.list.name + ".nut"); Let me know if it works or not. I'm not at home. Print it to console to check and isolate the issue.

liquid8d

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 442
    • View Profile
Re: Getting Magic Tokens to work with fe.do_nut
« Reply #7 on: November 17, 2017, 10:55:05 PM »
I used this before without any issue:

Code: [Select]
//replace specified magic tokens in path
    function get_magic_token_path(path) {
        local tokens = {
            "Name": fe.game_info(Info.Name),
            "Emulator": fe.game_info(Info.Emulator),
            "Year": fe.game_info(Info.Year),
            "Manufacturer": fe.game_info(Info.Manufacturer),
            "Category": fe.game_info(Info.Category),
            "System": fe.game_info(Info.System),
            "DisplayName": fe.list.name
        }
        foreach( key, val in tokens)
            path = replace(path, "[" + key + "]", val);
           
        //replace slashes with backslashes
        path = replace(path, "\\", "/");
        //ensure trailing slash
        local trailing = path.slice(path.len() - 1, path.len());
        if ( trailing != "/") path += "/";
        return path;
    }

    //replace all instances of 'find' in 'str' with 'repl'
    function replace(str, find, repl) {
        local start = str.find(find);
        if ( start != null ) {
            local end = start + find.len();
            local before = str.slice(0, start);
            local after = str.slice(end, str.len());
            str = before + repl + after;
            str = replace(str, find, repl);
        }
        return str;
    }

But your problem may be that you are trying to load the .nut before AM has that info.

Try doing this before you load .nut:
Code: [Select]
local filename = fe.list.name + ".nut";
print( filename + "\n" );

You might have to use a transition callback and catch the Transition.StartLayout or Transition.ToNewList or whatever you need, where that information will be available.

That may put a kink in your plans, depending on what you are trying to do in the .nut

BadFurDay

  • Full Member
  • ***
  • Posts: 82
    • View Profile
Re: Getting Magic Tokens to work with fe.do_nut
« Reply #8 on: November 18, 2017, 10:23:30 AM »
I've tried different variations of fe.do_nut(fe.game_info(Info.Emulator) + ".nut") and fe.do_nut(fe.Display(name) + ".nut") including fe.displays and neither work. My knowledge of coding this stuff is minimal and I usually just copy and paste previous work tweaking it to my liking. Unfortunately with this I am totally stumped, I don't know why or how it works so I can't get my head around it. Really no clue hoping someone can just show me how this is done please.

Try fe.do_nut(fe.list.name + ".nut"); Let me know if it works or not. I'm not at home. Print it to console to check and isolate the issue.

This worked a treat! Thanks for your input too though liquid8d. I'm basically trying to put all the robospin themes made by Cosmo and myself (in the themes section of this forum) into one layout. I'm using this command to bring up a separate .nut file with all the system/display specific stuff like snap position, but the main layout has the generic stuff like wheel and game information settings. Hoping this means that using the themes and customising them will be much easier for people. Does appear to cause a slightly longer loading time (on the Pi at least) though nothing too noticeable.

BadFurDay

  • Full Member
  • ***
  • Posts: 82
    • View Profile
Re: Getting Magic Tokens to work with fe.do_nut
« Reply #9 on: November 19, 2017, 03:00:57 PM »
Couple more questions, the first one isn't major but the second one would be good to know:

1) Can I add a folder to the fe.do_nut(fe.list.name + ".nut"); line so I can put the extra files in a separate folder i.e. fe.do_nut(nuts/fe.list.name + ".nut"); (but this doesn't work).

2) Can I add a Transition.StartLayout to the fe.do_nut as currently scrolling through the displays with a button press means the same .nut is active instead of loading the new one to mach the new display/display name.

Thanks again.

keilmillerjr

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1167
    • View Profile
Re: Getting Magic Tokens to work with fe.do_nut
« Reply #10 on: November 19, 2017, 03:23:14 PM »
Couple more questions, the first one isn't major but the second one would be good to know:

1) Can I add a folder to the fe.do_nut(fe.list.name + ".nut"); line so I can put the extra files in a separate folder i.e. fe.do_nut(nuts/fe.list.name + ".nut"); (but this doesn't work).

2) Can I add a Transition.StartLayout to the fe.do_nut as currently scrolling through the displays with a button press means the same .nut is active instead of loading the new one to mach the new display/display name.

Thanks again.

1. If your parameter is not a variable, it needs to be enclosed in quotes. Wrap your nuts and you will be fine. Lol "nuts/" + nutsvar + ".nut"

2. I don't understand what you are trying to do.

BadFurDay

  • Full Member
  • ***
  • Posts: 82
    • View Profile
Re: Getting Magic Tokens to work with fe.do_nut
« Reply #11 on: November 19, 2017, 04:14:29 PM »
Couple more questions, the first one isn't major but the second one would be good to know:

1) Can I add a folder to the fe.do_nut(fe.list.name + ".nut"); line so I can put the extra files in a separate folder i.e. fe.do_nut(nuts/fe.list.name + ".nut"); (but this doesn't work).

2) Can I add a Transition.StartLayout to the fe.do_nut as currently scrolling through the displays with a button press means the same .nut is active instead of loading the new one to mach the new display/display name.

Thanks again.

1. If your parameter is not a variable, it needs to be enclosed in quotes. Wrap your nuts and you will be fine. Lol "nuts/" + nutsvar + ".nut"

2. I don't understand what you are trying to do.

I'll be sure to wrap my nuts lol.

It's for when you scroll through the displays with a button press, it doesn't "reload " the layout so it causes the old background and snap/boxart settings to carry over too which is what I have loading in this separate display name .nut file. I can share what I've done so far if that helps.

keilmillerjr

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1167
    • View Profile
Re: Getting Magic Tokens to work with fe.do_nut
« Reply #12 on: November 19, 2017, 04:42:32 PM »
Couple more questions, the first one isn't major but the second one would be good to know:

1) Can I add a folder to the fe.do_nut(fe.list.name + ".nut"); line so I can put the extra files in a separate folder i.e. fe.do_nut(nuts/fe.list.name + ".nut"); (but this doesn't work).

2) Can I add a Transition.StartLayout to the fe.do_nut as currently scrolling through the displays with a button press means the same .nut is active instead of loading the new one to mach the new display/display name.

Thanks again.

1. If your parameter is not a variable, it needs to be enclosed in quotes. Wrap your nuts and you will be fine. Lol "nuts/" + nutsvar + ".nut"

2. I don't understand what you are trying to do.

I'll be sure to wrap my nuts lol.

It's for when you scroll through the displays with a button press, it doesn't "reload " the layout so it causes the old background and snap/boxart settings to carry over too which is what I have loading in this separate display name .nut file. I can share what I've done so far if that helps.

Ok, I understand now. I do not use displays. So there might be a better way. However, I would try creating a transition and reloading the layout via signal?

BadFurDay

  • Full Member
  • ***
  • Posts: 82
    • View Profile
Re: Getting Magic Tokens to work with fe.do_nut
« Reply #13 on: November 20, 2017, 02:22:26 AM »
I've tried to us: fe.do_nut("nuts/" + fe.list.name + ".nut"); and it didn't work I'm afraid.

I've also tried to play about with signals previously and failed miserably. My experience with scripting is basically copying and pasting what has been done previously but manipulating it to try get it to work. Anything from scratch I'm pretty useless.

BadFurDay

  • Full Member
  • ***
  • Posts: 82
    • View Profile
Re: Getting Magic Tokens to work with fe.do_nut
« Reply #14 on: November 25, 2017, 11:54:33 AM »
Can anyone help me to make the fe.do_nut apply/reload every time the display is changed?