MZ Asked an AI to generate a plugin

I asked ChatGPT to generate a plugin to create Speech Balloons. I don't know JS so i'm not sure of how close it is to a fully functional script.

It tells me to use $gamePlayer.createSpeechBalloon("Hello, World!", 100, 100, 200, 100);, which doesn't work ("createSpeechBalloon isnt a function"). But could it serve as a base for something ? Any workaround to make it work ?

Note that I don't actually need such plugin, I was just curious about requesting the AI to generate code, and this is the first plugin idea that went through my mind. I might try something simpler.

Anyway, here's the script :

// Plugin name: Speech Balloon // Author: Your Name // Description: This plugin creates speech balloons above characters' heads /*: * @target MZ * @plugindesc This plugin creates speech balloons above characters' heads * @author Your Name * @help * * To use this plugin, simply call the following script: * * this.createSpeechBalloon(text, x, y, width, height); * * where: * - text: the text to display in the speech balloon * - x: the x position of the speech balloon (in pixels) * - y: the y position of the speech balloon (in pixels) * - width: the width of the speech balloon (in pixels) * - height: the height of the speech balloon (in pixels) * * The speech balloon will be displayed above the character's head for a short period of time, and then it will disappear. * * Example: * * this.createSpeechBalloon("Hello, World!", 100, 100, 200, 100); * */ Game_CharacterBase.prototype.createSpeechBalloon = function(text, x, y, width, height) { // Create a new sprite for the speech balloon var sprite = new Sprite(); // Set the position and size of the speech balloon sprite.x = x; sprite.y = y; sprite.bitmap = new Bitmap(width, height); // Draw the speech balloon shape and text sprite.bitmap.drawSpeechBalloon(0, 0, width, height, 4, true); sprite.bitmap.drawText(text, 0, 0, width, height); // Add the speech balloon sprite to the scene SceneManager._scene.addChild(sprite); // Set a timer to remove the speech balloon after a short period of time setTimeout(function() { SceneManager._scene.removeChild(sprite); }, 2000); };
createSpeechBalloon() is a function, it's created right there in your plugin.

However, the drawSpeechBalloon() method that it calls later on is not. So that's a failure at pretty much point zero.

This hypothetical plugin would need to define the entire graphical layout for a "speech balloon" as no such thing exists in MZ. The closest thing are the icon balloons, and those are a set size with externally defined graphics.

Your AI doesn't have a lot of "I" if its code is relying on calling functions that blatantly don't exist in the rest of the game's engine 😛
createSpeechBalloon() is a function, it's created right there in your plugin.

However, the drawSpeechBalloon() method that it calls later on is not. So that's a failure at pretty much point zero.

This hypothetical plugin would need to define the entire graphical layout for a "speech balloon" as no such thing exists in MZ. The closest thing are the icon balloons, and those are a set size with externally defined graphics.

Your AI doesn't have a lot of "I" if its code is relying on calling functions that blatantly don't exist in the rest of the game's engine 😛
In fairness though it got significantly closer to something that would work than you might expect. Aside from needing that blank filled in, if you added that I think everything else would click in just fine.
A lot would depend on what the Machine Learning tool is trained on. If there was a subset that was trained specifically on RPG Maker code, functions and syntax then it would potentially produce something that would be more consistent with the product's design.

Many of these tools are also limited by the original coding teams designs or understanding of the domain for which they are trying to generate code and the type of training they use(d.) Some systems will use pre-conceptions made by the original team as to what constitutes 'proper' coding etc. while others will have the system trying to learn the rules from examining millions of coding examples to correct or improve it's results. Often it ends coming down to humans needing to analyse the output and deciding if it's 'good' or bad and sometimes human bias can come into play (coding styles etc.)

I detest the term Artificial Intelligence as nothing done so far remotely comes to earning that moniker. The original paper where the term was coined has long been forgotten and only the term AI continued to keep the field alive. Only modern scalable architecture and 'relatively' cheap processing power have made more advances possible. I think if any company ever does develop a 'real' self-aware artificial intelligence then they would rue the day - They would potentially be on the hook to keep it 'alive' forever by maintaining continuous power, maintaining it's hardware etc. even if the AI refused to do their bidding. One can't assume a true AI would have (or would be bound by) the same ethical standards of humans but that is a debate better left for philosophers.
The drawSpeechBalloon method is just to draw the balloon shape/background. You can comment out the line that calls it and the plugin will work, though it won't be pretty: the text, in default HTML font, will display for 2 seconds and then abruptly disappear.

Typically you'd use define a new game window class for this kind of thing, rather than use an unclassed sprite. 2 big flaws with this implementation:
  1. Memory leak: the sprite gets removed from the scene, OK. But it blits text to its base texture, so the bitmap should be destroyed (technical term) to allow its edited base texture to be cleared from memory. Game windows handle this automatically.

  2. Display layer: these "balloons" do not respect the engine's container arrangement, e.g. they will display on top of the game window layer (Show Text, Show Choices, etc).
The balloons also lack a persistent reference (important if, for example, you wanted to animate its position or opacity) and setTimeout is used rather than counting frames in the main game loop.

It's not far off being functional, and I've seen worse, but I wouldn't say it's close to being good.

Original thread: https://forums.rpgmakerweb.com/threads/asked-an-ai-to-generate-a-plugin.153462/