Hello ladies, gentleman, and those in between/neither who are better at Javascript than I (SQL nerd here).
I have the following code that draws a nifty little preview menu (SRPG plugin for those curious):
Window_SrpgStatus.prototype.drawParameters = function(x, y) {
var lineHeight = this.lineHeight();
for (var i = 0; i < 6; i++) {
if (i==2 || i == 3)
continue;
var paramId = i + 2;
var x2 = x + 188 * (i % 2); //alright set if statement for the math here to change what i is for the placement
var y2 = y + lineHeight * Math.floor(i / 2); //alright set if statement for the math here to change what i is for the placement
this.changeTextColor(this.systemColor());
this.drawText(TextManager.param(paramId), x2, y2, 120);
this.resetTextColor();
this.drawText(this._battler.param(paramId), x2 + 120, y2, 48, 'right');
}
};
Now my game doesn't use Magic Attack or Magic Defense so instead of 2 dummy parameters that do nothing, I'm hiding them. Now while I can hide params 2 and 3 the code still makes space for them because in the var x2 = and var y2 = lines they're doing math based on if variable 2 and 3 are there (leaving a blank line. I need it to basically say in the case where i > 1 ... treat it like it's i - 1
This attempt errors out:
var x2 = x + 188 * ((if (i>1) i-1 % 2
else
i % 2));
I... am at a loss as to why. I assume it's pesky syntax and I'm missing a , or ) somewhere. Thoughts?
I have the following code that draws a nifty little preview menu (SRPG plugin for those curious):
Window_SrpgStatus.prototype.drawParameters = function(x, y) {
var lineHeight = this.lineHeight();
for (var i = 0; i < 6; i++) {
if (i==2 || i == 3)
continue;
var paramId = i + 2;
var x2 = x + 188 * (i % 2); //alright set if statement for the math here to change what i is for the placement
var y2 = y + lineHeight * Math.floor(i / 2); //alright set if statement for the math here to change what i is for the placement
this.changeTextColor(this.systemColor());
this.drawText(TextManager.param(paramId), x2, y2, 120);
this.resetTextColor();
this.drawText(this._battler.param(paramId), x2 + 120, y2, 48, 'right');
}
};
This attempt errors out:
var x2 = x + 188 * ((if (i>1) i-1 % 2
else
i % 2));
I... am at a loss as to why. I assume it's pesky syntax and I'm missing a , or ) somewhere. Thoughts?