oomek/attractplus

Cannot convert the string

Closed this issue · 7 comments

Hi oomek,

I have a theme issue again. Is it a bug since there is no error ruuning on orginial AM.

The action can run on AM+, but show error message.

Thanks

AN ERROR HAS OCCURED [cannot convert the string]

CALLSTACK
*FUNCTION [on_signal()] layout.nut line [626]

LOCALS
[signal] "custom1"
[this] INSTANCE
Script Error in signal handler: on_signal - cannot convert the string

Below is my script

`//Use with the 0-9 buttons to select music

class NumSearch
{
_last_search="";
_trigger="";

constructor()
{
	fe.add_signal_handler( this, "on_signal" )
	_trigger=fe.get_config()["trigger"].tolower();
}

function on_signal( signal )
{
	if ( signal == _trigger )
	{
		_last_search=""
		_last_search = fe.overlay.edit_dialog(
			"Use with the 0-9 buttons to select music:",
			_last_search ).tointeger();

		if ( _last_search < fe.list.size + 1 )
				fe.list.index = _last_search - 1

		return true;
	}

	return false;
}

}

NumSearch()
`

oomek commented

Please provide a minimal working example that shows the error.
The code provided above is not giving me any errors unless I leave the field empty, or enter a letter instead of a number.
Btw you encapsulate the code blocks in triple backquotes ```

you can download the theme in here. The error message will show on attractplus-console message while you press "custom1" key. Thanks

https://www.dropbox.com/scl/fi/fvmk671awus4s51m9gq0n/C.A.T-AM.zip?rlkey=lvr88auks0sh7mkz51tc3hzdl&dl=0

oomek commented

I am not getting any errors
image

oomek commented

As I said, it gives an error only when you enter an invalid character.
You should add some protection to only allow integers to be processed with .tointeger() method

Print to the console the output of _last_search after fe.overlay.edit_dialog() but before .tointeger()

_last_search = fe.overlay.edit_dialog("Use with the 0-9 buttons to select music:", _last_search)
fe.log(_last_search);
_last_search = _last_search.tointeger();

Than

As I said, it gives an error only when you enter an invalid character. You should add some protection to only allow integers to be processed with .tointeger() method

Print to the console the output of _last_search after fe.overlay.edit_dialog() but before .tointeger()

_last_search = fe.overlay.edit_dialog("Use with the 0-9 buttons to select music:", _last_search)
fe.log(_last_search);
_last_search = _last_search.tointeger();

Thank you for coding, the error message is gone now.

One more question, Do you know how to change the font as above popup overlay?

On orginial AM, I can use fe.layout.font = "font/impact.ttf" to change it. But in AM+, it doesn't work. Please advise. Thanks.

oomek commented

Listen, this is not a layout coding helpdesk, but AM+ issue tracker.
You have not even explained what was causing this error and just asked for another advise.
To get help in diagnosing your coding mistakes I encourage you to join our Discord server and ask there.
https://discord.gg/fg5w55Yh

Sorry about it and Thank you for your advise.