Is there a way around the size limitation for a Script?

I've got a rather long Javascript script that I need to use in a common event (it's a long switch statement and I'm having to use it since the Conditional Statements in MV Events don't have a way to compare a string variable value)
Anyway, it only let's me put in 12 lines, which isn't long enough. Based on the value of a string, I'm setting two variables
differently.

◆Script:switch($gameVariables.value(175)) {
:Script: case 'MM':
:Script: $gameVariables.setValue(177) = 1;
:Script: $gameVariables.setValue(178) = 1;
:Script: break;
:Script: case 'MA':
:Script: $gameVariables.setValue(177) = 1;
:Script: $gameVariables.setValue(178) = 2;
:Script: break;
:Script: case 'ME':
:Script: $gameVariables.setValue(177) = 1;
:Script: $gameVariables.setValue(178) = 3;

That's all it's letting me do, but the script needs to be longer. It is something that determines the day and time period during the day to notify the player of specific events. Variable 177 goes up to 7 (mon - sun) with 178 set to 1-3 for morning, afternoon, evening. (Night and Late Night don't apply for this CE)



Is there a way around this lenth limit or can I put it in a .js file and call it somehow?
Either.

For one thing, the limitation is vertical - so just take away line breaks and put chunks of the code onto one line.

Or you can copy the code into a text file, make a JavaScript function around it, include it as a plugin then call that function from your script command.
There's this from the JS code snippets thread
its like ATT_Turan said, vertical is limited, horizontal isn't.

another way is to make a plugin function:

SwitchStatement = function() {
// your code here
}

than call it in your common event or whereever "SwitchStatement()"
without quotes and it works the same way, + you have it still readable.
if you need to change something.
Try it like this:

Code:
undefined    ◆Script:switch($gameVariables.value(175)) {
    :Script:  case 'MM':$gameVariables.setValue(177) = 1;$gameVariables.setValue(178) = 1;break;
    :Script:  case 'MA':$gameVariables.setValue(177) = 1;$gameVariables.setValue(178) = 2;break;
    :Script:  case 'ME':$gameVariables.setValue(177) = 1;$gameVariables.setValue(178) = 3;break;
There's this from the JS code snippets thread
There is a snippet there that says it can do what I need (combine multiple script blocks) but it isn't really clear to me how to use it. I'll try contacting the author of the post.

Thanks.
There is a snippet there that says it can do what I need (combine multiple script blocks) but it isn't really clear to me how to use it. I'll try contacting the author of the post.
You can do that if you like, but I think that's by far the most cumbersome method of the three offered to you. It's not actually putting all the code in one place, it's just manipulating RPG Maker's engine to be able to read it consecutively.

Especially if you need further explanation...compressing the code and making a plugin have already been explained 😉

But whatever works for you! Good luck with your project.
Either.

For one thing, the limitation is vertical - so just take away line breaks and put chunks of the code onto one line.

Or you can copy the code into a text file, make a JavaScript function around it, include it as a plugin then call that function from your script command.
I might be able to try that.
Try it like this:

Code:
undefined    ◆Script:switch($gameVariables.value(175)) {
    :Script:  case 'MM':$gameVariables.setValue(177) = 1;$gameVariables.setValue(178) = 1;break;
    :Script:  case 'MA':$gameVariables.setValue(177) = 1;$gameVariables.setValue(178) = 2;break;
    :Script:  case 'ME':$gameVariables.setValue(177) = 1;$gameVariables.setValue(178) = 3;break;

The script block still isn't big enough unfortunately. that's only 1 day's worth of code, there are 7 days in the switch statement lol..
You can do that if you like, but I think that's by far the most cumbersome method of the three offered to you. It's not actually putting all the code in one place, it's just manipulating RPG Maker's engine to be able to read it consecutively.

Especially if you need further explanation...compressing the code and making a plugin have already been explained 😉

But whatever works for you! Good luck with your project.

I kind of panicked when you first mentioned writing a plugin. I've never been very successful in doing that. But if all it takes is turning it into a function then calling that function, it may be simpler than I thought.

Compressing the code wouldn't work though..it's too big.

My big problem is I suck when it comes to writing JS code. LOL
I kind of panicked when you first mentioned writing a plugin. I've never been very successful in doing that. But if all it takes is turning it into a function then calling that function, it may be simpler than I thought.

Compressing the code wouldn't work though..it's too big.

My big problem is I suck when it comes to writing JS code. LOL
Plugins are just .js text files that your game can access. They can be as short as a few lines. You can put your switch case into a .js file, import it through the plugin manager and it's now a plugin.
Compressing the code wouldn't work though..it's too big.
I copied the entirety of your first post, removed the line breaks, and put it into a Script window with no problem. Then I copied that and pasted it at the end of the line over again with no problem.

As you've been told several times here, it would work - it just isn't very readable or easily editable at that point.

But if you type it all out in an external text editor, compress it down and paste it in, it works fine.

I would do it as a plugin, personally. I have my own plugin in my project that's just a collection of functions I call for various purposes. Some stuff for Yanfly's AI, my basic damage formula, etc. That way if you need to read or edit it, it's easy.
I copied the entirety of your first post, removed the line breaks, and put it into a Script window with no problem. Then I copied that and pasted it at the end of the line over again with no problem.

As you've been told several times here, it would work - it just isn't very readable or easily editable at that point.

But if you type it all out in an external text editor, compress it down and paste it in, it works fine.

I would do it as a plugin, personally. I have my own plugin in my project that's just a collection of functions I call for various purposes. Some stuff for Yanfly's AI, my basic damage formula, etc. That way if you need to read or edit it, it's easy.

It appears that you're correct. I had not posted the entire switch statement in my original post, only enough of a snippet to show the basics of what I was trying to do. The entire statement was something like 90-95 lines long (21 cases plus an empty default). I honestly didn't think the entire thing would fit but I compressed it all down as you suggested and it went in on about 5 lines. (Nearly impossible for me to read clearly should I need to make any edits but it did fit.)

Since this is only the first iteration of this switch statement, and I could very well be adding other variables, switches, or code statements to it, I've decided to go the plugin route.

Otherwise updating it would be nothing short of a nightmare.

Thank you for all the advice and help on this matter.
(Nearly impossible for me to read clearly should I need to make any edits but it did fit.)
Do you use a code editor? Then just save a copy to work on when you need edits, and then remove the break lines at the end AFTER you save and copy the code into RPG maker.

In most editors, removing the break lines is easy and pretty quick:

- Put the cursor on the first line
- Press END on your keyboard
- Press DEL on your keyboard
- Repeat step 2 and 3 quickly till your done

90 lines should take you about 10 seconds that way.

After this you can remove empty spaces in the code by placing [2 spaces] with [1 space] by using the "find and replace" option. In most editors I used, it is either CTRL+F or CTRL+H. And repeat this till there is no more double spaces left.

---

Anyhow, you say you'll try a plugin. I think that is a good idea.

If you do, you should really google for tutorials to cover the basics. Because if you can add parameters to the code (which even I was able to do with help of a tutorial), the values of your plugin would be so much easier to alter, right in the plugin list in RPG maker.

There are plenty tutorials around, but if I have to suggest one, I'd say watch the youtube tutorials on plugins by SumRndmDde. https://www.youtube.com/@SomeRanDev
(That is a name I didn't see in this community for way too long, btw... It seems like he goes by SumRanDev now. at leatst at youtube.)
Now that you've got the way to run longer code sorted out, some code advice: it might be considerably simpler for you to handle the day of the week and time of day separately, by looking at each character individually (I'm assuming you're using M,T,W,H,F,S,U for Monday, Tuesday, Wednesday etc.).

(also, it's $gameVariables.setValue(178, 1) to set a variable and not $gameVariables.setValue(177) = 1)

Like so:
JavaScript:
switch($gameVariables.value(175)[0]) {
    case 'M': $gameVariables.setValue(177, 1); break;
    case 'T': $gameVariables.setValue(177, 2); break;
    case 'W': $gameVariables.setValue(177, 3); break;
    //etc..
}
switch($gameVariables.value(175)[1]) {
    case 'M': $gameVariables.setValue(178, 1); break;
    case 'A': $gameVariables.setValue(178, 2); break;
    case 'E': $gameVariables.setValue(178, 3); break;
}
Or you could use indexOf to do it in two lines:
JavaScript:
$gameVariables.setValue(177, "MTWHFSU".indexOf($gameVariables.value(175)[0]) + 1);
$gameVariables.setValue(178, "MAE".indexOf($gameVariables.value(175)[1]) + 1);
(also, it's $gameVariables.setValue(178, 1) to set a variable and not $gameVariables.setValue(177) = 1)
Can't believe it took 14 posts for someone to say this.

Original thread: https://forums.rpgmakerweb.com/threads/is-there-a-way-around-the-size-limitation-for-a-script.156591/