Pixel Game Maker MV

Pixel Game Maker MV

评价数不足
Plugins Made Easy
由 Baz 制作
Making plugins in Pixel Game Maker MV can be very beneficial to your projects and to the community. If you can make a simple script, then you can definitely make a plugin, it is that easy! In this guide you will be provided with the following:
  • Plugin templates with explanations
  • Parameter templates with explanations
  • Baz functions
This guide is a WIP. I will continue to update this guide by adding new functions, templates, and examples. I have already used this guide a ton in my own projects and will make videos that support and add to this guide in the future. Hope this helps you advance in PGMMV!

Special Thanks:
  • Joe
  • Beenbaba
  • Standard Enemy
These developers paved the way for PGMMV to reach this next level of Plugins Made Easy! Enjoy!

baz
   
奖励
收藏
已收藏
取消收藏
----- Plugin Templates -----
API Documentation[tkool.jp]
Base
(function(){ var obj = {}; obj.internal = {}; obj.getInfo = function(category){ if(category == 'name'){ return "Plug-in Name"; } else if(category == 'description'){ return "Plug-in Description"; } else if(category == 'author'){ return "Plug-in Author"; } else if(category == 'help'){ return "Plug-in Help"; } else if(category == 'parameter'){ return []; } else if(category == 'internal'){ return obj.internal; } else if(category == 'actionCommand'){ return []; } else if(category == 'linkCondition'){ return []; } return null; }; obj.initialize = function(settings){ }; obj.finalize = function(){ }; obj.setLocale = function(_locale){ }; obj.setInternal = function(settings){ obj.internal = settings; }; obj.setParamValue = function(param){ }; obj.call = function(name, param1, param2){ }; obj.update = function(dt){ }; obj.execActionCommand = function(index, valueJson, objectId, instanceId, actionId, commandId){ var paramId = obj.getInfo("actionCommand")[index].id; valueJson = obj.completeValueJson(index, valueJson, "actionCommand"); switch(paramId){ case 1: break; } return Agtk.constants.actionCommands.commandBehavior.CommandBehaviorNext; }; obj.execLinkCondition = function(index, valueJson, objectId, instanceId, actionLinkId){ var paramId = obj.getInfo("linkCondition")[index].id; valueJson = obj.completeValueJson(index, valueJson, "linkCondition"); switch(paramId){ case 1: break; } return false; }; obj.completeValueJson = function(index, valueJson, type){ var vj = obj.getInfo(type)[index]; var parameter = vj.parameter; if(!!parameter){ var paramLen = parameter.length; for(var _i = 0; _i < paramLen; _i++){ var id = parameter[_i].id; var found = false; var valueLen = valueJson.length; for(var j = 0; j < valueLen; j++){ if(valueJson[j].id == id){ found = true; break; } } if(!found){ valueJson.push({id: id, value: parameter[_i].defaultValue}); } } } return valueJson; }; obj.getValueJson = function(valueJson, id){ var len = valueJson.length; for(var _i = 0; _i < len; _i++){ if(valueJson[_i].id == id){ return valueJson[_i].value; } } return null; }; return obj; }())
Base With Comments
(function(){ // # Comments by Joe. var obj = {}; obj.internal = {}; obj.getInfo = function(category){ if(category == 'name'){ return "Plug-in Name"; } else if(category == 'description'){ return "Plug-in Description"; } else if(category == 'author'){ return "Plug-in Author"; } else if(category == 'help'){ return "Plug-in Help"; } else if(category == 'parameter'){ // # Parameters of this Plug-in. // return [{id: 1, name: "Select the Image", type: "ImageId", defaultValue: -1}] return []; } else if(category == 'internal'){ // # Run at the moment of saving. // # Must be defined to return JSON format. // return null; // if you don't use return obj.internal; } else if(category == 'actionCommand'){ // # Parameters of action commands. // # The process is defined in obj.execActionCommand // return []; // if you don't use return [ {id: 1, name: '[ActionCommand1]', description: 'description', parameter: [ {id: 1, name: 'Number:', type: 'Number', defaultValue: 0} ]}, {id: 2, name: '[ActionCommand2]', description: 'description', parameter: []} ]; } else if(category == 'linkCondition'){ // # Parameters of link conditions. // # The process is defined in obj.execLinkCondition // return []; // if you don't use return [ {id: 1, name: '[LinkCondition1]', description: 'description', parameter: [ {id: 1, name: 'Number:', type: 'Number', defaultValue: 0} ]}, {id: 2, name: '[LinkCondition2]', description: 'description', parameter: []} ]; } return null; }; obj.initialize = function(settings){ // # Runs immediately after the plug-in is loaded into the game or editor. }; obj.finalize = function(){ // # Runs when the plug-in is unloaded. }; obj.setLocale = function(_locale){ // # For setting the language of the plug-in. // # Runs immediately after the plug-in is loaded into the game or editor. // var ja = _locale.substr(0, 2) == 'ja'; }; obj.setInternal = function(settings){ // # Runs immediately after loading. // # Used when the data of the plug-in is kept by save load. // # If you don't use it, don't need the code below. obj.internal = settings; }; obj.setParamValue = function(param){ // # Used when setting the parameters in a action or link. }; obj.call = function(name, param1, param2){ // # This is a dedicated function for auto tiles and is not normally used. }; obj.update = function(dt){ // # Runs every frame on the game side. 'dt' is the delta time. (1 / dt is FPS) }; obj.execActionCommand = function(index, valueJson, objectId, instanceId, actionId, commandId){ // # Action Commands var paramId = obj.getInfo("actionCommand")[index].id; valueJson = obj.completeValueJson(index, valueJson, "actionCommand"); switch(paramId){ // # Branch the command where is executed by paramId. case 1: // # id: 1 Agtk.log("[ActionCommand1] is executed."); // You can check in the runtime log. var paramValue = obj.getValueJson(valueJson, 1); // Gets the value of the parameter id: 1. (Numeric input value) Agtk.log("The parameter entered for [ActionCommand1] is "+paramValue+"."); break; case 2: // # id: 2 Agtk.log("[ActionCommand2] is executed."); break; } // # The behavior of the action after executing the command is selected. // # In addition to Next (transition to the next command), there are Loop, Block, Break. return Agtk.constants.actionCommands.commandBehavior.CommandBehaviorNext; }; obj.execLinkCondition = function(index, valueJson, objectId, instanceId, actionLinkId){ // # Link Conditions var paramId = obj.getInfo("linkCondition")[index].id; valueJson = obj.completeValueJson(index, valueJson, "linkCondition"); switch(paramId){ case 1: // # id: 1 Agtk.log("[LinkCondition1] is executed."); var ten = 10; return ten > 5; // # true break; case 2: // # id: 2 Agtk.log("[LinkCondition2] is executed."); var ten = 10; return ten < 5; // # false break; } // Have to the link condition returns a true or false result. return false; }; obj.completeValueJson = function(index, valueJson, type){ // # Formats and returns the parameter JSON (valueJson). var vj = obj.getInfo(type)[index]; var parameter = vj.parameter; if(!!parameter){ var paramLen = parameter.length; for(var _i = 0; _i < paramLen; _i++){ var id = parameter[_i].id; var found = false; var valueLen = valueJson.length; for(var j = 0; j < valueLen; j++){ if(valueJson[j].id == id){ found = true; break; } } if(!found){ valueJson.push({id: id, value: parameter[_i].defaultValue}); } } } return valueJson; }; obj.getValueJson = function(valueJson, id){ // # Extracts the value of the specified id from the parameter JSON. var len = valueJson.length; for(var _i = 0; _i < len; _i++){ if(valueJson[_i].id == id){ return valueJson[_i].value; } } return null; }; return obj; }())
Base With Baz Functions
(function(){ var obj = {}; obj.internal = {}; var baz = { // USEFUL FUNCTIONS Log: function(event){ return Agtk.log(event); }, Lerp: function(start, end, time){ var _dist = (1 - time) * start + time * end; return Math.round(_dist * 10) / 10; }, GetRandomNumberRange: function(min, max){ min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max - min) + min); }, ConvertTimeTo300: function(timeToConvert){ return timeToConvert * 300; }, GetAngleAway: function(startX, startY, endX, endY){ var _pi = Math.PI; var _x = startX - endX; var _y = endY - startY; var _angle = Math.atan2(_x, _y) * (180 / _pi); return (_angle < 0) ? (360 + _angle) : _angle; }, GetAngleToward: function(startX, startY, endX, endY){ var _pi = Math.PI; var _x = endX - startX; var _y = startY - endY; var _angle = Math.atan2(_x, _y) * (180 / _pi); return (_angle < 0) ? (360 + _angle) : _angle; }, // INPUT RELATED FUNCTIONS IsKeyPressed: function(keyId){ for(var i = 0; i <= Agtk.controllers.MaxControllerId; i++){ if(Agtk.controllers.getOperationKeyPressed(i, keyId)){ return true; } } }, // INSTANCE RELATED FUNCTIONS GetSelf: function(instance){ return Agtk.objectInstances.get(instance); }, GetOtherInstance: function(nameOrId){ if(isNaN(nameOrId)){ return Agtk.objectInstances.get(Agtk.objectInstances.getIdByName(-1, nameOrId)); } return Agtk.objectInstances.get(nameOrId); }, GetParentInstance: function(childNameOrId){ var _child; if(isNaN(childNameOrId)){ _child = Agtk.objectInstances.get(Agtk.objectInstances.getIdByName(-1, childNameOrId)); }else{ _child = Agtk.objectInstances.get(childNameOrId); } var _parentId = _child.variables.get(_child.variables.ParentObjectInstanceIDId).getValue(); return Agtk.objectInstances.get(_parentId); }, GetAttackerInstance: function(instance){ var _attackerList = instance.getAttackerInstanceIdList(); for(var attacker in _attackerList){ return Agtk.objectInstances.get(_attackerList[attacker]); } }, // INSTANCE SWITCH/VARIABLE RELATED FUNCTIONS GetInstanceSwitch: function(instance, nameOrId){ if(isNaN(nameOrId)){ return instance.switches.get(instance.switches.getIdByName(nameOrId)).getValue(); } return instance.switches.get(nameOrId).getValue(); }, SetInstanceSwitch: function(instance, nameOrId, value){ if(isNaN(nameOrId)){ instance.switches.get(instance.switches.getIdByName(nameOrId)).setValue(value); return; } instance.switches.get(nameOrId).setValue(value); }, GetInstanceVariable: function(instance, nameOrId){ if(isNaN(nameOrId)){ return instance.variables.get(instance.variables.getIdByName(nameOrId)).getValue(); } return instance.variables.get(nameOrId).getValue(); }, SetInstanceVariable: function(instance, nameOrId, value){ if(isNaN(nameOrId)){ instance.variables.get(instance.variables.getIdByName(nameOrId)).setValue(value); return; } instance.variables.get(nameOrId).setValue(value); }, // COMMON SWITCH/VARIABLE RELATED FUNCTIONS GetCommonSwitch: function(nameOrId){ if(isNaN(nameOrId)){ return Agtk.switches.get(Agtk.switches.getIdByName(nameOrId)).getValue(); } return Agtk.switches.get(nameOrId).getValue(); }, SetCommonSwitch: function(nameOrId, value){ if(isNaN(nameOrId)){ Agtk.switches.get(Agtk.switches.getIdByName(nameOrId)).setValue(value); return; } Agtk.switches.get(nameOrId).setValue(value); }, GetCommonVariable: function(nameOrId){ if(isNaN(nameOrId)){ return Agtk.variables.get(Agtk.variables.getIdByName(nameOrId)).getValue(); } return Agtk.variables.get(nameOrId).getValue(); }, SetCommonVariable: function(nameOrId, value){ if(isNaN(nameOrId)){ Agtk.variables.get(Agtk.variables.getIdByName(nameOrId)).setValue(value); return; } Agtk.variables.get(nameOrId).setValue(value); } } obj.getInfo = function(category){ if(category == 'name'){ return "Plug-in Name"; } else if(category == 'description'){ return "Plug-in Description"; } else if(category == 'author'){ return "Plug-in Author"; } else if(category == 'help'){ return "Plug-in Help"; } else if(category == 'parameter'){ return []; } else if(category == 'internal'){ return obj.internal; } else if(category == 'actionCommand'){ return []; } else if(category == 'linkCondition'){ return []; } return null; }; obj.initialize = function(settings){ }; obj.finalize = function(){ }; obj.setLocale = function(_locale){ }; obj.setInternal = function(settings){ obj.internal = settings; }; obj.setParamValue = function(param){ }; obj.call = function(name, param1, param2){ }; obj.update = function(dt){ }; obj.execActionCommand = function(index, valueJson, objectId, instanceId, actionId, commandId){ var paramId = obj.getInfo("actionCommand")[index].id; valueJson = obj.completeValueJson(index, valueJson, "actionCommand"); switch(paramId){ case 1: // EXAMPLE HOW TO USE BAZ FUNCTION USE baz.Log("Hello World!"); break; } return Agtk.constants.actionCommands.commandBehavior.CommandBehaviorNext; }; obj.execLinkCondition = function(index, valueJson, objectId, instanceId, actionLinkId){ var paramId = obj.getInfo("linkCondition")[index].id; valueJson = obj.completeValueJson(index, valueJson, "linkCondition"); switch(paramId){ case 1: break; } return false; }; obj.completeValueJson = function(index, valueJson, type){ var vj = obj.getInfo(type)[index]; var parameter = vj.parameter; if(!!parameter){ var paramLen = parameter.length; for(var _i = 0; _i < paramLen; _i++){ var id = parameter[_i].id; var found = false; var valueLen = valueJson.length; for(var j = 0; j < valueLen; j++){ if(valueJson[j].id == id){ found = true; break; } } if(!found){ valueJson.push({id: id, value: parameter[_i].defaultValue}); } } } return valueJson; }; obj.getValueJson = function(valueJson, id){ var len = valueJson.length; for(var _i = 0; _i < len; _i++){ if(valueJson[_i].id == id){ return valueJson[_i].value; } } return null; }; return obj; }())
----- Parameter Templates -----
Action & Conditions Commands
Blank Action Command
{id: 1, name: 'Action 1', description: 'Action 1 does this.', parameter: []}

Blank Link Condition
{id: 1, name: 'Condition 1', description: 'Condition 1 does this.', parameter: []}
Parameters
Blank Parameters
{id: 0, name: '', type: '', defaultValue: 0}
Custom Parameters
Blank Custom Parameters
{id: 0, name: ''}
----- Parameter Types -----
This section is for copy/pastable parameter types. The sections following this will show examples and any sub types required for each one of the above! (note: I left the comma at the end of each type because typically you will want a , afterwards to continue the args)

type: 'String', type: 'MultiLineString', type: 'Number', type: 'Json', type: 'ImageId', type: 'TextId', type: 'SceneId', type: 'TilesetId', type: 'AnimationId', type: 'ObjectId', type: 'FontId', type: 'MovieId', type: 'BgmId', type: 'SeId', type: 'VoiceId', type: 'VariableId', type: 'SwitchId', type: 'AnimOnlyId', type: 'PortalId', type: 'CustomId', type: 'Embedded', type: 'EmbeddedEditable', type: 'SwitchVariableObjectId',

Some types have extension args:
//Number minimumValue: 0, maximumValue: 10, //TextId withNewButton: true, //VariableId referenceId: 0, withNewButton: true,
String
type: 'String',
  • String is for using a single lined string as values inside the plugin
  • Example could be for an object name to reference instead of using the traditional way of selecting an object from the drop down menu (note: example is of a global parameter):
    {id: 1, name: 'Name of Object:', type: 'String', defaultValue: 'player1'}
MultiLineString
type: 'MultiLineString',
  • MultiLineString is for using multi-line strings as values inside the plugin
  • Not sure an exact example for this, but I'll show what it looks like. (note: example is of a global parameter and also the use of \n for next line in the defaultValue):
    {id: 1, name: 'Name of Objects:', type: 'MultiLineString', defaultValue: 'player1\nplayer2'}
Number
type: 'Number',
  • Number is for using numbers as values inside the plugin
  • Example is for using the value for an x coordinate. (note: example is of a global parameter):
    {id: 1, name: 'Example Number:', type: 'Number', defaultValue: 0}


  • You can extend this to also include a Minimum and Maximum value:
    {id: 1, name: 'Example Number:', type: 'Number', minimumValue: 0, maximumValue: 10, defaultValue: 0}
Json
type: 'Json',
  • Json is for using JSON text strings inside the plugin
  • I have no examples of using this type
ImageId
type: 'ImageId',
  • ImageId is for selecting an image resource as the value inside the plugin
  • Example, note that -1 defaultValue = Not Set:
    {id: 1, name: 'Example Image ID:', type: 'ImageId', defaultValue: -1}
TextId
type: 'TextId',
  • TextId is for selecting a text resource as the value inside the plugin
  • Example, note that -1 defaultValue = Not Set:
    {id: 1, name: 'Example Text ID:', type: 'TextId', defaultValue: -1}


  • You can extend this to also include a 'New' button to create text resource (note: withNewButton is true/false):
    {id: 1, name: 'Example Text ID:', type: 'TextId', withNewButton: true, defaultValue: -1}
SceneId
type: 'SceneId',
  • SceneId is for selecting a scene index as the value inside the plugin
  • Example, note that -1 defaultValue = Not Set:
    {id: 1, name: 'Example Scene ID:', type: 'SceneId', defaultValue: -1}
TilesetId
type: 'TilesetId',
  • TilesetId is for selecting a tileset index as the value inside the plugin
  • Example, note that -1 defaultValue = Not Set:
    {id: 1, name: 'Example Tileset ID:', type: 'TilesetId', defaultValue: -1}
----- How To -----
Add/Update Custom Plugins
Adding Custom Plugins:
  1. Click on 'Plug-ins' tab inside editor
  2. Right click anywhere in the plugin list and click 'Add Plug-in'
  3. With the new plugin highlighted click the 'Load' button
  4. Select the directory, click on custom plugin to add and click open
  5. Rename your plugin on the left to keep organized
  6. Done!


Updating Custom Plugins:
  1. Save the plugin inside your text editor (ie. Visual Studio Code)
  2. Click on 'Plug-ins' tab inside PGMMV editor
  3. Click to highlight the plugin to be updated
  4. Click Update button (note you may need to find the directory again if you moved file)
  5. Done!
Add Runtime Actions
All runtime actions you desire to have in the plugin will go here:



You can have as many runtime actions as you need, but make sure to number the id's accordingly (note this is a barebone example, you can add a lot to customize the settings inside the action):



After saving the plugin and Updating it inside the editor, you can see already these runtime actions are available, both in the 'Plug-ins' tab and the 'Other Runtime Actions' window:





Now these runtime actions need logic. So go down to the obj.execActionCommand section of the plugin and add the logic for each id. In this example we will just use Agtk.log to show they were used:



Don't forget to save the plugin and Update it in the Plug-ins tab again!

Now when we add these runtime actions to the game and playtest, we can see they ran their appropriate logic:





And that is it! Notice you don't need any parameters if you don't want. You can purely use them as you would a normal Execute Script, but using plugin commands instead of normal scripts makes them more scalable because of how easy it is to update plugins.
Add Link Conditions
All link conditions you desire to have in the plugin will go here:


You can have as many link conditions as you need, but make sure to number the id's accordingly (note this is a barebone example, you can add a lot to customize the settings inside the condition):



After saving the plugin and Updating it inside the editor, you can see already these link conditions are available, both in the 'Plug-ins' tab and the 'Other Condition Settings' window:





Now these link conditions need logic. So go down to the obj.execLinkCondition section of the plugin and add the logic for each id. In this example we will just use Agtk.log to show they are being used:



Remember that link conditions need a 'return true;' in order for the link to activate. Here is a quick example of what that would look like:



Don't forget to save the plugin and Update it in the Plug-ins tab again!

Now when we add these link conditions to the game and playtest, we can see they ran their appropriate logic. Note that the conditions are OR's in this example so we can check them all. For instance, if they were all AND's it would only check the condition 1 and if that wasn't true it would restart the check, meaning condition 2 and 3 would never be ran until condition 1 is true first (this can be a useful tip!):






And that is it! Notice you don't need any parameters if you don't want. You can purely use them as you would a normal Execute Script, but using plugin commands instead of normal scripts makes them more scalable because of how easy it is to update plugins.
Add Parameters
There are three places you can add parameters:

First, the 'parameter' category are parameters that are universal and will always be the same no matter which objects you are calling the action/conditions from. You can simply use the param/custom params templates for them:



These are the parameters you find in the 'Change Parameter' section in the Plug-ins tab:



The next two parameter types are found in the 'actionCommand' and 'linkCondition' categories. They work the in the same fashion, you add as many param/custom params that you need. The only difference is that these need to be embedded inside an Action or Condition block, unlike the main parameter.

Let's look at actionCommand first. Here is a simple setup for adding parameters inside the action:



The above setup gives us this in the editor (I'm using the Plug-in Preview for ease, but you will see these actions individually inside objects):




Lastly, let's look at linkCondition. Params are setup the same as actionCommand's, but I wanted to show different types for examples (specifically how to add blank spaces between params):



And this is how it looks in the editor:

Get Parameter Value
Remember there are three areas to fill out parameters:

- Global
- Runtime Actions
- Link Conditions



Now the question is, how do we get those values to the place where the logic is (ie. in the areas shown below):



Getting global parameters will be different then getting Runtime Action/Link Condition parameters. So let's begin with global ones.

First, global parameters need to be specified in their own obj.setParamValue function. Note this function comes with the plugin templates. In this example you can see that global parameter 1 is being set to obj.globalParameter1 (the name can be anything, ie. obj.anyName):



Once we have set the global parameters, we can now call their values at will in both Runtime Actions and Link Conditions:



And that is for global parameters!

Now let's look at calling Runtime Action/Link Condition parameters. They are similar but do not require setup in another function. Any time you call a parameter you will use command obj.getValueJson(valueJson, ID#) and that will return the parameter based on the ID. In the example below you see the value being got from the action and another one from the condition. Note that both ID's are the same #, but because they are in different sections (action vs condition) they will pull from their specific areas in the plugin:



And that is the basics of getting parameter values!
----- Explanations -----
Obj Functions
obj.getInfo
  • Setup basic info that appears inside the editors Plugin tab
  • Setup plugin parameters
  • Setup behavior when saving
  • Setup runtime actions
  • Setup link conditions
obj.initialize
  • Runs immediately after the plug-in is loaded into the game or editor.
obj.finalize
  • Runs when the plug-in is unloaded.
obj.setLocale
  • For setting the language of the plug-in.
  • Runs immediately after the plug-in is loaded into the game or editor.
obj.setInternal
  • Runs immediately after loading.
  • Used when the data of the plug-in is kept by save load.
obj.setParamValue
  • Used when setting the parameters in a action or link.
obj.call
  • This is a dedicated function for auto tiles and is not normally used.
obj.update
  • Runs every frame on the game side. 'dt' is the delta time. (1 / dt is FPS)
obj.execActionCommand
  • Runtime Actions
  • Each case represents a unique Runtime Action
  • The behavior of the action after executing the command is selected, there are Loop, Block, Break
obj.execLinkCondition
  • Link Conditions
  • Each case represents a unique Link Condition
  • Have the link condition returns a true or false result.
obj.completeValueJson
  • Formats and returns the parameter JSON (valueJson)
obj.getValueJson
  • Extracts the value of the specified id from the parameter JSON
Baz Functions
What are Baz Functions?
Baz Functions are the same as the Power Functions you find in my Scripting Made Easy guide. They have been converted to work inside of plugins. Not every function was able to convert though, for instance the power function GetSelf() that you commonly see me use in my video's was unable to be used in plugin form, since helper functions cannot read 'instanceId'. I will continue to add and update these functions as needed:

Baz Functions Complete Template:
var baz = { // USEFUL FUNCTIONS Log: function(event){ return Agtk.log(event); }, Lerp: function(start, end, time){ var _dist = (1 - time) * start + time * end; return Math.round(_dist * 10) / 10; }, ConvertTimeTo300: function(timeToConvert){ return timeToConvert * 300; }, GetAngleAway: function(startX, startY, endX, endY){ var _pi = Math.PI; var _x = startX - endX; var _y = endY - startY; var _angle = Math.atan2(_x, _y) * (180 / _pi); return (_angle < 0) ? (360 + _angle) : _angle; }, GetAngleToward: function(startX, startY, endX, endY){ var _pi = Math.PI; var _x = endX - startX; var _y = startY - endY; var _angle = Math.atan2(_x, _y) * (180 / _pi); return (_angle < 0) ? (360 + _angle) : _angle; }, // INPUT RELATED FUNCTIONS IsKeyPressed: function(keyId){ for(var i = 0; i <= Agtk.controllers.MaxControllerId; i++){ if(Agtk.controllers.getOperationKeyPressed(i, keyId)){ return true; } } }, // INSTANCE RELATED FUNCTIONS GetSelf: function(instance){ return Agtk.objectInstances.get(instance); }, GetOtherInstance: function(nameOrId){ if(isNaN(nameOrId)){ return Agtk.objectInstances.get(Agtk.objectInstances.getIdByName(-1, nameOrId)); } return Agtk.objectInstances.get(nameOrId); }, GetParentInstance: function(childNameOrId){ var _child; if(isNaN(childNameOrId)){ _child = Agtk.objectInstances.get(Agtk.objectInstances.getIdByName(-1, childNameOrId)); }else{ _child = Agtk.objectInstances.get(childNameOrId); } var _parentId = _child.variables.get(_child.variables.ParentObjectInstanceIDId).getValue(); return Agtk.objectInstances.get(_parentId); }, GetAttackerInstance: function(instance){ var _attackerList = instance.getAttackerInstanceIdList(); for(var attacker in _attackerList){ return Agtk.objectInstances.get(_attackerList[attacker]); } }, // INSTANCE SWITCH/VARIABLE RELATED FUNCTIONS GetInstanceSwitch: function(instance, nameOrId){ if(isNaN(nameOrId)){ return instance.switches.get(instance.switches.getIdByName(nameOrId)).getValue(); } return instance.switches.get(nameOrId).getValue(); }, SetInstanceSwitch: function(instance, nameOrId, value){ if(isNaN(nameOrId)){ instance.switches.get(instance.switches.getIdByName(nameOrId)).setValue(value); return; } instance.switches.get(nameOrId).setValue(value); }, GetInstanceVariable: function(instance, nameOrId){ if(isNaN(nameOrId)){ return instance.variables.get(instance.variables.getIdByName(nameOrId)).getValue(); } return instance.variables.get(nameOrId).getValue(); }, SetInstanceVariable: function(instance, nameOrId, value){ if(isNaN(nameOrId)){ instance.variables.get(instance.variables.getIdByName(nameOrId)).setValue(value); return; } instance.variables.get(nameOrId).setValue(value); }, // COMMON SWITCH/VARIABLE RELATED FUNCTIONS GetCommonSwitch: function(nameOrId){ if(isNaN(nameOrId)){ return Agtk.switches.get(Agtk.switches.getIdByName(nameOrId)).getValue(); } return Agtk.switches.get(nameOrId).getValue(); }, SetCommonSwitch: function(nameOrId, value){ if(isNaN(nameOrId)){ Agtk.switches.get(Agtk.switches.getIdByName(nameOrId)).setValue(value); return; } Agtk.switches.get(nameOrId).setValue(value); }, GetCommonVariable: function(nameOrId){ if(isNaN(nameOrId)){ return Agtk.variables.get(Agtk.variables.getIdByName(nameOrId)).getValue(); } return Agtk.variables.get(nameOrId).getValue(); }, SetCommonVariable: function(nameOrId, value){ if(isNaN(nameOrId)){ Agtk.variables.get(Agtk.variables.getIdByName(nameOrId)).setValue(value); return; } Agtk.variables.get(nameOrId).setValue(value); } }

How to add Baz Functions to plugin:
Simply copy the template above and add it inside your plugin (or grab the base template with baz functions from this guide). You can then minimize the baz object if you text editor allows and not worry about it again unless you need to update them (or add too, but I would recommend making your own object for those functions).



How to use Baz Functions:
The only difference in using these plugin functions is that you must preference each function with 'baz.'. For example GetOtherInstance() is now baz.GetOtherInstance(). I used the name 'baz' for a couple reasons, 1. it's short, so typing it is easy and 2. you will know who to contact if any function isn't working properly. As mentioned earlier the power function GetSelf() that you commonly see me use in my scripting video's was unable to be used in plugin form so you will have to use the full syntax of Agtk.objectInstances.get(instanceId) instead. Examples below:

1 条留言
Zeronidus 2022 年 8 月 26 日 上午 10:39 
Hi baz, wasn't sure where to contact you or if you knew, but it's possible to change the code inside the engine itself. The code in the engine can be directly referenced in game through the normal Action Command "Execute Script". I tested by outputting Agtk.log(cc.ENGINE_VERSION); to the debug log which resulted in "Cocos2d-JS v3.15" being displayed. After changing said version to "NightmareSauce" (in the source file) and restarting the play test the debug log output "NightmareSauce" which means it's not even baked into an executable.

Definitely not something beginners should be messing with so apologies for posting here XD

The files are located in "Steam\steamapps\common\Pixel Game Maker\player-win\Resources\script".

Documentation for the engine can be found by following links inside the code.

I hope yourself and other expert programmers will find this information useful.