Author Topic: [Fixed] Syntax error [firstletter ()]?  (Read 976 times)

manzarek

  • Sr. Member
  • ****
  • Posts: 147
    • View Profile
    • YouTube
[Fixed] Syntax error [firstletter ()]?
« on: September 15, 2022, 04:05:03 PM »
When I start AM and try to enter a system for example MAME, AM freezes and I have to close it manually. When I open the last_run.log file I see this error, can you give me a hand to solve? did he do it to you too?

AN ERROR HAS OCCURED [slice out of range]

CALLSTACK
*FUNCTION [firstletter()] H:\Arcade\layouts/Boysroom/layout.nut line [163]



In line 163 I have this syntax
Code: [Select]
////////////////////////////////////////////////////////////////////////////////
//First Letter//

function firstletter ()
    {
        local first_char = rstrip(fe.game_info(Info.Title)).slice(0,1);
        local expression = regexp("[a-zA-Z]");
        if (expression.match(first_char) == true) return first_char
        else return "#";
    }

//First Letter White//
local surface = fe.add_image( "firstletter/[!firstletter]",10, 1040, 480, 25);

////////////////////////////////////////////////////////////////////////////
« Last Edit: September 17, 2022, 05:35:57 AM by manzarek »
Mame Fighting

Daimon

  • Jr. Member
  • **
  • Posts: 13
    • View Profile
Re: Syntax error [firstletter ()]?
« Reply #1 on: September 16, 2022, 10:41:07 AM »
The error message indicates -> [slice out of range]
which refers to line 163 -> local first_char = rstrip(fe.game_info(Info.Title)).slice(0,1);

Most likely the 'Info.Title' is empty. If this assumption is correct the following is adviced.

Try replacing the complete function firstletter () with:

function firstletter ()
    {
        local first_char = "#";
        if  (rstrip(fe.game_info(Info.Title)).len() > 0) {
            first_char = rstrip(fe.game_info(Info.Title)).slice(0,1);
        }
        local expression = regexp("[a-zA-Z]");
        if (expression.match(first_char) ==  false) first_char = "#"
        return first_char;
    }


The scribble is not tested.
Goodluck.

manzarek

  • Sr. Member
  • ****
  • Posts: 147
    • View Profile
    • YouTube
Re: Syntax error [firstletter ()]?
« Reply #2 on: September 17, 2022, 05:27:45 AM »
A worked thanks a lot! :)
If I can leverage your help, I also have a problem with this clock syntax

at line 71 I have this code: specifically line 71 is this syntax that gives error. (marked it in red)
clock.msg = format("%02d", now.hour) + ":" + format("%02d", now.min );

The whole code is this, I put it outside because here it gives me a server error
https://justpaste.it/8nr2p



EDIT: Fixed, was a double code exactly the same as the one reported
« Last Edit: September 17, 2022, 05:35:30 AM by manzarek »
Mame Fighting