I was planning on writing a rather long script for a common event (something regarding switch statements; learning skills by comparing various variables) but apparently I can only write up to 12 lines per script. Is there a way to break this limit?
Longer scripts?
RPG Maker MV SupportNot in MV (MZ doesn't have one) but you can put multiple lines of script on one line by putting semicolons between them. MV doesn't have a horizontal limit, so it might end up looking unwieldy and hard to read but you can squeeze more in doing that.
It can also help to store longer repeated property access chains in smaller identifiers.
no, but there is no need for longer script commands either
if you have a longer function, write it as a plugin and then place a call to that function in the event scriptbox
if you have a longer function, write it as a plugin and then place a call to that function in the event scriptbox
And I'm sure you can do this with event as well?
Learning a skill based on different events?
Learning a skill based on different events?
It's better to create a plugin and call it when necessary.
Example:
MyPlugin.isValid()
MyPlugin.myAction("addPotion", "5")
It's also possible to create plugin commands (MyPlugin add "potion" 5), reading event comments (<MyPlugin add 1 5>).
This can be useful for maintenance, since you can change the scripts in one place and not need to change common events, and you can call and use the same code from multiple locations.
Example:
MyPlugin.isValid()
MyPlugin.myAction("addPotion", "5")
It's also possible to create plugin commands (MyPlugin add "potion" 5), reading event comments (<MyPlugin add 1 5>).
This can be useful for maintenance, since you can change the scripts in one place and not need to change common events, and you can call and use the same code from multiple locations.
Another workaround would be to store the processed value(s) in game variables at the end of a 12 lines block, then call it back on the next script block, and continue the operations.
VisuStella adds an extension that allows you to write scripts in a Scrolling Text command. I don't know of an MV plugin that does the same, but I was planning to make one sometime as I think it would be quite easy to implement. If you'd like, I'll look into it and get back to you.
There's also the option of breaking your script into 12-line chunks. Variables will be local to a specific chunk, but if you have any thing you need to share between chunks, you can easily store it on
There's also the option of breaking your script into 12-line chunks. Variables will be local to a specific chunk, but if you have any thing you need to share between chunks, you can easily store it on
this. For example, this.your_variable = 42.i don't wanna look at a convoluted nest of if-else statements no thank you
Here you go. Paste this into a file (call it whatever you want; I called it SFG_LongerScripts.js) and add it as a plugin. If on Windows, make sure you set the file type to "any file", otherwise you might get a .txt extension added to the end.
JavaScript:
/*:
@plugindesc [1.0] Allows you to write script calls in a Scrolling Text event command.
@author Solarflare Games
@help
To use, just create a scrolling text command and put the follpwing on the
first line:
// <SCRIPT>
Then you can write whatever JavaScript code you want in the rest of the
text box. This allows writing scripts longer than 12 lines.
*/
(function() {
const scriptHeader = /^\s*\/{2}.*?<SCRIPT>/i;
const parseLongScripts = function(page) {
var inLongScript = false, scrollingHeader = -1;
for(let i = 0; i < page.list.length; i++) {
let cmd = page.list[i];
if(cmd.code == 105) {
scrollingHeader = i;
inLongScript = false;
} else if(cmd.code == 405) {
if(i == scrollingHeader + i && scriptHeader.test(cmd.parameters[0])) {
page.list[scrollingHeader].code = 0;
cmd.code = 355;
inLongScript = true;
} else if(inLongScript) {
cmd.code = 655;
}
} else {
inLongScript = false;
scrollingHeader = -1;
}
}
};
const old_load = DataManager.onLoad;
DataManager.onLoad = function(obj) {
if(obj == $dataTroops) {
for(let i = 1; i < $dataTroops.length; i++) {
let troop = $dataTroops[i];
for(let j = 0; j < troop.pages.length; j++) {
parseLongScripts(troop.pages[j]);
}
}
} else if(obj == $dataCommonEvents) {
for(let i = 1; i < $dataCommonEvents.length; i++) {
parseLongScripts($dataCommonEvents[i]);
}
} else if(obj == $dataMap) {
for(let i = 1; i < $dataMap.events.length; i++) {
let event = $dataMap.events[i];
if(event == null) continue;
for(let j = 0; j < event.pages.length; j++) {
parseLongScripts(event.pages[j]);
}
}
}
old_load.call(this, obj);
};
})();
Original thread: https://forums.rpgmakerweb.com/threads/longer-scripts.178434/