Author Topic: Slice: Out of Range Error (RegEx)  (Read 2459 times)

rand0m

  • Sr. Member
  • ****
  • Posts: 343
    • View Profile
Slice: Out of Range Error (RegEx)
« on: May 24, 2019, 08:29:44 PM »
While using the following code if I move from last filter to first (loop) or move backwards from first filter to last i get the error "Slice out of range". Lets say the filters are Action, Adventure, Horror, Shooter. When I try to go from Shooter to Action (its a loop) I get the error. If I move back from Action to Shooter, I get the same error. No error/ issues while moving within Action - Shooter, the error is only coming up when moving to start or end of loop i.e. before action or after shooter. Can anyone please help in this regard?

The code being used is:

Code: [Select]
//Get First Letter of Title and Adjust Non-Alphabetical Chars
function first_letter ()
{
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 "#";
}

local indicator_text = fe.add_text( "[!first_letter]",7, 0, 40, 40);
indicator_text.font="BebasNeue Book.ttf";
indicator_text.set_rgb(203,203,203);
indicator_text.style = Style.Bold;
indicator_text.align = Align.MiddleCentre;
indicator_text.charsize = 38;

I am using Leap plugin but doesn't seem like a leap issue because its working within the loop and works without issue in places where some empty filters are "leaped"

keilmillerjr

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1167
    • View Profile
Re: Slice: Out of Range Error (RegEx)
« Reply #1 on: May 24, 2019, 11:51:06 PM »
Quote
slice(start,[end])

returns a section of the string as new string. Copies from start to the end (not included). If start is negative the index is calculated as length + start, if end is negative the index is calculated as length + end. If end is omitted end is equal to the string length.

It sounds like the slice method isnt happy. Do you have a title with a length of zero? Perhaps narrow it down with comments and try blocks. Print your stripped title to screen with length before trying the slice method.

rand0m

  • Sr. Member
  • ****
  • Posts: 343
    • View Profile
Re: Slice: Out of Range Error (RegEx)
« Reply #2 on: May 25, 2019, 05:26:16 AM »
It sounds like the slice method isnt happy. Do you have a title with a length of zero? Perhaps narrow it down with comments and try blocks. Print your stripped title to screen with length before trying the slice method.

It was happening because I was not wrapping the filters in a single display (default) but jumping to next display. Since most display are not properly organized I think slice found an empty romlist and threw the out of range error.

l3m35

  • Jr. Member
  • **
  • Posts: 16
    • View Profile
Re: Slice: Out of Range Error (RegEx)
« Reply #3 on: March 14, 2020, 08:23:29 PM »
I have the same problem with this function. Could anyone show how to solve it? I can say it's not a matter of empty listbox since it's happening to me when I filter the favorites (when returning, I get the error and AM freezes).

Edit: nevermind, I had another filter for tags (empty)  :P

And the If to test was

Code: [Select]
local test = fe.game_info(Info.Title);
if ( test .len() > 0 ){ //the function }
« Last Edit: March 14, 2020, 08:30:01 PM by l3m35 »