After a night of sleep, I manage to got the problem.
The lines was put in a wrong file (this script uses multiple files with scripts inside each one). These lines must the put in the main file, and not in the "sub-files".
Another thing I got was other error messages. First, I added some commands to make your command runs only at the player select screen, and just while the player don't confirm the character. After that, I got a different error. I make tests neutralizing some lines of your example and found out the line "while true do" was the final problem. I just removed it and everything is running flawless.
In the end, the lines become this (just bellow the "function cheat()" line):
Language: lua
--Boss Select
t = {10,21,30,31}
a=0
curr = memory.readbyte(0xFF8502)
for i=1,4 do
if curr == t[i] then
a=i
end
end
if memory.readbyte(0xffbe52) == 0xFF and
memory.readbyte(0xffbed2) == 0xFF and
memory.readbyte(0xffbcca) == 0x00 then
if memory.readword(0xFF8060)==256 then
memory.writebyte(0xFF8502,t[(a%4)+1])
end
end
I changed the memory.readword(0xFF8060) value from 1 to 256 to make the character change when the Start button is pressed, not when it is released. The final two lines of your code ("emu.frameadvance()" and "end") was already present in the files. So, no need to have redundant lines, do you agree?
Now everything is perfect. For the Player 1...
From now, I can play with the lines of your help, and try other possibilities with this script. First, I'll try to change the command to change the characters to see it's possible to make the thing work more elegantly (like put to change the characters with left and right). But, of course, I must change other variants with the memory.readword(0xFF8060), once it registers the P2's Start Button press as well.
Anyway, I must say thank you for all the help and attention. You guys are amazing!! Again, thanks you!!
EDIT: Added the "a=0" into the code.