Tracking purchases in specific shops. (for business style sim)

Hi,

I'm sure something like this probably exists and I'd be super grateful if someone could point me in the right direction (I have looked but...). If not my .js is improving and if you could suggest a way to do it I'll happily look into it myself.

I'm looking for a way to store, as a variable, how much money an in game shop has made during a transaction.

The mechanic revolves around certain factions owning certain stores so:
* Each shop needs to be able to store it's data seperately,
* And the variable in which the data is saved needs to be changeable.

I'm in no rush for this, it's just a little side project I'm playing with so please don't desturb your own projects!!!

Thank you!

-Beth
I'll try to point you in a right direction.

Phase 1: It is important to locate which function inside your shop plugin takes care of the transaction itself. If you use the default shop menu, it will be probably in rpg_windows under Window_ShopMenu or something, not sure how it is exactly called.
Phase 2: Edit that function as you see fit. Tracking the faction you're making trade with is pretty easy. Inside the engine I would set a variable to certain value (to distinguish which faction am I buying from without any hassle) before calling the shop menu.
And then you need a global variable (array to be precise). To make it a global variable, don't use var transactionArray = [], but only transactionArray = [].
Array can store multiple values, so it will be able to store all you need and since it is a global variable, it is accessible and editable from anywhere, not just within the function.

Demonstration:
I decide I'll use a variable 5 to store the value of last faction I am making a trade with.
Then inside the function I'm looking for...

Code:
if (!transactionArray) {
 transactionArray = []
 //not sure if it is necessary or not, but maybe it is...
for (var i = 0, i<your factions, i++){
 transactionArray[i]=0 (because you cannot do math operations with undefined values)
}else {
 transactionArray[$gameVariables.value(5)] += value of the bargain
}
Thank you @Poryg , that worked amzingly and was exactly what I was looking for.
You're welcome, I just completely forgot to mention that there's an intentional bug in the code I provided 😀
As it is now, it will not count the very first transaction you make. The fix isn't too hard though 🙂

Original thread: https://forums.rpgmakerweb.com/threads/tracking-purchases-in-specific-shops-for-business-style-sim.83409/