attract
attract copied to clipboard
index 0 error in filter magic string
Hi, I was writing a layout for me and in AM 2.4 it works ok, but in AM 2.5.1 it is thowing an error in a line with the command below
local text = fe.filters[fe.list.filter_index].name;
String error in magic string function: filter - the index '0' does not exist
The code of the layout is exact the same and it works in AM 2.4. Has anything changed in AM2.5.1?
I am using Windows version.
Is this a bug or can I fix the code? Thanks
Does the following code work for you?
function filter() {
return fe.filters[fe.list.filter_index].name;
}
fe.add_text("[!filter]", 0, 0, 400, 50 )
Could you post a minimalistic example of the code that throws this error?
yes the code is very similar:
local listtext = fe.add_text( "[!filter] Games", 33, 45, 240, 21);
listtext.set_rgb( 211, 250, 255 );
listtext.font="Ticketbook W01 Bold";
listtext.align = Align.Centre;
// Change filter name to upper case
function filter(){
local text = fe.filters[fe.list.filter_index].name;
return text.toupper();
}
it fails in local text = fe.filters[fe.list.filter_index].name;
The code you have posted do not throw any errors. I believe it was fixed recently in the following commit https://github.com/mickelson/attract/commit/0b9853119487a7bd80b7b27ad6b85b40c962cee9
Would you please try it in the daily build http://forum.attractmode.org/index.php?topic=2324.0
@oomek I've run attract-64console_03_14_2019.exe and the same error is thrown
I am also using the Platforms plugin don't know if it is related
this is the setup I am using in my attract.cfg
general
language en
exit_command
default_font arial
font_path %SYSTEMROOT%/Fonts/
screen_saver_timeout 600
displays_menu_exit no
hide_brackets no
startup_mode displays_menu
confirm_favourites yes
confirm_exit yes
mouse_threshold 10
joystick_threshold 75
window_mode default
filter_wrap_mode default
track_usage yes
multiple_monitors yes
smooth_images yes
accelerate_selection yes
selection_speed_ms 40
scrape_snaps yes
scrape_marquees yes
scrape_flyers yes
scrape_wheels yes
scrape_fanart no
scrape_videos no
scrape_overview no
hide_console no
video_decoder software
menu_prompt Displays Menu
menu_layout Pandoras Box
display Consoles
layout Pandoras Box
romlist Consoles
in_cycle no
in_menu yes
global_filter
rule FileIsAvailable equals 1
filter All
filter Favourites
rule Favourite equals 1
display Atari 2600
layout Pandoras Box
romlist Atari 2600
in_cycle no
in_menu no
global_filter
rule FileIsAvailable equals 1
filter All
filter Favourites
rule Favourite equals 1
and my Consoles.txt:
Atari 2600;Atari 2600;@;;;;;;;;;0;;;;;
and the Atari 2600 contains the normal romlist games for Atari
I had the same issue recently when I checked the latest build by Oomek, that happened because I’m that installation I had no filters defined. Check if installing 2.5.1 you created at least an ALL filter. I solved this first checking if fe.filters.len() > 0
Maybe your index is out of range. Are you sure you have at least 1 filter defined?
If this is the case the array index might be going out of range.
you can try adding one line in your function.
if( fe.filters.len() == 0 ) return ""
I think maybe there's something related to the config "startup_mode displays_menu"... not sure... if I change it to "startup_mode default" attract mode loads up but does not show anything:
*** Initializing display: 'Consoles'
- Loaded master romlist 'Consoles' in 0 ms (0 entries kept, 1 discarded)
- Constructed 2 filters in 0 ms (0 comparisons)
- Loaded layout: C:\Temp\attract\layouts/Pandoras Box/ (layout.nut)
Error getting emulator info for launch
@zpaolo11x but I have defined filters for the top category Consoles and also for the system Atari 2600. See my attract.cfg above
Which is the line with error in last_run? This > local listtext = fe.add_text( "[!filter] Games", 33, 45, 240, 21); or This > local text = fe.filters[fe.list.filter_index].name;
If the first line try this > local listtext = fe.add_text( "[!filter]" + "Games", 33, 45, 240, 21);
Platforms plugin functions were added in base AM.
no the error is in this line -> local text = fe.filters[fe.list.filter_index].name;
And about the platforms plugin do I need to enable it somewhere or it is built in attract mode and using a romlist like Atari 2600;Atari 2600;@;;;;;;;;;0;;;;; it detects?
its built-in you don't need the "0" but do need to use "@" for emulator. The romlist example will become Atari 2600;Atari 2600;@;;;;;;;;;;;;;; and will work without anything else
found the issue... for some reason if I remove the filter
global_filter
rule FileIsAvailable equals 1
from the Platform it works (in this example Consoles). If I put it back the error is thrown
also another thing is that if I put all displays with the same layout and also the menu_layout with this same layout the bug happens... maybe someone should look if possible
the problem persists when using the same layout for all displays including the same display for menu_layout.
I am having trouble with this as well. I am trying to update a formatted filter string on a transition ToNewList. It doesn’t work if I start on menu_layout. printing to terminal, I don’t think filter array is being updated properly. If I enable Startup Mode Show Displays Menu, string is constantly empty as filter array length is always zero.
Weird because using a magic token works perfectly, except I can not format the text.
EDIT: Here’s a snippet of my code. I just edited the font to have all uppercase letters. Solves the issue with displaying the filter. Good thing I am not search and replacing text in it. Just char case. Using attract 2.5.1-28 compiled on my mac. I have 3 displays, all of them not in cycle but in menu.
function formatFilter() {
if ((fe.list.display_index < 0) || fe.list.filter_index == 0) return "";
return fe.filters[fe.list.filter_index].name.toupper();
}
fe.add_transition_callback("transitions");
function transitions(ttype, var, ttime) {
switch (ttype) {
case Transition.ToNewList:
// ---------- Filter Transition
//filter.msg = formatFilter();
local filterCharWidth = filter.msg.len()*filter.char_size.tofloat();
if (filterCharWidth < config.filter.width) {
filter.width = filterCharWidth;
filter.x = config.filter.x+config.filter.width-filter.width;
}
else {
filter.width = config.filter.width;
filter.x = config.filter.x;
}
break;
}
return false;
}