Author Topic: Diving into squirrel-scripting: some questions  (Read 14445 times)

Arcade-TV

  • Jr. Member
  • **
  • Posts: 17
    • View Profile
Diving into squirrel-scripting: some questions
« on: January 30, 2019, 01:26:04 AM »
Hey guys,
I'd like to thank you for all the efford that went into attract mode. Having the freedom of doing so much with it is just awesome.

I'm creating a layout for a 240p-setup to be outputted to a crt and ran into some questions I'd like to sort out.

First issue is with the default font and missing font-size parameter for it:
The font-size is calculated by the layout's size. Mine is 320x240 so the font in my "Configure"-menu is appx. 8px in height, which is okay as long as I use a pixel-font that was created with 8px height in mind. The help-messages on the bottom of the menu are rendered smaller, appx 5px in height in my layout, so again, if I use a font like "CG pixel 4x5" those texts display just fine but the menu-items don't display properly because the 5px font is stretched to a height of 8px.
I would love to see some more parameters to target this issue maybe sometime in the future development of attract mode.

Next is a scripting question about creating a condition for "DisplayName". This does exist as a Magic Token so it can be used in "add_text" but when I want to create a condition I fail to do something like this:

Code: [Select]
if([DisplayName] == "Displays Menu"){
    // code for the layout where I can select the different displays/systems
}else{
    // code for layouts that relate to a display/emulator/gamelist
}

I use snaps with a low alpha value in the background and titles as a small preview image in my layout. When a display has a lot of entries in its gamelist I see performance issues while navigating through the list of games, so I'd like to remove all media while browsing and add it back to the layout after a delay-timer counted to a given value. I've seen concepts like this in other threads but I have to ask:
How can remove an image or artwork and use a function to add it to the layout.
Something like this, called on transition-callbacks doesn't seem to work:
Code: [Select]
function showImage(){
    fe.add_image(...);
}

I sure have some more questions, but for a start this is enough ;-)


Thanks, any help with this is very much appreciated!

rand0m

  • Sr. Member
  • ****
  • Posts: 343
    • View Profile
Re: Diving into squirrel-scripting: some questions
« Reply #1 on: January 30, 2019, 02:17:04 AM »
Welcome to the forums!

1- You can use charsize to force font size
Code: [Select]
local Oview = fe.add_text"[Overview]", #,#,#,#)
Oview.charsize = 20; //Specificy charsize

2- Not sure, I *think* code should be something like
Code: [Select]
if ((fe.displays[fe.list.display_index].name) == "[Specific Display")
 do this

3- U can use following for images:
Code: [Select]
local flyer = fe.add_artwork( "flyer", 670, 130, 450, 610 ); //can be any artwork or image
flyer.trigger = Transition.EndNavigation; //doesn't load all images at once, effects browsing speed in large lists
flyer.mipmap = true;// have a huge effect on performance specially when images are large and shown in AM in reduced size

keilmillerjr

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1167
    • View Profile
Re: Diving into squirrel-scripting: some questions
« Reply #2 on: January 30, 2019, 03:57:08 AM »
You can always edit cfg files using nano or vim. This isn’t something a user should have to mess with while playing. However, try it on an actual crt at 240p. Default install is ok to view minus certain characters like a period. It would be nice to fix, but don’t overthink it because it doesn’t really matter in my opinion.

My layout I’m using percentages for everything including fonts. You will find a percentage that works.

Arcade-TV

  • Jr. Member
  • **
  • Posts: 17
    • View Profile
Re: Diving into squirrel-scripting: some questions
« Reply #3 on: January 30, 2019, 04:03:27 AM »
You can always edit cfg files using nano or vim.

True, but as far as I'm aware, there are no parameters for font-size, only for the default font to use.
In Layouts it's different, but I was targeting the menu that is hardcoded within attract mode.
Or what cfg are you referring to?

Thanks!

Arcade-TV

  • Jr. Member
  • **
  • Posts: 17
    • View Profile
Re: Diving into squirrel-scripting: some questions
« Reply #4 on: January 30, 2019, 04:37:46 AM »
Another thing that I can't sort out is the screensaver.
I'm on Ubuntu Server 18.04 LTS and already added the console blanking command to my grub file.
In RetroArch, when a game is running the screen will stay on forever, but in Attract Mode it blanks after a short time.

I dunno how it's done in RA but I'd love to disable any (system-)screen blanking or screensaver for good.
(this is not related to AM-screensaver)

If anybody has an idea, I'd love to hear it.

keilmillerjr

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1167
    • View Profile
Re: Diving into squirrel-scripting: some questions
« Reply #5 on: January 30, 2019, 06:24:19 AM »
You can always edit cfg files using nano or vim.

True, but as far as I'm aware, there are no parameters for font-size, only for the default font to use.
In Layouts it's different, but I was targeting the menu that is hardcoded within attract mode.
Or what cfg are you referring to?

Thanks!

Everything in the config menu GUI can also be found in attract.cfg and [emulator].cfg files. I can tell you that the menu is not the best, but legible enough to use at 240p.

Arcade-TV

  • Jr. Member
  • **
  • Posts: 17
    • View Profile
Re: Diving into squirrel-scripting: some questions
« Reply #6 on: January 30, 2019, 08:25:46 AM »
With your help I already sorted some problmens I had out, thanks!

Is there a way to re-assign the signals or the way a listbox is navigated?

I'd like to have a horizontal control scheme on start in the displays-menu, then a classical list - a bit like EmulationStation works.
My idea is to position a list and set it to ".visible = false", then animating the system-logos on a horizontal line.
Now I guess I just need to tell the list it has to react to "left/right" instead of "up/down" by manipulating the default signals...?





Is there something like dynamic assignment?

In other languages this might work:

Code: [Select]
array = {1,2,3,4,5};
which_element = "element_" + array[0];
which_element.animate(); // -> should be the same as: element_1

or like this

Code: [Select]
for(i=0;i<10;i++){
    ["element"+i].doSomething;
}

in other words: is there a way to make up an object's name out of a string + a variable and then do something with it?
« Last Edit: January 30, 2019, 08:34:57 AM by Arcade-TV »

Bgoulette

  • Sr. Member
  • ****
  • Posts: 116
  • I wrote a book.
    • View Profile
    • BlakeGoulette.com
Re: Diving into squirrel-scripting: some questions
« Reply #7 on: January 30, 2019, 08:46:30 AM »
So long as your "composite" element exists on the main table (fe), you should be able to do what you want. I have a bunch of variables that I've defined like this (for example):


this.rom_1942 <- {
    "btnA": "Fire",
    "btnB": "Loop"
}


Later, in a function, I want to get the values of btnA, btnB, etc., based on the currently selected game, so I reference it like this, for example:

::print( this["rom_" + fe.game_info(Info.Name)].btnA + "\n" ); // Prints "Fire" (no quotes) to the console

That's off the top of my head. I'm not in front of my "real" code, but I think the above is accurate.

Arcade-TV

  • Jr. Member
  • **
  • Posts: 17
    • View Profile
Re: Diving into squirrel-scripting: some questions
« Reply #8 on: January 31, 2019, 03:14:10 AM »
It's coming together.. bit by bit, thanks guys!

Is there a way to prevent AM from jumping into another Display when I hit left or right in the "Displays Menu"?
I'd like to do custom stuff when up/down/left/right is pressed and I can't find a way to unbind the default signals/actions.


edit:
I think I solved this one...
I'll post my code when it's ready.
« Last Edit: January 31, 2019, 07:37:34 AM by Arcade-TV »

Arcade-TV

  • Jr. Member
  • **
  • Posts: 17
    • View Profile
Re: Diving into squirrel-scripting: some questions
« Reply #9 on: January 31, 2019, 11:35:11 AM »
I'm looking for an elegant way to create this by the number of displays with a loop:

Code: [Select]
::OBJECTS <- {
sys0 = "",
sys1 = "",
sys2 = "",
sys3 = "",
sys4 = "",
sys5 = "",
sys6 = "",
sys7 = "",
sys8 = "",
sys9 = "",
sys10 = "",
sys11 = "",
sys12 = ""
}

« Last Edit: January 31, 2019, 11:37:25 AM by Arcade-TV »

Bgoulette

  • Sr. Member
  • ****
  • Posts: 116
  • I wrote a book.
    • View Profile
    • BlakeGoulette.com
Re: Diving into squirrel-scripting: some questions
« Reply #10 on: January 31, 2019, 12:11:28 PM »
Code: [Select]
::Displays = {};
for ( local i = 0; i < fe.displays.len(); i++ ) {
    ::Displays["sys" + i] = fe.displays[i];
}

/*
Access slots like this (these are all equivalent):

::Displays.sys0;
::Displays["sys0"];
::Displays["sys" + 0.tostring()];
*/

That should work (not at home: can't test it), but it just gives you a table-ized version of the already existing fe.displays array. Unless you're passing something else where I've included fe.displays

Arcade-TV

  • Jr. Member
  • **
  • Posts: 17
    • View Profile
Re: Diving into squirrel-scripting: some questions
« Reply #11 on: January 31, 2019, 12:38:13 PM »
I had the same solution, but without the "::" (What does it mean?)

But it doesn't seem to work:
Script Error in /opt/retropie/configs/all/attractmode/layouts/012019-menu/layout.nut - the index 'sys1' does not exist

edit:
ha! Got the solution here: https://developer.valvesoftware.com/wiki/Squirrel#Tables

The assignment outside a table has to be a key/value pattern with "<-" instead of an equal-sign :-)

Thanks!
« Last Edit: January 31, 2019, 01:10:09 PM by Arcade-TV »

Arcade-TV

  • Jr. Member
  • **
  • Posts: 17
    • View Profile
Re: Diving into squirrel-scripting: some questions
« Reply #12 on: February 01, 2019, 02:07:54 AM »
Another day - another question...

When I create a surface to "group"  images that are aligned horizontally,
must it be the exact size of the layout?

I'm asking because when I create a surface that is 10x wider than the layout it just disappears...

Arcade-TV

  • Jr. Member
  • **
  • Posts: 17
    • View Profile
Re: Diving into squirrel-scripting: some questions
« Reply #13 on: February 02, 2019, 06:40:05 PM »
Is there a opposite method for add_x? Like remove_image and remove_artwork?

Also, I see that the base for positioning a video is top/left. Could it be that this is different for images?
When I do
Code: [Select]
fe.add_image("myImage.extension", 0, 0, layout_with/2, layout_height/2);it looks like the horizontal center is off to the left...

I'm still struggeling to disable the screen blank in AttractMode.

keilmillerjr

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1167
    • View Profile
Re: Diving into squirrel-scripting: some questions
« Reply #14 on: February 02, 2019, 07:19:07 PM »
Is there a opposite method for add_x? Like remove_image and remove_artwork?

Also, I see that the base for positioning a video is top/left. Could it be that this is different for images?
When I do
Code: [Select]
fe.add_image("myImage.extension", 0, 0, layout_with/2, layout_height/2);it looks like the horizontal center is off to the left...

I'm still struggeling to disable the screen blank in AttractMode.

You can toggle visibility, opacity, change path to empty string, or possibly changing the variable (haven’t actually tried the latter, but assume it would work).

Images will stretch (default) to the dimensions provided, and be placed at the location provided. Horizontal center of the image is off to the left of the screen because that is where you placed the image. Image is placed in the top left of your layout, and is half the size of your layout. You need to change your position if you want the image centered horizontally within your layout.

Not sure what a screen blank is.