I know nothing about the dual screen script. I don't know where you've put your code, but I'm pretty sure I know what your problem is.
$Trainer.pokedex is not a method. It's a boolean (a true/false value). It's part of $Trainer, which is defined when the player chooses a name. Before this, though, there's a bit of the game in which your code applies, but $Trainer doesn't exist. Therefore $Trainer.pokedex doesn't exist either, which causes the problem.
What you need to do is replace the problem line with if $Trainer && $Trainer.pokedex==true. This makes sure it only cares about $Trainer.pokedex if $Trainer exists.