Project1
标题:
【脚本新手求助】写了一段代码不懂怎么用。。
[打印本页]
作者:
Stolf
时间:
2016-3-14 21:44
标题:
【脚本新手求助】写了一段代码不懂怎么用。。
本帖最后由 Stolf 于 2016-3-14 23:03 编辑
var arr = new Array();
for(var i = 0; i < 100; i++) {
arr[i] = new Array();
}
var Width = $gameVariables.value(1);
var Height = $gameVariables.value(2);
var dir[8][2] = [[0, 1], [1, 0], [-1, 0], [0, -1], [1, 1], [1, -1], [-1, 1], [-1, -1]];
for (var i = 0; i < Width; i++) {
for (var j = 0; j < Height; j++) {
var sumA = 0; var sumB = 0;
for (var k = 0; k < 8; k++) {
var tX = i + dir[i][0]; var tY = j + dir[i][1];
if (tX >= 0 && tX < Width && tY >= 0 && tY < Height) {
var e = $gameMap.eventIdXy(i, j); var m = $gameMap.mapId();
if ($gameSelfSwitches.value([m, e, 'A'])) {sumA++;}
else if ($gameSelfSwitches.value([m, e, 'B'])) {sumB++;}
}
}
var sum = sumA + sumB;
if (sum == 3) {
if (sumA >= 2) {
arr[i][j] = 1; // Black+
} else {
arr[i][j] = 2; // Red+
}
} else {
if (sum == 2) {
arr[i][j] = 3; // +-
} else {
arr[i][j] = 0; // -
}
}
}
}
for (var i = 0; i < Width; i++) {
for (var j = 0; j < Height; j++) {
var e = $gameMap.eventIdXy(i, j);
var m = $gameMap.mapId();
if (arr[x][y] == 0) {
$gameSelfSwitches.setValue([m, e, 'A'], false);
$gameSelfSwitches.setValue([m, e, 'B'], false);
} else if (arr[x][y] == 1) {
if ($gameSelfSwitches.Value([m, e, 'B']) == false) {
$gameSelfSwitches.setValue([m, e, 'A'], true);
}
} else if (arr[x][y] == 2) {
if ($gameSelfSwitches.Value([m, e, 'A']) == false) {
$gameSelfSwitches.setValue([m, e, 'B'], true);
}
}
}
}
复制代码
我是想像公用事件一样使用这段代码。。。然而直接用事件选项里的插入脚本会报错。。还不知道错哪。。而且长度也有限制。。
所以如果要改写成插件的模式要怎么办?
谢谢!( ̄︶ ̄)!
作者:
andrewx
时间:
2016-3-15 02:05
var foobar20160315 = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
foobar20160315.call(this, command, args);
if (command.toUpperCase() === 'SOMECODE') { //引号内改成你的插件指令名,全大写
//你的代码写在这
}
};
复制代码
保存为js插件并打开。在事件里执行插件指令,输入你的插件指令名。
作者:
Stolf
时间:
2016-3-15 06:34
andrewx 发表于 2016-3-15 02:05
保存为js插件并打开。在事件里执行插件指令,输入你的插件指令名。
谢谢!我还想请教一下,怎么样才能像编译器一样定位到发生错误的具体代码行数?
比如游戏报错出Type Error : Cannot read property '0' of undefined
完全不懂错哪了。。
var foobar20160315 = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function (command, args)
{
foobar20160315.call(this, command, args);
if (command.toUpperCase() === 'CALLMYFUNC')
{
var arr = new Array();
for (var i = 0; i < 100; i++)
{
arr[i] = new Array();
for (var j = 0; j < 100; j++)
{
arr[i][j] = "";
}
}
var dir = new Array();
for (var i = 0; i < 8; i++)
{
dir[i] = new Array();
for (var j = 0; j < 2; j++)
{
dir[i][j] = "";
}
}
var Width = $gameVariables.value(1);
var Height = $gameVariables.value(2);
dir = [[0, 1], [1, 0], [-1, 0], [0, -1], [1, 1], [1, -1], [-1, 1], [-1, -1]];
for (var i = 0; i < Width; i++)
{
for (var j = 0; j < Height; j++)
{
var sumA = 0;
var sumB = 0;
for (var k = 0; k < 8; k++)
{
var tX = i + dir[i][0];
var tY = j + dir[i][1];
if (tX >= 0 && tX < Width && tY >= 0 && tY < Height)
{
var e = $gameMap.eventIdXy(i, j);
var m = $gameMap.mapId();
if ($gameSelfSwitches.value([m, e, 'A']))
{
sumA++;
}
else if ($gameSelfSwitches.value([m, e, 'B']))
{
sumB++;
}
}
}
var sum = sumA + sumB;
if (sum == 3)
{
if (sumA >= 2)
{
arr[i][j] = 1; // Black+
}
else
{
arr[i][j] = 2; // Red+
}
}
else
{
if (sum == 2)
{
arr[i][j] = 3; // +-
}
else
{
arr[i][j] = 0; // -
}
}
}
}
for (var i = 0; i < Width; i++)
{
for (var j = 0; j < Height; j++)
{
var e = $gameMap.eventIdXy(i, j);
var m = $gameMap.mapId();
if (arr[x][y] == 0)
{
$gameSelfSwitches.setValue([m, e, 'A'], false);
$gameSelfSwitches.setValue([m, e, 'B'], false);
}
else if (arr[x][y] == 1)
{
if ($gameSelfSwitches.Value([m, e, 'B']) == false)
{
$gameSelfSwitches.setValue([m, e, 'A'], true);
}
}
else if (arr[x][y] == 2)
{
if ($gameSelfSwitches.Value([m, e, 'A']) == false)
{
$gameSelfSwitches.setValue([m, e, 'B'], true);
}
}
}
}
}
};
复制代码
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1