Get the first/mid/last index variable/switch/event ID

(if this is the wrong thread, move it to the correct one).

Dear community eventers.

I made a simple mechanic, but I want to extend it in a specific way.

so let to make it simple:

I use 3 variables for a specific mechanic, but to extend it nicely, I need a way to check
the ORDER of those 3 variables. (switches, event ID can have the same principle).

so let call them easy: Var1, var2, var3.

you can see the following combinations (1,2,3 - 2,1,3 - 1,3,2 - 3,1,2 - 3,2,1).

Question is, how can you check which variable is activated first?

based on MapID, SS, Switch, variable can all work, depends what is easier as this need to go
inside a conditional branch.

as the variable are on 3 places (and can be more too), what is best approach for this to work?
I know of a way, but it is also unnecerrassy checks that I want to avoid.
(I dont mind adding switches if that makes things easier).
all variables as you list them (map ID, switches, variables, etc) are contained within larger objects.
so, it would be a matter of collecting the range in question, and then filter one out.

does your design contemplate that? because otherwise there's no point... the more variables you add, the more individual conditionals you'd have to add, and it blows up out of proportion.
I just need a easy way for checking which variable/SS is activated
first, if this require a scriptcall or minor function to use, I will be happy
for that as well.

as this is inside a dungeon, a map ID/event ID might work too,
I just need a way to check them in which order, as this relies on
a another event to be triggered.

each order can have a different thing triggers (like timers can be
more or less (depending the order of triggered events).
I need a way to check
the ORDER of those 3 variables.
Please define "ORDER".

your description is a bit vague, and the result of your request depends on what kind of order you're talking about.

Are you talking about value order, highest value to lowest value?
or are you talking about access order, in which sequence the player triggers the values?
or are you talking about ID order, how the engine sorts the variables?

all three can be done and handled but require different methods to identify what you want.

EDIT: ninja'd

In that case you'll need to add another variable that is checked for order.
give me a few minutes to get an example together.
Let us declare a 4th Variable before Quest or after Game start.
Var4 = 1

Event1
Var1 set to Var4 and after that Var4 +1
Change Eventpage or insert Condition, so the above Line will not repeat when talking to the NPC again.

Event2
Var2 set to Var4 and after that Var4 +1

Event3
Var3 set to Var4 and after that Var4 +1

Depending on in which order you are talking to the NPC, the Variables have different Values (1, 2 or 3).

I doubt this is what you were looking for?
OK, this is a very simple example where you have a number of different buttons that need to be pressed in order to do something, and reset if the wrong event button is triggered. Let's try this with buttons A, B, C, D.


you'll need to make a list of the steps first, noting which event has to be triggered at each step to succeed. It is both possible to have a button pressed multiple times, or to have different combinations with different results - it just means that you'll need more conditional branches and more complex checks.
In all cases the steps are counted up from zero, and if you want multiple combinations you'll need multiple step lists and either multiple counters or a code identifier to check for which combination is attempted.

Example:

Step Code
0 A
1 B
2 D
3 C
4 A
5 B

One limitation with this method is that the codes either have to have different length or end on different buttons. If multiple valid combinations end with the same length AND the same last button, it might require more complex coding to identify the sequence.


The next step you have to do is basically invert the table to focuse on the button events, to know which button has to be pressed when:

Button Valid Presses
A step 0 , step 4
B step 1 , step 5 (finish)
C step 3
D step 2

Now this table will tell you which checks to implement at which button event.

Button A event:
if stepcounter = 0
> control variable stepcounter +=1
else
> if stepcounter = 4
>> control variable stepcounter +=1
> else
> show text "error"
> control variable stepcounter = 0

Button B event
if stepcounter = 1
> control variable stepcounter +=1
else
> if stepcounter = 5
>> show text "success"
> else
> show text "error"
> control variable stepcounter = 0

Button C event
if stepcounter = 3
> control variable stepcounter +=1
else
> show text "error"
> control variable stepcounter = 0

Button D event
if stepcounter = 2
> control variable stepcounter +=1
else
> show text "error"
> control variable stepcounter = 0

As said the entire principle can be expanded any way, but you'll have to have a different counter variable for each such puzzle.
and the list of conditional branches can get complex if you go overboard with the combinations.
let me explain it differently.

I have 4 variables in total for this mechanic, the main mechanic
depends on variable 1, 2, 3 (so variable can be 34, 35, 36).
each hold their own value.

the end of the 3 variables contain the number/string in the 4th variable.

I need to check HOW variable can be index (access order).
this can be also by indexes the switch (acces1, acces2, acces3).

if I add a 5th variable (like Bex said), I need to add +1, +10, +100
depending which variable is activated first.
this get a bit long (if you check my ocarina evented way) this is
a part I like to avoid, to have a long list, just to check which is
activated.

if there is an array part for Sw index (10-11-12)
switch 11 for first (so array = [11, null, null].
than check the final if it's equal or not (so another event can
be triggered).

the easiest way if it's the wrong order, it drops it instantly, but I
want to get a different way around, for different effect based
on this order.

so you need to trigger 3 events (in this case) before the event get
triggered, so I need the index order.
@ShadowDragon
we posted at the same time, is my solution above working for you?
it's not about pressing the buttons, as those are 3 different events
on different locations, so I need to check the event order by
switches/variables or array to check the order, than activate the
last check based on this order.

what you explained is more a ocarina based that I made by pressing
the buttons, but that is not what is going on here.

the event on it's own works, but I need to find a way to get a order
that is activated without making a huge list of check.

more of a simple way by activating the last one that has something like:

if : array = [1,3,2]
do stuff
else
if : array = [2,3,1]
do other stuff
else
if array = [3,1,2]
do other stuff
end
end
end

not with variable +1, +10,+100 (so te list is 5x so long, or triple the events
for a simple check.

the [1,2,3] are basicly the index of variable activating event or switches.
Since you want it to be eventing, I'd take 2 more variables, let me name them order1 order2.
So:

10.access1 11.access2 12.access3 13.order1 14.order2

Lets say I change acces2:
access2 = 3 if order1 = 0 then order1 = 11 else if order2 = 0 then order2 = 11 else [it's the third, so we check order1 and order2 to do stuff]

That way, order1 keeps the first variable we edited, order2 the second, and we may add a third for the next node, or resolve with this.

not with variable +1, +10,+100 (so te list is 5x so long, or triple the events
for a simple check.
How about calling a common event instead?

And I kind of got more lost with your message.

I thought what you wanted is: "I have 3 variables that may have this or that value, but I want to know which one was set sooner or later".
Spoiler
Changing a variable doesn't save the time, place or any other info about it being set, only the variable, and the value, so we can't use any "map" or stuff like that to use the scripting way. You can save the map on order1 and order2 if you prefer, instead.
The easiest way would be to have a 4th variable and store an array in it. Each time you perform an interaction that manipulates one of the three variables, push its variable ID to the array in the 4th one. Then the order of the elements in that array will be the order you activated things in.
but that is not what is going on here.
wrong, it is exactly the same.

your three arrays are three bossible code sequences - there are a lot more possible sequences as well.

you make a step counter, and on each of the three events you have that step counter checked for zero.
if it is zero you know that this event is going to be the first in your sequence, and you mark that somewhere before continuing - for example if this is event A then you know that the solution after that could only be either array [A, B, C] or [A, C, B] - none of the arrays beginning with B or C would be possible anymore
and then event A counts up the counter.

going to any other event that will now find that the step is 1, no longer 0, so that event can now determine that it is the second one and mark which of your sequences is achieved.

You will always need an additional identifier for which order is given, and your ifs have to be on that identiefier instead of an array. and that identifier always has to be set on the three events themselves, it cannot be determined after the fact.

EDIT: ninja'd, but trihan basically wrote the same as I did in my last part, just proposed a different mechanic to store the info.
@Trihan how can I push those variables inside and reading them?
as this is going to be into the right direction.

@Andar that is the problem, as A B C or B C A can be used as the
variables used are all connected and can be used (no matter the order),
the event trigger (like traps, timer, pathways can be different depending
on this order.

if A is 1st, than C and B than it's always 1 solution, which is not the case.
all answers of order are correct, just the outcome are different.

@myenemy your solution may come in handy too as it is more 4 extra
variables, as you can count them up for a different approach.
a bit different setup I used now, but can come in handy maybe if
Trihans options are going to fail.
@myenemy your solution may come in handy too as it is more 4 extra
variables, as you can count them up for a different approach.
a bit different setup I used now, but can come in handy maybe if
Trihans options are going to fail.
Demo
I added a unrequested management trick to it too
@myenemy
I need acces request, but can be usefull if it can do the trick.
@Trihan how can I push those variables inside and reading them?
as this is going to be into the right direction.

@Andar that is the problem, as A B C or B C A can be used as the
variables used are all connected and can be used (no matter the order),
the event trigger (like traps, timer, pathways can be different depending
on this order.

if A is 1st, than C and B than it's always 1 solution, which is not the case.
all answers of order are correct, just the outcome are different.

@myenemy your solution may come in handy too as it is more 4 extra
variables, as you can count them up for a different approach.
a bit different setup I used now, but can come in handy maybe if
Trihans options are going to fail.
If you do

$gameVariables.setValue(10, [])

Then 10 is now an empty array. Then when you need to push an ID to it, you can do like

$gameVariables.value(10).push(5)

And then variable 10 will be [5].
@Trihan so, when I do than var10.push(6) (id of variable)
it become var10, [5, 6]?

so I can do,

if: script: var(10, [5,6,7]
do stuff
end?

if so, than it's exactly what I needed as I can reset it on the end of the event
back to [] if they fail.
Edited the demo to have a more functional example
Do you want me to make a demo with the scripting way too?

if: script: var(10, [5,6,7]
do stuff
end?
if:
script:
$gameVariables.value(10) == [5, 6, 7];
any way is good, as the mechanic require a scripting part
in order to make this work.

event 1, 2, 3 uses activating switches, each event has the same
scriptcall to check upon activating if all 3 switches are active.
if so, the scriptcall is activating.

I just need a nice adding for different event effect depending the
order.

see what you can do (maybe add Trihans version too (if not to much trouble).

I also saw you use RMMZ, as I use MV, but I can add MV project.exe on it
to run it in MV.

but it is highly appreciated (because this might help more people
extending nice mechanic 🙂
if A is 1st, than C and B than it's always 1 solution, which is not the case.
all answers of order are correct, just the outcome are different.
You didn't read what I wrote.

all three events will have the same code.
so the C event will also have the conditional branch "if step = 0", and that branch will mark the code for those cases of [CAB] and [CBA] as possible, and the same goes for the B event, marking if step=0 on the B event to mean the the codes for [BAC] and [BCA] will be set.

So no matter what event is used first, that event will mark in the appropiate variable or switch that the specific event A, B or C is the one that got first, no matter which one it is.

Original thread: https://forums.rpgmakerweb.com/threads/get-the-first-mid-last-index-variable-switch-event-id.148121/