Enemy detection system

Hello, everyone! 🙂

I'm creating my first game using RMMZ, I tried to create a variable that in "others", I selected "steps", to be able to get the information of how many steps were taken, and together with that I created 3 variables that separates in (<)- of 10 steps; (>)+10 of steps; and (>)20 of steps, and each one was to play a different sound effect, but the only one that works is the -10 steps...

I don't understand...

I thought it might be the program counting the total number of steps I've walked so far, but I've played for 10 minutes and walked a lot, and even so the only one that works is (<)-10 steps...

If anyone can help me with this, I'd be very grateful!

It's a very simple system that will help the player to know more or less when a new enemy will come, and on this map it's set to 20 steps on average, so I thought it was something very interesting to add to the game, and after trying for hours I didn't get any results even trying to use the common event, and the program itself doesn't have any tool that can do this, so maybe I need a plugin of my own for this...?

I really have no idea if it's possible without a plugin.

That's it, and thanks for your attention!

Oh, and about the 3 options, I've separated them into conditions of course (I forgot to mention that).

That's why I can't understand why it doesn't work...
The steps IS counting the total steps since new game, nothing else.
to compare you'll need two variables, one storing an older value and one the current value, and then check the difference.

we cannot tell you what you did wrong because you never posted a screenshot of what your event code is, so please post that and we can tell then what you did wrong in your logic.
I didn't quite understand how to create these two variables as you said, but I'll leave some screenshots.

(After posting here, I also tried to add some images that move, and the color line changes as the sound effect changes, along with the variables of (<)10 steps; (>)10 steps, and (>)20 steps.

(Another important thing to say is that "self switch" and "item" are only enabled because I don't want to leave the event running, as it doesn't work, so it wouldn't make sense to leave it in the game)
that will never work.

you'll need the multiple variables I mentioned

this is the basic prinziple:

control variable zerosteps = steps
This is to be used when you want to reset the steps

control variable current steps = steps
control variable difference = currentsteps - zero steps

Now you can check the difference in conditional branches to see how many steps have passed since you set the zerosteps.
However that number will never be negative - you cannot remove steps or count into the past, steps are only counted up.
So I don't know what you even try top accomplish with a check for negative 10
Regarding -10, I meant (<)10 steps (sorry! I didn't explain myself properly)

In order not to compromise the previous process, just to create the basis I created another page to try, but I'm not sure if it's correct...
In addition to what @Andar indicated above, it also looks like you have created infinite Loops.

A Loop just repeats whatever is in the Loop until you tell it to break with some sort of condition.

In your Loops, you just have Repeat, which goes back to the start of that Loop. Since there is nothing in your Loop, once the Loop is triggered, it will just endlessly Loop and never do anything else.

So, since this is a Parallel Event, if it starts running when your Steps are <10, it will immediately get stuck in the first Loop and never do anything else.

Maybe I am missing something, but I think your understanding of how Loops work might be an issue as well.
I'm not sure if it's wrong, but I'll leave 2 screenshots below that have images in the loop of (>)10 and (>)20 steps.

They are separated into different conditions, being (<)10; (>10); and (>20) steps.
In addition, there is also a last condition that is set to (>)30, so that when it reaches 30 steps, it doesn't allow it to exceed that value, and at the same time it takes it to the "start" label.
You still have a problem with your Loops. A Loop will never break unless the condition to break the Loop is INSIDE the Loop. Because the Loop just repeats whatever is IN the Loop and the Event will never check anything outside the Loop until it is broken.

So you need some condition at the end of each Loop, just before the Repeat Above, to check to see if the Loop should stop.

If you only want what is inside the Loop to run once and then the Event should start at the beginning again, you don't even need Loops to do that.
but I'm not sure if it's correct...
no

Your CANNOT set steps to zero.
the variable zerostep has to be set to the number of steps you want to start counting.
That number will likely in the hundreds, but it is called zerostep because that is the number from which you're beginning to count the difference in steps.
you cannot use the =0 as you have in that event, and you CANNOT set current steps and zero steps one after another, they have to be set at different times.

that is why I said zero steps needs to be set when you want to start counting.

So your question should be: when and where do you want to start counting the steps?
that is a question you never mentioned, only how many steps after counting.
I tried to do as @ZombieKidzRule , and as you can see in the video, it still doesn't switch to the next variable.

And @Andar , it didn't really cross my mind to ask where I should put the variables.
I'll leave a screenshot of how I thought about leaving the variable isolated from the others, but only the "zero step" one, because the others I don't know where to use.

I put the "step" condition inside the cycle, telling MZ how many steps it should change to another variable, but it didn't work...
Would it be necessary to put the "step" variable in another position as @Andar said...?

As you can see, even if it goes beyond 10 steps, it continues to play the images that are in the loop, including the audio that is in the (<)10 conditional, whereas if it were moving on to the (>)10 conditional, it should stop the previous sound effect and play the other sound effect that is in that same (>)10 conditional.

Just to confirm I'll say it, but the audios are only inside the conditionals, and not inside the loop, so it's easy to tell if it's going from one conditional to another.
Do you even read our explanation?
for example in post #6 you were told that your loops are completely wrong and will always break your events, and you still use them.
not to mention that you haven't understood anything about my explanation about step countin.
The zerostep variable MUST NEVER BE SET AT START.

When do you want to start counting the steps? in which situation?
Answer THAT question first before doing anything else.
Okay, all right, I'll explain.

About the loop, I'm trying to use it because it's necessary to keep running the images to achieve the expected end result, because without the loop, the images will end at the end of execution, or am I wrong?

About the "zerostep" variable, I understood that it needs to be somewhere else, but I don't know where to use it, and I apologize if I wasn't clear in saying that.
About the "zerostep" variable, I understood that it needs to be somewhere else, but I don't know where to use it, and I apologize if I wasn't clear in saying that.
from where do you want to count?
"less than 10 steps SINCE WHAT?"
because without the loop, the images will end at the end of execution, or am I wrong?
yes, you are wrong.
currently your loops would never end because there is no break loop command inside, which means once you are inside the loop your game has ended for the player.

what is the condition under which you want to end the loops? That is what is missing there.
About the first question:

Yes, I want the (<)10 condition to play the image and audio shown in the video, so it should be zero steps, or 1 (it doesn't really matter), what's important here is to count as soon as the character enters the map. In other words, 0 steps. That's why I've been trying to use a (<)10 condition. That way I could tell the MZ to execute the commands inside it only after 10 steps, and then as the character walks, move on to the other 2 variables of (>)10, and (>) steps.


About the second one:

As you can see below, I added a condition inside the loop to take it to other variables, and it still doesn't work.
Captura de tela 2024-04-11 183543.png
Captura de tela 2024-04-11 183600.png
Captura de tela 2024-04-11 183619.png

In fact, before that I tried the "stepzero" variable at the start of the event, but 1 hour ago I left it without anything as you can see in the first screenshot because I didn't know where to use it.

If that's the problem now, I'd be happy to know where to use it.

In fact, if instead of a loop, you simply let it continue executing the commands within the condition infinitely, the image will restart, which isn't exactly a problem, but with the loop it has a better level of design.
I could be completely wrong, but I don't think you want your Conditional Branches and Loops nested within each other. The subsequent Conditional Branches and Loops will only run if the previous Conditional Branch and Loop are met. Sometimes you might want that, depending on what you are trying to achieve. But if you don't do it right, things just won't work.

Have you watched and recreated any basic tutorials? I'm just asking because it seems like you might be misunderstanding some basic concepts.

Also, you might find it helpful to use Show Text as a means of telling if the Event is running correctly or where it might be having problems. Use Show Text quite a bit for testing purposes and it can be very useful for troubleshooting.
I understood. Great idea!



From now on I will do what you told me.



Regarding your question, I haven't seen any tutorials. I'm just trying to get an idea out of my head and into the game.



I'll continue testing with texts, but thank you very much for helping!



You told me things that certainly helped me better understand the use of conditions! (⁠^⁠^⁠)(⁠^⁠^⁠)

I did it!

Unlike what I've done so far, I've changed my thinking and started using other pages.
When you reach X steps, it takes you to auto switch A and B.

But a problem has arisen.

Maybe I'm doing it wrong, but what I'm trying to do now is set the "step" variable to 0, and then make page 2 of this event that has the "step" variable at 0 be executed, and then redo the whole process.

Am I wrong about something?

After page 2, on page 3 there is a step condition of 10 and on page 4 it is 16.


So I can think of two things now.




Am I making an error in the final process in resetting the (step) variable, or for reasons of MZ priority, it does not execute the previous pages even if ONLY ONE page is fulfilling the conditions...? (I don't think RM would do that...)




Regarding operation, everything works correctly until then, as I mentioned in the message above, where I try to reset the number of steps, but it seems that it is not returning, as it continues to execute what is on page 4, which has a way of conditioning the variable of ( step), with value 16.




I hope the explanation is clear this time.
what's important here is to count as soon as the character enters the map. In other words, 0 steps.
No.
As I said several times you CANNOT set steps to zero.

What you need to do is to make a map event autorun with exactly two commands:
control variable zero_steps = game data: steps
erase event

That will set the zero step marker to the current steps on every map entry.

Then in your event, you start with the following two commands:
control variable difference = game data: steps
control variable difference -= zero_steps

THEN your variable "difference" will contain the number of steps since entering the map.
And your event will work once correctly, because you never set the zero_steps again - to have it work multiple times you would have to answer when the steps should be reset and recounted, because that would determine where else the zerosteps need to be set.

By the way, "exit event processing" is useless like you placed it.
Exit event processing tells the engine to jump to the end of the event, and it is already there.
And since its a parallel it automatically restarts on exit event processing.
Okay, I did what you said, but please help me with one last thing.

This "control variable difference", where is it found? (I don't usually use the program in English, so I didn't know it existed in MZ. Only now am I using it to better understand the tips)

Once understand where to put these last two commands, you just have to finish the event.
that is the control variable command, with a variable named "Difference" to make it clear to you that you are not counting steps but the difference between two different numbers of steps, one set by the marker zerosteps and one current
and inside the control variable you'll use substraction for the command to substract the zero_step number
Yes, I get it! It worked!

But it doesn't reset to zero even though I put the variables as you see in the picture at the end of the command, using the (>)30 steps condition to reset.

Original thread: https://forums.rpgmakerweb.com/threads/enemy-detection-system.167642/