Example: So you've got a situation where you want to have the player listen to 10 conversations, but some of the people are in conversation with each other so talking to any of those people should count as hearing the conversation. Let's say there are 7 people that you talk to individually, and another 6 people pairs that count as 3 conversations. Total conversations = 10, total people = 13. You could use switches and self switches and set them after each conversation and increment a counter. Another way to do this would be with an array. Yes, you can set a game variable = to an array.
So instead of using 7 self switches and 3 control switches we only need one array variable and one variable to store the total conversations number. First you need to identify each event with a note signifying the conversation number. At the top of the event editor and to the right of the event name is the note section. Just put a number like 1,2,3, etc to represent the conversation number. For the people pairs they would have the same conversation number.
Now at the start of each conversation you call a common event, 'check conversation'. In this common event we run a simple script.
var array = $gameVariables.value(14)
var event = $dataMap.events[this._eventId]
var note = event.note
if (array.indexOf(note) === -1) {
array.push(note)
}
What this snippet does is it loads up the array, game variable 14 in my case, checks the event note and if the note does not exist in the array we add it to the array. Following this snippet you just need to check array.length and see if it is equal to the max conversation number. If it is you can run another event or whatever you want to happen if all the conversations have occurred.
This technique can be applied to any situation where you need to track something. You can even reuse the array variable, max number variable and common event if the two tracking scenarios are sufficiently isolated, just remember to clear the array and reset the max number.
Update:
I wound up writing a utility plugin for this tracking task. It uses a provided game variable to store the tracker object and keeps track of everything internally. The only caveat is you lose the ability to track progress via debug. However, if you really needed to see what was going on you can just assign another variable the value of tracker variables array property and then you can monitor the array contents in debug.
If anyone is interested in this plugin send me a message. I might post it later under plugins development if I get time or if someone asks me to.
So instead of using 7 self switches and 3 control switches we only need one array variable and one variable to store the total conversations number. First you need to identify each event with a note signifying the conversation number. At the top of the event editor and to the right of the event name is the note section. Just put a number like 1,2,3, etc to represent the conversation number. For the people pairs they would have the same conversation number.
Now at the start of each conversation you call a common event, 'check conversation'. In this common event we run a simple script.
var array = $gameVariables.value(14)
var event = $dataMap.events[this._eventId]
var note = event.note
if (array.indexOf(note) === -1) {
array.push(note)
}
What this snippet does is it loads up the array, game variable 14 in my case, checks the event note and if the note does not exist in the array we add it to the array. Following this snippet you just need to check array.length and see if it is equal to the max conversation number. If it is you can run another event or whatever you want to happen if all the conversations have occurred.
This technique can be applied to any situation where you need to track something. You can even reuse the array variable, max number variable and common event if the two tracking scenarios are sufficiently isolated, just remember to clear the array and reset the max number.
Update:
I wound up writing a utility plugin for this tracking task. It uses a provided game variable to store the tracker object and keeps track of everything internally. The only caveat is you lose the ability to track progress via debug. However, if you really needed to see what was going on you can just assign another variable the value of tracker variables array property and then you can monitor the array contents in debug.
If anyone is interested in this plugin send me a message. I might post it later under plugins development if I get time or if someone asks me to.