- Joined
- Sep 12, 2018
- Messages
- 25
- Reaction score
- 6
- First Language
- English
- Primarily Uses
- RMMZ
Hi,
I've been using the ButtonPicture plugin that Rpg Maker MZ comes bundled with and by itself, it worked nice.
For those who aren't aware of it, it's a short plugin that allows for plugin calls that will make clicking on a picture run a Common Event.
Then later on I found @Artille 's ButtonPicture.js v1.01, which expands on it by adding the ability to pass a variable ID and value to the Commont Event of your liking.
Then later on I decided to expand on it myself - first off, by letting you choose if you want to simply run a Common Event (as the original plugin did) OR run it and pass values (so Artille's 1.01 version) - as you sometimes might prefer one option over the other. But then, I also wanted to add the ability to call an event on the map itself - and again, have the option to simply run it OR run and pass a variable with a value.
At first it seemed to work fine, as by checking both Rpg Maker's F9 variables debug and Java's console it seemed to correctly assign the variables. But no, it's not working at all - and I believe this might extend to Artille's version too. While it's fine on the surface (even when printing variables during messages), it completely fails any IF check that runs in any event, be it Common or in a map. It DOES seem to assign something, as it wouldn't recognize the variable as "0" anymore, but it also won't assign the specified variable either. I really have no idea what's causing this behaviour.
I've copied the code in the spoiler tag down below in the hope that someone can spot what's haywiring Rpg Maker MZ here - also I'm sorry if it turns out the answer is extremely simplistic - while I did my best to investigate this and asked around, I am far from tech-savvy when it comes to Javascript, and I know next to zero about the internals of Rpg Maker.
Thanks in advance for any help!
I've been using the ButtonPicture plugin that Rpg Maker MZ comes bundled with and by itself, it worked nice.
For those who aren't aware of it, it's a short plugin that allows for plugin calls that will make clicking on a picture run a Common Event.
Then later on I found @Artille 's ButtonPicture.js v1.01, which expands on it by adding the ability to pass a variable ID and value to the Commont Event of your liking.
Then later on I decided to expand on it myself - first off, by letting you choose if you want to simply run a Common Event (as the original plugin did) OR run it and pass values (so Artille's 1.01 version) - as you sometimes might prefer one option over the other. But then, I also wanted to add the ability to call an event on the map itself - and again, have the option to simply run it OR run and pass a variable with a value.
At first it seemed to work fine, as by checking both Rpg Maker's F9 variables debug and Java's console it seemed to correctly assign the variables. But no, it's not working at all - and I believe this might extend to Artille's version too. While it's fine on the surface (even when printing variables during messages), it completely fails any IF check that runs in any event, be it Common or in a map. It DOES seem to assign something, as it wouldn't recognize the variable as "0" anymore, but it also won't assign the specified variable either. I really have no idea what's causing this behaviour.
I've copied the code in the spoiler tag down below in the hope that someone can spot what's haywiring Rpg Maker MZ here - also I'm sorry if it turns out the answer is extremely simplistic - while I did my best to investigate this and asked around, I am far from tech-savvy when it comes to Javascript, and I know next to zero about the internals of Rpg Maker.
JavaScript:
//=============================================================================
// RPG Maker MZ - Button Picture
//=============================================================================
/*:
* @target MZ
* @plugindesc Makes a picture clickable & Adds variable control.
* @author Yoji Ojima
*
* @help ButtonPicture.js
*
* This plugin provides a command to call a common event when a picture is
* clicked.
*
* Use it in the following procedure.
* 1. Execute "Show Picture" to display your button image.
* 2. Call the plugin command "Set Button Picture".
* 3. Set Variable ID and value to assign to said Picture ID.
*
* @command commonevent
* @text Common event
* @desc Calls common event.
*
* @arg pictureId
* @type number
* @min 1
* @max 100
* @default 1
* @text Picture Number
* @desc Control number of the picture.
*
* @arg commonEventId
* @type common_event
* @default 1
* @text Common Event
* @desc Common event to call when the picture is clicked.
* @command commoneventargs
* @text Common event with args
* @desc Calls common event while passing additional arguments.
*
* @arg pictureId
* @type number
* @min 1
* @max 100
* @default 1
* @text Picture Number
* @desc Control number of the picture.
*
* @arg commonEventId
* @type common_event
* @default 1
* @text Common Event
* @desc Common event to call when the picture is clicked.
*
* @arg VariableId
* @type variable
* @default 1
* @text Variable ID
* @desc Variable used to attribute a value to the comment event call.
*
* @arg VariableValue
* @type text
* @default 1
* @text Variable Value
* @desc Value given to determine how the common event should react.
* @command roomevent
* @text Map event
* @desc Calls event on the current map
*
* @arg pictureId
* @type number
* @min 1
* @max 100
* @default 1
* @text Picture Number
* @desc Control number of the picture.
*
* @arg roomEventId
* @type number
* @default 1
* @text Map Event ID
* @desc Map event to call when the picture is clicked.
* @command roomeventargs
* @text Map event with args
* @desc Calls event on the current map while passing additional arguments.
*
* @arg pictureId
* @type number
* @min 1
* @max 100
* @default 1
* @text Picture Number
* @desc Control number of the picture.
*
* @arg roomEventId
* @type number
* @default 1
* @text Map Event ID
* @desc Map event to call when the picture is clicked.
*
* @arg VariableId
* @type variable
* @default 1
* @text Variable ID
* @desc Variable used to attribute a value to the map event call.
*
* @arg VariableValue
* @type text
* @default 1
* @text Variable Value
* @desc Value given to determine how the event should react.
*
*/
(() => {
'use strict';
const pluginName = "ButtonPicture";
PluginManager.registerCommand(pluginName, "commoneventargs", args => {
const pictureId = Number(args.pictureId);
const commonEventId = Number(args.commonEventId);
const variableId = Number(args.VariableId);
const variableValue = args.VariableValue;
const picture = $gameScreen.picture(pictureId);
if (picture) {
picture.mzkp_commonEventId = commonEventId;
picture.mzkp_variableId = variableId;
picture.mzkp_variableValue = variableValue;}
});
PluginManager.registerCommand(pluginName, "commonevent", args => {
const pictureId = Number(args.pictureId);
const commonEventId = Number(args.commonEventId);
const picture = $gameScreen.picture(pictureId);
if (picture) {
picture.mzkp_commonEventId = commonEventId;}
});
PluginManager.registerCommand(pluginName, "roomeventargs", args => {
const pictureId = Number(args.pictureId);
const roomEventId = Number(args.roomEventId);
const variableId = Number(args.VariableId);
const variableValue = args.VariableValue;
const picture = $gameScreen.picture(pictureId);
if (picture) {
picture.mzkp_roomEventId = roomEventId;
picture.mzkp_variableId = variableId;
picture.mzkp_variableValue = variableValue;
}
});
PluginManager.registerCommand(pluginName, "roomevent", args => {
const pictureId = Number(args.pictureId);
const roomEventId = Number(args.roomEventId);
const picture = $gameScreen.picture(pictureId);
if (picture) {
picture.mzkp_roomEventId = roomEventId;
}
});
Sprite_Picture.prototype.isClickEnabled = function() {
const picture = this.picture();
return picture && !$gameMessage.isBusy();
};
Sprite_Picture.prototype.onClick = function() {
if(this.picture().mzkp_roomEventId)
{
if(this.picture().mzkp_variableId)
$gameVariables.setValue(this.picture().mzkp_variableId,this.picture().mzkp_variableValue);
$gameMap.event(this.picture().mzkp_roomEventId).start();
}
else
{
$gameTemp.reserveCommonEvent(this.picture().mzkp_commonEventId);
if(this.picture().mzkp_variableId)
$gameVariables.setValue(this.picture().mzkp_variableId,this.picture().mzkp_variableValue);
}
};
Spriteset_Base.prototype.mzkp_isAnyPicturePressed = function() {
return this._pictureContainer.children.some(sprite =>
sprite.isPressed()
);
};
const _Scene_Map_isAnyButtonPressed =
Scene_Map.prototype.isAnyButtonPressed;
Scene_Map.prototype.isAnyButtonPressed = function() {
return (
_Scene_Map_isAnyButtonPressed.apply(this, arguments) ||
this._spriteset.mzkp_isAnyPicturePressed()
);
};
})();
Thanks in advance for any help!