Help with making a script requested

I have a game that I made using VX Ace that I am trying to upgrade to MV. But since MV uses Javascript now, I am trying to create a script based on a script I was using for my game (link: http://cobbtocs.co.uk/wp/?p=54). Since I am new to scripting, I am unsure of whether I am going in the right direction with what I have created so far. Currently, I am able to activate the plugin, but when running the game, there are no errors and the script doesn't function at all. Any help would be appreciated.

View attachment LearnByCast.js
I managed to get the script to crash. I commented out the $gameMessage lines and am now using the debug console to get an idea of how to fix it.
I have completed the script. I will post it here in case anyone else wants to use it.

View attachment LearnByCast.js

Original thread: https://forums.rpgmakerweb.com/threads/help-with-making-a-script-requested.56586/