Trying to make a simple help window script for battles

Hello everyone, this is the first time I'm posting here because I really don't know how to proceed.

I'm trying to make a very simple help window plugin for my custom combat system. The idea is simple enough; display a window at the top of the screen that gives context to basic actor commands, such as attack, magic, guard and the like. Help text appears when the cursor is placed over the command. I got the window working and the script can identify basic commands without any problems.

Here's the issue; I also decided to add some personalized commands to my actors. These are in fact regular spells that can be selected directly from the actor's command window, and I'm having a lot of trouble with providing a description for them.
As it stands, my plugin is unable to tell the difference between two different skills, it just retrieves "skillID" without being able to identify the precise ID and thus provide the appropriate text in the help window.
I have absolutely no idea how to get the skill's ID, and trust me, I've tried xD ...

Here's what I got so far;

Code:
// Custom descriptions
var commandDescriptions = {
    "attack": "Description of attack",
    "item": "Description of items",
    "skill": "Description of skills",
};

// Trying to get skill ID
function getCommandDescription(command, index) {
    if (command === "skillID") {
        var skillId = index;
        if (skillId && $dataSkills[skillId]) {
            var skill = $dataSkills[skillId];
            if (skill.description !== undefined) {
                return skill.description;
            } else {
                return "No description available";
            }
        } else {
            return "No description available";
        }
    } else {
        // If the command is another predefined command, return the corresponding description
        var description = commandDescriptions[command];
        if (description !== undefined) {
            return description;
        } else {
            return "No description available";
        }
    }
}

// Command checker
Scene_Battle.prototype.updateHelpWindow = function() {
    if (this._helpWindow) {
        var item = this._actorCommandWindow.currentSymbol();
        var index = this._actorCommandWindow.index();

        // Display in the console to check the current command and index
        console.log("Current command:", item);
        console.log("Current index:", index);

        var description;
        if (item === "skillID") {
            description = getCommandDescription(item, index);
        } else {
            description = getCommandDescription(item);
        }
      
        if (description !== null) {
            this._helpWindow.setText(description);
            this._helpWindow.show();
        } else {
            this._helpWindow.clear();
            this._helpWindow.hide();
        }
    }
};

var _alias_scene_battle_window_actor_command_select = Window_ActorCommand.prototype.select;
Window_ActorCommand.prototype.select = function(index) {
    _alias_scene_battle_window_actor_command_select.call(this, index);
    SceneManager._scene.updateHelpWindow();
};

It is probably a bit messy as my understanding of the code is pretty limited, but if anyone can take a look and help me out, I'd be eternally grateful.

Edit : added images for additional context, in case my English is too sucky.
Try using this for the skill id:

JavaScript:
var skillId = BattleManager._action._item._itemId;

In the future, you can find out these things by using the console by pressing F8 or F12(it's different for some) while your game is running. It's your best friend when you are trying to learn how to reference things properly.

Edit* sorry that’s for the current skill being used but you can use the console to figure this out I’m sure.
I'm not very familiar with the console, but I actually used it to write that first part of the script. (You can tell, there's a line that helped me verify if the plugin could identify the command types)

I'm clueless as to how I should proceed, but I'll try your method. Thanks!

Will keep you updated if there's any progress.
It's hard to say exactly what you would want to use. Are you using the actual skill object for the command? This could be what you can use if it was from the skill window itself to get the id:

JavaScript:
var skillId = SceneManager._scene._skillWindow._data[SceneManager._scene._skillWindow.index()].id;

You would then have to change this a little bit to reference the actor command window instead. So something like this:

JavaScript:
var skillId = SceneManager._scene._actorCommandWindow._list[SceneManager._scene._actorCommandWindow.index()].id;

This will only work if you are using the actual skill object in the list. If you are not using the skill object, you will have to define the properties yourself. I hope this helps.
I'm not sure, I'm using another plugin that lets you decide what commands each actor has access when their actor command window appears. It certainly seems like I'm using the skill directly, as the console returns "skillID" when hovering above the command. I'll try a few different methods and will give more info if I manage to make it work, thanks a lot.

As for the plugin, I copy and pasted the entire thing in the first post. It's pretty much all of it.
You could always enter this:

JavaScript:
SceneManager._scene._actorCommandWindow._list

into the console to see if your skill appears in the list as a skill object in the array, and if it does, then the code I gave you should work fine to get the ID. Make sure you are in the actor command window itself when inputting the code into the console.
So, tiny update, I actually managed to get the script to figure out the Skill ID (yay). I also checked with your method after that, just in case, and it is indeed a skill object. Now, all I have to do, is find a way for the script to use the skill ID that was found, and get a description for it.
Typically help windows use the following structure:
Spoiler: description
  • Have the scene associate the parent window with its help window, e.g.
    JavaScript:
    this._actorCommandWindow.setHelpWindow(this._helpWindow);
    One help window can have multiple parents, if appropriate.

  • Define an appropriate updateHelp method for each parent, e.g.
    JavaScript:
    Window_ActorCommand.prototype.updateHelp = function() {
      if (!this._helpWindow) return;
      const symbol = this.currentSymbol();
      const text = commandDescriptions[symbol];
      if (text)
        this._helpWindow.setText(text);
      else if (symbol === "skillID")
        this.setHelpWindowItem($dataSkills[this.currentExt()]);
      else
        this._helpWindow.setText("No description available.");
      // Show iff displaying help text.
      if (this._helpWindow._text) this.showHelpWindow(); else this.hideHelpWindow();
    };

  • updateHelp is called via setHelpWindow, select, etc (cf Window_Selectable). If you ever need to manually update the help, you can use:
    JavaScript:
    this.callUpdateHelp();
For the skill ID thing...you may have noticed currentExt() in the code inside that spoiler. When adding a command, you can specify an ext value:
JavaScript:
this.addCommand(text, symbol, enabled, ext);
This lets you determine the intended use of the command regardless of its index (i.e. its position in the list). The core scripts use this for skill types; I've assumed your skillID commands do the same.
So, tiny update, I actually managed to get the script to figure out the Skill ID (yay). I also checked with your method after that, just in case, and it is indeed a skill object. Now, all I have to do, is find a way for the script to use the skill ID that was found, and get a description for it.

Great, I'm glad you were able to figure it out.
I'm not quite there yet, but... baby steps. I'm studying caethryl's advices as well and I'm currently trying to make sense of all of this. Will keep you guys updated, thank you all for your time.

​

@Matt Black - With your current code, I think you could just replace this:
JavaScript:
description = getCommandDescription(item, index);
...with this:
JavaScript:
description = getCommandDescription(item, this._actorCommandWindow.currentExt());
Sadly, the currentExt method doesn't seem to work for me, although there's a good chance I'm doing it wrong. In any case, changing this line for the one you suggested doesn't do anything. I'm exploring other methods, but so far, even though the console provides me with every single detail, I still can't make use of the ID to get a description. Welp, my shortcomings in the oh so obscure art of coding are starting to become obvious!
Try changing your code to this:
Spoiler: Code
JavaScript:
// Trying to get skill ID
function getCommandDescription(command, index) {
    if (command === "skillID") {
        var skillId = SceneManager._scene._actorCommandWindow._list[index].id;
        if (skillId && $dataSkills[skillId]) {
            var skill = $dataSkills[skillId];
            if (skill.description !== undefined) {
                return skill.description;
            } else {
                return "No description available";
            }
        } else {
            return "No description available";
        }
    } else {
        // If the command is another predefined command, return the corresponding description
        var description = commandDescriptions[command];
        if (description !== undefined) {
            return description;
        } else {
            return "No description available";
        }
    }
}

You have it right from what I can see. Everyone learns their own way. I just helped you get the skill id and replaced one line. Leave the rest of your code the way you had it and see if this helps.
@Dungeonmind Unfortunately, this didn't make a difference, I still get "no description available" whenever the cursor is placed over a skill. I also tried setting a custom description in the plugin for a specific skillID but it doesn't work either, which leads me to believe that for some reason, the script is not getting the ID after all. (Even though I can obtain it with the console)

Here's my current version;
Spoiler: Code
Code:
// Custom Descriptions
var commandDescriptions = {
    "attack": "Description of attack",
    "item": "Description of items",
    "skill": "Description of skills",
};


// Getting Descriptions
function getCommandDescription(command, skillId) {
    // If the command is "skillID"
    if (command === "skillID") {
        if (skillId && $dataSkills[skillId]) {
            var skill = $dataSkills[skillId];
            if (skill && skill.description !== undefined) {
                // If skillID is a specific value (test)
                if (skillId === 103) {
                    return "Custom description for skill ID 103";
                } else {
                    return skill.description;
                }
            }
        }
    } else {
        // If the command is another predefined command, return the corresponding description
        var description = commandDescriptions[command];
        if (description !== undefined) {
            return description;
        }
    }
    return "No description available";
}


// Command checker
Scene_Battle.prototype.updateHelpWindow = function() {
    if (this._helpWindow && this._actorCommandWindow) {
        var item = this._actorCommandWindow.currentSymbol();
        var skillId = this._actorCommandWindow.currentExt();


        // Console logs
        console.log("Current command:", item);
        console.log("Skill ID:", skillId);


        // Get the description for the command
        var description = getCommandDescription(item, skillId);


        // More console logs
        console.log("Description:", description);
       
        if (description !== null) {
            this._helpWindow.setText(description);
            this._helpWindow.show();
        } else {
            this._helpWindow.clear();
            this._helpWindow.hide();
        }
    }
};


var _alias_scene_battle_window_actor_command_select = Window_ActorCommand.prototype.select;
Window_ActorCommand.prototype.select = function(index) {
    _alias_scene_battle_window_actor_command_select.call(this, index);
    SceneManager._scene.updateHelpWindow();
};


I'll try a few other methods after this one, but I think I need some fresh air first :LZSsad:
Try this:

Spoiler: Code
JavaScript:
// Custom Descriptions
var commandDescriptions = {
    "attack": "Description of attack",
    "item": "Description of items",
    "skill": "Description of skills",
};


// Getting Descriptions
Scene_Battle.prototype.getCommandDescription = function(command, skillId) {
    // If the command is "skillID"
    if (command === "skillID") {
        if (skillId) {
            var skill = $dataSkills[skillId];
            if (skill && skill.description) {
                // If skillID is a specific value (test)
                if (skillId === 103) {
                    return "Custom description for skill ID 103";
                } else {
                    return skill.description;
                }
            }
        }
    } else {
        // If the command is another predefined command, return the corresponding description
        var description = commandDescriptions[command];
        if (description !== undefined) {
            return description;
        }
    }
    return "No description available";
}


// Command checker
Scene_Battle.prototype.updateHelpWindow = function() {
    if (this._helpWindow && this._actorCommandWindow) {
        var item = this._actorCommandWindow.currentSymbol();
        var skillId = this._actorCommandWindow.currentExt();


        // Console logs
        console.log("Current command:", item);
        console.log("Skill ID:", skillId);


        // Get the description for the command
        var description = this.getCommandDescription(item, skillId);


        // More console logs
        console.log("Description:", description);
    
        if (description !== null) {
            this._helpWindow.setText(description);
            this._helpWindow.show();
        } else {
            this._helpWindow.clear();
            this._helpWindow.hide();
        }
    }
};


var _alias_scene_battle_window_actor_command_select = Window_ActorCommand.prototype.select;
Window_ActorCommand.prototype.select = function(index) {
    _alias_scene_battle_window_actor_command_select.call(this, index);
    SceneManager._scene.updateHelpWindow();
};
Unfortunately it didn't work, but it gave me an idea and I found this thanks to your help;
Spoiler: Code
Code:
// Custom Descriptions
var commandDescriptions = {
    "attack": "Description of attack",
    "item": "Description of items",
    "skill": "Description of skills",
};




// Getting Descriptions
Scene_Battle.prototype.getCommandDescription = function(command, skillId) {
    // Debug log
    console.log("Getting description for command:", command, "and skill ID:", skillId);
 
    // If the command is "skillId"
    if (command === "skillId") {
        if (skillId && $dataSkills[skillId]) {
            var skill = $dataSkills[skillId];
            if (skill && skill.description) {
                // If skillID is a specific value (test)
                if (skillId === 103) {
                    // I like console logs
                    console.log("Custom description found for skill ID 103");
                    return "Custom description for skill ID 103";
                } else {
                    // More console logs
                    console.log("Description found for skill ID:", skillId);
                    return skill.description;
                }
            }
        }
    } else {
        // If the command is another predefined command, return the corresponding description
        var description = commandDescriptions[command];
        if (description !== undefined) {
            // More console logs, the return
            console.log("Description found for command:", command);
            return description;
        }
    }
    // Even more console logs
    console.log("No description available");
    return "No description available";
}




// Command checker
Scene_Battle.prototype.updateHelpWindow = function() {
    if (this._helpWindow && this._actorCommandWindow) {
        var item = this._actorCommandWindow.currentSymbol();
        var skillId = this._actorCommandWindow.currentExt();


        // Console logs
        console.log("Current command:", item);
        console.log("Skill ID:", skillId);


        // Get the description for the command
        var description = this.getCommandDescription(item, skillId);


        // More console logs
        console.log("Description:", description);
 
        if (description !== "No description available") {
            this._helpWindow.setText(description);
            this._helpWindow.show();
        } else {
            this._helpWindow.clear();
            this._helpWindow.hide();
        }
    }
};




var _alias_scene_battle_window_actor_command_select = Window_ActorCommand.prototype.select;
Window_ActorCommand.prototype.select = function(index) {
    _alias_scene_battle_window_actor_command_select.call(this, index);
    SceneManager._scene.updateHelpWindow();
};

And it works! It's clearly not perfect - it kind of feels applying a piece of duct tape to the bottom of a ship that's just been hit by a torpedo - but the plugin can associate a description to skills from the database AND react to custom descriptions that have been written directly into the script itself. All that's left for me to do is to tweak a few details here and there, and I'll be good to go!

None of this would have been possible without your help. Thank you so much for your valuable time and knowledge, both of you guys.
Ah, yes, it's because it is actually not using the skill object, and it does not have the 'id' property like it does in the skills window. So you indeed have to use:

JavaScript:
this._actorCommandWindow.currentExt();

to get the id.

I'm glad we were able to help you understand some things a bit better. Keep on trying and never give up because you can only get better over time and then eventually this will all be trivial to you.
Ah, yes, it's because it is actually not using the skill object, and it does not have the 'id' property like it does in the skills window.
That is my mistake then, very sorry for this.

Original thread: https://forums.rpgmakerweb.com/threads/trying-to-make-a-simple-help-window-script-for-battles.167101/