Setting variable Scriptcalls ends up overwriting previous variables...

I'd like to apologize for the long post, but it's really only long because I'm trying to clearly demonstrate what I'm doing so everyone has the relevant info.

Long story short, I'm making a point and click game, so I need to make the 'ShowPicture' scriptcall as streamlined as possible, because some scenes could possibly have up to 30 images that when clicked with the mouse will trigger interaction events.
(Note:the Background art is not mine and just a place holder to test out my picture interaction hitboxes)
2023-04-12 13_31_04-PointNClickTest.png

-But trying to guess the XY coordinates of each hitbox picture to place onscreen with the ShowPictureCommand would be an nightmare.
-So I figured out that I can easily get the X, Y coordinates of where I want the picture to show onscreen by the following process:

I have a phase in during playtesting where I need to save certain Mouse coordinates to a variable, along with a number(to represent the pictureID#) that increases by 1 each time. Naturally the thing is saved as an array and looks like this:
Variable1: 11,400,200
Variable2: 12,240,311
etc

I was able to do this using 4 variables:

>2 that are set to the Mouse X and Mouse Y -which is constantly being tracked with a separate parallel event.
>And then another variable Called PicID to mark the Show picture Layer #. (because pictures can't have the same layer # without overwriting themselves).
>The fourth Variable is the VarSlotVar. And that one is to decide which Variable the above info gets saved into, otherwise, each new set of coordinates would just overwrite the same variable slot.

It's fairly simple. I have an event that runs parallel that detects ingame if I 'right click'. When I do, it saves the current mouse coordinates along with the picID (which starts out set to 11) into the slot decided by the VarSlotVar.
Then it adds 1 to the Pic Id and VarSlotVar.
2023-04-12 13_04_50-ID_032 - Event Editor.png

By doing this, while the first saved var would be something like this, clicking again would move the slot:
Example:

(VarSlot) (Pic#), (x), (y)
Variable100: 11,568,319
Variable101: 12,656,396
2023-04-12 13_49_19-PointNClickTest.png



-After I've clicked on all the pictures, I talk to an NPC that is set to display the \v[] of all the variables in order.
2023-04-12 13_13_42-ID_034 - Event Editor.png


-Then I screenshot the info and feed it to program that will dump text into a text file.(I'd prefer to have a scriptcall save the variables to a textfile but I don't know how to do that so in the meantime the screenshot to txt program works just fine)

-Perfect! Everything's working fine.
------------------------------------------------

But then I thought, "Instead of having to manually copy and paste each pic# and X,Y value into each 'show picture' scriptcall about 20 times, what if I automate that too?"

So I made use of the set var scriptcall to save things as a mix of strings and variables.

Inputting this into the scriptbox:
$gameVariables.setValue(961, '$gameScreen.showPicture(' + '\x1bV[995]' + ', "X", 1, ' + '\x1bV[998]' + '\x1bV[999]' + ', 100, 100, 255, 0)');

I would then do the command ingame to receive this saved into variable 1:
$gameScreen.showPicture(11, "X", 1, 586, 478, 100, 100, 255, 0)

2023-04-12 12_32_42-PointNClickTest.png


Which is great, because that is a properly formatted and usable scriptcall to showpicture, and as long as you've got an image with the filename 'X', it works perfectly ingame!

But during the last step, something goes wrong.
It's WEIRD and I can't explain why it happens, but it does.

The Setvariable Event with the new format:
2023-04-12 13_53_30-ID_037 - Event Editor.png


Remember how earlier I was able to get about 10 different variable slots each with their own coordinates?
For some reason, whenever I try to use this new Set variable script command to save the variable into the new format, it OVERWRITES the previous variables too!
So all 10 variable slots will have the exact same value of the latest variable saved! T-T

Example:
2023-04-12 13_48_26-PointNClickTest.png


I only have the scriptcall saving the info to one slot at a time, and even then the slot changes after each scriptcall! So I don't understand how it could possibly be overwriting the previous variables like this!?

Does anyone have any ideas?
(PS: if anyone has a plugin or a script snippet to do this better than my current way I'm also all ears >.>)
Hiya,

I believe RPG Maker MZ natively comes with a 'ButtonPicture' plugin by default, which enables clickable pictures that activate common events, if this perhaps simplifies what you were looking to achieve?

There's also an adjustment someone made in the instance where a lot of button pictures may be used that allows you to assign values on clicking which I can see helping when you're dealing with this many: https://forums.rpgmakerweb.com/index.php?threads/button-picture-update.142058/

Edit: Whoops, looks like I misinterpreted what was being asked here, my apologies, haha. ;~; I hope someone is able to help!
Hiya,

I believe RPG Maker MZ natively comes with a 'ButtonPicture' plugin by default, which enables clickable pictures that activate common events, if this perhaps simplifies what you were looking to achieve?

There's also an adjustment someone made in the instance where a lot of button pictures may be used that allows you to assign values on clicking which I can see helping when you're dealing with this many: https://forums.rpgmakerweb.com/index.php?threads/button-picture-update.142058/

I am currently using a picture to button plugin, and it is indeed very helpful.

The issue is not clicking the picture, it's needing to set up 20 "showPicture" scriptcalls each with their own unique X and Y coordinates to begin with that is troublesome.
Hence why I need to get that scriptcall working.
So that it generates the scriptcalls for each picture for me. ie this:
"$gameScreen.showPicture(11, "X", 1, 586, 478, 100, 100, 255, 0)"

It is indeed working. But ends up overwriting all the previous variables for some reason.
So I end up with 20 different variables that all somehow have the same value. Which should not be happening.
The mistake you've made here is assuming that assignment is static. It's not; you're creating a reference. What's being stored in the parameters of the showPicture call is the values in those variables *at the time*, which once you've run through them all will always be the most recent value they had.
What's being stored in the parameters of the showPicture call is the values in those variables *at the time*, which once you've run through them all will always be the most recent value they had.
Just to clarify, because I understand what you're saying but this sentence confused me.

Do you mean "What's being stored in the parameters of the showPicture call will always reflect the current value of those variables"?

To me, "at the time" means their value at the time the code was run, but you mean at the time the text is printed.

It seems like the OP wants to replace those escape codes with appropriate calls to $gameVariables.value()
I fear I'm a bit lost too.
I just want it to save the Coords where I click on-screen, and dump them into a pre-defined template so that later on I can just make an event that does a batch scriptcall of these 20-something "ShowPicture@XY" scriptcalls so these pictures will then show ingame T-T

BUT, to help demonstrate I just set up a demo so people can test this themselves!
There's no common events, everything used is onscreen, and there are 2 plugins included, but those are needed only for getting the coords of the cursor's x and y and have nothing to do with the SetVariable thing.
*Updated the link (old was set to self delete after 1 download whoops)
Does it work when you do what the folks above already said?

Replace '\x1bV[995] with $gameVariables.value(995) and the such.
Does it work when you do what the folks above already said?

Replace '\x1bV[995] with $gameVariables.value(995) and the such.
Sadly that doesn't work. The reason I have to use the \x1b thing is that if I just put
'$gameVariables.value(X)'
then instead of giving me the value of Variable X (ie like 315), it merely shows up as:
$gameVariables.value(X)
There's something about strings that messes up escape codes or something ;>.>
Are you using single quotes around $gameVariables.value(X)? If you are, then remove those.

$gameVariables.setValue(961, ('$gameScreen.showPicture(' + $gameVariables.value(995) + ', "X", 1, ' + $gameVariables.value(998) + ', ' + $gameVariables.value(999) + ', 100, 100, 255, 0)'));
Are you using single quotes around $gameVariables.value(X)? If you are, then remove those.

$gameVariables.setValue(961, '$gameScreen.showPicture(' + $gameVariables.value(995) + ', "X", 1, ' + $gameVariables.value(998) + ', ' + $gameVariables.value(999) + ', 100, 100, 255, 0)');
Ohhh dude, you did it!!
I did have to change
$gameVariables.setValue(961,
to
$gameVariables.setValue($gameVariables.value(996),
(even that is a variable, bc it lets me change which variable slot to save the Coords into.)

But yes, that solved it! Final scriptcall was:

$gameVariables.setValue($gameVariables.value(996), '$gameScreen.showPicture(' + $gameVariables.value(995) + ', "X", 1, ' + $gameVariables.value(998) + $gameVariables.value(999) + ', 100, 100, 255, 0)');


Now, where ever I click onscreen it saves the value as a scriptcall that I can then later use in a batch scriptcall to ShowPicture many images at all these coords!
ezgif-4-2a21cb6a4d.gif


...Now if only I could save those 10-20 variables to a text document.
Having to screenshot and use a program to dump the text so I can use those scriptcalls in an event is kinda tedious xP
Just to clarify, because I understand what you're saying but this sentence confused me.

Do you mean "What's being stored in the parameters of the showPicture call will always reflect the current value of those variables"?

To me, "at the time" means their value at the time the code was run, but you mean at the time the text is printed.

It seems like the OP wants to replace those escape codes with appropriate calls to $gameVariables.value()
I can see how that got confused, but I meant at the time the code is *executed*. The variable contains the function call text, not the function or call itself. So when it's actually displayed, all the variables contain whatever their last evaluated value was.

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/setting-variable-scriptcalls-ends-up-overwriting-previous-variables.156617/