Way to reduce 700+ Conditional Branches in Common Event?

@ATT_Turan Thanks for that! I get the storage of the note values just fine. The problem is then displaying all those notes in the squares. I will post here what I shared with @Trihan in a PM.

Essentially, I have Common Events for each of the 81 squares of the puzzle. The CEs are used when the square can be clicked on to allow the player to choose a value or also input notes now. I am using Show Picture and the ButtonPicture plugin to make the squares selectable.

I have a parallel event running that makes these square selectable and constantly updates the squares to show either Official Hints, player inserted values, player inserted notes, or a blank square.

For the mechanic to add notes, the way I know how to do it is to use 4 different Variables for each square so the player can add up to 4 notes in the square. I am using Input Number to store those selections. Then I am using Show Picture to display the values of those 4 Variables as the Notes in the square.

Since a player could, in theory, add notes to up to 64 of the squares for the hardest puzzle, I need to be able to show that many notes (4 x 64) at any given time. Even though that is extremely unlikely.

So the notes the player inputs are stored in 4 unique Variables for each square they select. And each square has a Switch to indicate if the notes should be displayed. Because ultimately, the notes will be replaced with a real value to solve the puzzle.

So Square 1 would have Variables for S1Note1, S1Note2, S1Note3, & S1Note4.

I am using the TextPicture plugin to use the Variables to display the notes in the squares.

Based on my limited knowledge, I don't know of any other options to display the notes in the squares other than using the 4 Variables.

And even if I could assign Variables as the player decides to add the notes, instead of having 4 unique Variables for each square by default, it would seem like I would still need quite a few Variables to achieve that.

I have Switches for each square that indicate whether the square should be showing the official hint for that square or the value the player entered or the values of the notes. So 3 Switches for each square.

So the issue isn't just storing what the player decides to input as notes. It is also showing all those notes in the puzzle. The display part seems to be the issue.

EDIT: Adding Screenshots of Excerpts of Events

Spoiler: Screenshots
Sample Common Event, Excerpt of Parallel Event that runs the puzzle, and Experiment with displaying notes in a square.
CE Sample.pngExcept of Puzzle Run Event.pngNotes Experiment.png
For the mechanic to add notes, the way I know how to do it is to use 4 different Variables for each square so the player can add up to 4 notes in the square. I am using Input Number to store those selections.
You could reserve only 1 game variable for this and immediately put its value into an array as I demonstrated above.

I am using the TextPicture plugin to use the Variables to display the notes in the squares.
We'll make a minor edit on line 60 of the TextPicture plugin. Change it from:
Code:
textPictureText = String(args.text);
to:
Code:
textPictureText = eval(args.text);

That way, instead of taking escape codes à la Show Text, it takes JavaScript.

Then you can simply supply the nested array element like I demonstrated above.
@ATT_Turan Wow, very interesting! And exciting that I think I mostly understand what is going on.

So this would mean that I would only need 1 Variable for each of the squares to display 4 note values. I would need 1 Variable for the Array to store all the notes for the entire puzzle and 1 Variable to display all 4 note values in that square. So 82 Variables instead of 384.

So I need to experiment with pushing values into that storage array based on player inputs and making sure they are in the correct spot so I can extract them correctly. Because the array has to be able to store 4 values for any of the 81 squares and there's no way of knowing in advance which squares will need values added in the array.

But changing the TextPicture plugin by editing Line 60 won't impact how I am normally using it, right?

Because I use the TextPicture plugin to display all sorts of things from Words to Icons to Variables. I can't afford to have the normal function of the plugin change just for this mechanic.

EDIT: But then another consideration is making those 4 values fit inside a square. There isn't much room.
@ATT_Turan Wow, very interesting! And exciting that I think I mostly understand what is going on.

So this would mean that I would only need 1 Variable for each of the squares to display 4 note values. I would need 1 Variable for the Array to store all the notes for the entire puzzle and 1 Variable to display all 4 note values in that square. So 82 Variables instead of 384.

So I need to experiment with pushing values into that storage array based on player inputs and making sure they are in the correct spot so I can extract them correctly. Because the array has to be able to store 4 values for any of the 81 squares and there's no way of knowing in advance which squares will need values added in the array.

But changing the TextPicture plugin by editing Line 60 won't impact how I am normally using it, right?

Because I use the TextPicture plugin to display all sorts of things from Words to Icons to Variables. I can't afford to have the normal function of the plugin change just for this mechanic.
I would second the suggestion to use an array for your notes instead of individual variables. You could take it a step further and use an array element to determine whether the note should be displayed as well, but one step at a time. 🙂

And that edit to TextPicture shouldn't affect anything; using eval on a string will have the same effect as it did previously.
So this would mean that I would only need 1 Variable for each of the squares to display 4 note values. I would need 1 Variable for the Array to store all the notes for the entire puzzle and 1 Variable to display all 4 note values in that square. So 82 Variables instead of 384.
I'm sorry, I don't understand where you're getting 82 variables from. That's 1. How is displaying different from storing? And where are the other 80 coming from?

But changing the TextPicture plugin by editing Line 60 won't impact how I am normally using it, right?

Because I use the TextPicture plugin to display all sorts of things from Words to Icons to Variables.
As Trihan says, it won't affect how it already works, it will simply allow you to use code that produces a string in addition to providing a string in the first place.
So for the TextPicture plugin instead of putting something like \V[69] to display a specific Variable, I would put $gameVariables.value(69)[2] and that would display all 4 values that are stored in that part of the array?

So you just keep using that script, but changing the location like [3] or [65]? Which seems really cool!

I have never tried to use script in the TextPicture plugin. So maybe that is what the change in Line 60 is allowing?

But then there is still the issue of fitting the 4 values into the square. I would think that the values would be displayed in a row like 1 2 3 4.

I apologize if I am being dense here, but this is concept if new to me so I am trying to wrap my head around it.
So for the TextPicture plugin instead of putting something like \V[69] to display a specific Variable, I would put $gameVariables.value(69)[2] and that would display all 4 values that are stored in that part of the array?
You're missing a layer. You use the TextPicture and Show Picture calls exactly the way you were previously to position the four clues, and you use the syntax I already provided you to refer to 1 clue at a time.

And retrieve the second note on the third square thusly:
Code:
$gameVariables.value(69)[2][1];

I have never tried to use script in the TextPicture plugin. So maybe that is what the change in Line 60 is allowing?
Right.
That way, instead of taking escape codes à la Show Text, it takes JavaScript.
Although that should read "instead of just taking escape codes..."
Oh, duh! My thinking it too linear sometimes.

So in the TextPicture plugin it would look something like:

$gameVariables.value(69)[2][1] $gameVariables.value(69)[2][2]
$gameVariables.value(69)[2][3] $gameVariables.value(69)[2][4]

That would be assuming all 4 values would fit doing that. And I don't need any semicolons or anything in between?

I used 2 different TextPicture commands with 2 Show Picture commands because the space between the 2 rows was too big.

So mine might be:

TextPicture
$gameVariables.value(69)[2][1] $gameVariables.value(69)[2][2]
Show Picture
Text Picture
$gameVariables.value(69)[2][3] $gameVariables.value(69)[2][4]
Show Picture

But one more question about the array. Normally I use this script to add a value to an empty array.

$gameVariables.value(445).push($gameVariables.value(433))

This adds the value of Variable 433 to the Variable Array 445.

It seems like I would have to change that for the Array that I would need for this, right?

If I start with an empty array and then I need to add 4 values for any square the player chose, I would have to push those values into the array based on what square the player chose, right?
I used 2 different TextPicture commands with 2 Show Picture commands because the space between the 2 rows was too big.
Remember how all the support threads are always saying "you should post a screenshot"? 😉

I understand now your concern is because you were using one text argument to display one picture.

So if your plugin command argument was previously, say,
Code:
\v[22]   \v[23]

You'll need to add some JavaScript formatting via string literals. The format for that is backticks (above the Tab button, not single quotes), then you surround JavaScript with ${ } You can embed that in a string to put spaces between the two.

So your plugin command argument might now be:
Code:
`${$gameVariables.value(69)[2][0]}    ${$gameVariables.value(69)[2][1]}`

But one more question about the array. Normally I use this script to add a value to an empty array.
$gameVariables.value(445).push($gameVariables.value(433))
It seems like I would have to change that for the Array that I would need for this, right?
I don't know what your variables 445 and 433 represent, what these values are. If you're asking whether push() still functions, your array is still an array.

If I start with an empty array and then I need to add 4 values for any square the player chose, I would have to push those values into the array based on what square the player chose, right?
I'm slightly confused because pushing and adding values at a specific location in the array are two different things.

If you're doing something completely sequentially, push() works fine. If you're referencing a specific location, I don't see why you'd ever have used push, and I already supplied the syntax for setting values above.

If you're still confused, perhaps you can show a portion of the event in question and ask how it might change using this method.
@ATT_Turan Thanks for all your help and patience. All of this is very helpful, but it was still a bit confusing because I hadn't experimented with it.

However, here is an experiment I just did and it works perfectly fine. The Show Text commands are just there so I could see what was happening along the way. I made a few stupid mistakes at first.

All Notes Array Test.png


So now I think I understand how this works and it opens a LOT of new doors. I have to go back and look at what I have already done to see if I can incorporate this concept in other places.

I have already been able to significantly reduce quite a few Events from the first time I experimented with making a Sudoku puzzle many, many months ago based on questions I have asked this time around.

I didn't know how to add values to an Array like that so the concept was a bit confusing until I tried it.

I will explore this more later tonight.

Again, thanks to both you and @Trihan for teaching me so many new things!

This concept is going to be much more efficient.
You don't want all of the brackets around [$gameVariables.value(310)] because that's casting it as an array.

That might not do anything undesirable, but it also might, and it's certainly unnecessary/bad habit.

Just set the value of that element.

Code:
$gameVariables.value(305)[2][0] = $gameVariables.value(310)
etc. for indices 1, 2, 3.
Oh crap! I'm glad you pointed that out. It was working, but I will go back and fix that!

EDIT: Hmmm...I changed that and now I am getting a Type Error Cannot set property '0' of undefined.

EDIT EDIT: With the [ ] was I making an Array of Arrays? Because that might be ok as long as it didn't mess anything up.

EDIT EDIT EDIT: So I changed it to:

$gameVariables.value(305)[8] = $gameVariables.value(310)
$gameVariables.value(305)[9] = $gameVariables.value(310)
$gameVariables.value(305)[10] = $gameVariables.value(310)
$gameVariables.value(305)[11] = $gameVariables.value(310)

So 8-11 would be the indices of the values for square 3 and that worked fine. It is a little harder to keep track of what 4 values go with which square, but I'm not getting the TypeError any more.

Weird that keeping the [ ] around [$gameVariables.value(310)] seemed to make it work. But who knows if it would have caused other problems somewhere.
EDIT EDIT: With the [ ] was I making an Array of Arrays? Because that might be ok as long as it didn't mess anything up.
EDIT EDIT EDIT: So I changed it to:
Okay. Stop. Back up. Don't be a chicken with its head cut off 😛

It looks like the first line where you did that, e.g.
Code:
$gameVariables.value(305)[2] = [$gameVariables.value(310)]

was good, because that element needs to be initialized as an array in some way. You could do it as a separate line, but that works fine.

On every subsequent line, however, you should remove the brackets around 310.

$gameVariables.value(305)[8] = $gameVariables.value(310)
$gameVariables.value(305)[9] = $gameVariables.value(310)
$gameVariables.value(305)[10] = $gameVariables.value(310)
$gameVariables.value(305)[11] = $gameVariables.value(310)
Don't do all that - that's backtracking toward having a separate game variable for every square, which is the mess we're trying to get rid of - right?
Ah, that makes sense. So in my example, Variable 305 that was established as an empty Array will hold up to 81 other Arrays. So with the first Note that the player inputs, the new Array at the appropriate index is initialized.

Very cool. I will go back and make that change when I get back to my computer.

And I am assuming (without testing) that I can just repeat the process and an existing Array within the main Array will be overwritten. Meaning if the player wants to update their notes in a specific square. The new values will overwrite what was previously in that spot.

Yeah! More things to experiment with!

Original thread: https://forums.rpgmakerweb.com/threads/way-to-reduce-700-conditional-branches-in-common-event.164711/