Mine Cart Problem

Hi everyone,

Here is what I am doing. I got my hero climbing in to a mine cart to ride it. The controls mechanics are simple, if I push the joystick in the direction of the rails once, the car will roll down the track by it self. if I press the cancel button, (Brakes) the car will stop. When the car hit a switch Tile, it need to go left or right (Depending what direction the switch is set) I am using yanfly's RegionEvents Plug-in with a common event to control the car. here is the Code in the event:
◆Script:$gamePlayer.updateEncounterCount()
◆If:Boat is driven
◆Loop
◆If:SwitchTouch is OFF
◆If:Button [Down] is pressed down
◆Set Movement Route:Player (Wait)
: :◇Move Down
◆
:Else
◆If:Button [Up] is pressed down
◆Set Movement Route:Player (Wait)
: :◇Move Up
◆
:End
◆
:End
◆
:Else
◆If:SwitchTouch is ON
◆Jump to Label:Stop_Here
◆Break Loop
◆
:Else
◆If:Button [Cancel] is pressed down
◆Jump to Label:Stop_Here
◆Break Loop
◆
:End
◆
:End
◆
:End
◆
:Repeat Above
◆
:End
◆Label:Stop_Here

I tried to do loop, but I am having trouble interacting with the Switch Event.
Switch Event Code here:
◆If:Boat is driven
◆Control Switches:#0138 SwitchTouch = ON
◆If:Player is facing Left
◆Set Movement Route:Player (Wait)
: :◇Move Up
◆
:Else
◆If:Player is facing Right
◆Set Movement Route:Player (Wait)
: :◇1 Step Backward
◆
:Else
◆If:Player is facing Down
◆Set Movement Route:Player (Wait)
: :◇Move Right
◆
:End
◆
:End
◆
:End
◆
:End
Any Ideas what I can do to make this work?
Please give screenshots of your event pages - the content is not the entire event.
Things like triggers, page numbers and page ordering, conditions and more are affecting how the events react in such cases...
here are the sceenshots
What is on page 2 of the switch event? Because that page will have priority and the first page never executed if you set the wrong conditions there
How exactly is the common event triggered? Can you give a link to the website of the plugin?
Because if I remember correctly, the region events of that plugin are only triggered if the player moves the party on the tile, not if the party is moved there by an automatic move route. Can you test that by moving the cart manually?

But your entire common event is strange - why do you check for button presses just to move the player into the direction of the button press, why don't you simply let the engine handle movement the regular way?
page 2 of the switch event as the same, but reverse controls.
http://yanfly.moe/2015/10/19/yep-17-region-events/

as i states in my first post, i wanted to move the car in the the direction when i push the directional button. ie push up makes the car facing up and roll automatically in that direction.​
as i states in my first post, i wanted to move the car in the the direction when i push the directional button. ie push up makes the car facing up and roll automatically in that direction.
But that is exactly how the default moving works, no need for an event to do that.
Any Idea how I should achieve this problem? a nice tutorial would be great!
Ok, it seems that my idea can not be done in this engine. I may have to come up another Idea for my mine area.
Ok, it seems that my idea can not be done in this engine. I may have to come up another Idea for my mine area.
Anything can be done - but somehow you're not describing your idea correctly, because from what I understand, you don't need any event at all for that - going left when you press left, up when you press up is the default behavior of any movement on the map.

So please describe in detail what you want, and specifically what the difference is between your idea and the regular map movement.
I think @MikeRPG33 wants the mine cart to start rolling in the direction of the button press, and KEEP moving in that direction without additional button presses until the player stops it. Correct?

I'm confused about how you have your event set up currently, so I'm afraid I'm not sure how to go about fixing it. But I would think you would want something along the lines of the following:

Spoiler
Since the trigger for the common event is the player stepping on a tile in the region, you should only need to check that the player is in the minecart, and what direction they are facing in order to start your move loop. Once in the loop, you should only need to check if they hit cancel, or they land on the switch tile. Then your switch tile needs an event with a touch trigger to handle changing the minecart direction.

Interestingly, this route would require two different regions/region-triggered common events, one for Up/Down track and one for Left/Right track. And handle the switch tiles entirely by their own events (don't make them part of either region).

If Boat is driven
If Player is facing Up
Loop
If (cancel button) is pressed down
Break Loop​
If (condition set by hitting switch tile)
(Jump to Label or Break Loop, as appropriate)​
Move Route: Player Wait
Move Up​
If Player is facing Down
Loop
If (cancel button) is pressed down
Break Loop​
If (condition set by hitting switch tile)
(Jump to Label or Break Loop, as appropriate)​
Move Route: Player Wait
Move Down​

(Sorry for the multiple edits. Preview was showing me different formatting than the final post and I was having trouble getting it right.)

@MikeRPG33 , please avoid double posting, as it is against the forum rules. You can use the "Edit" function on your posts to add additional information you've forgotten or respond to multiple people. You can review our forum rules here. Thank you.



If Llareian is correct, then your problem is that you need some sort of loop for the move route. As is, you only have it to set 1 tile at a time. And since you don't know when the player will press stop, you can't set a move route for a certain length of time.

If you want to event this, I don't think you need the switches. I would just have it check if the "start" button is pressed, then in the if statement make a loop. The loop would move 1 tile then check for the cancel button. If the cancel button has been pressed, then it exits the loop, if not it repeats. I honestly don't know if this is the best way or not without testing, but it's what I would try first.

edit: Maybe something like this? I've never really utilized the break loop and I'm still on my first cup of coffee so this may not work. I've only used labels and jump to label for looping.

Spoiler
loop.png
ok tried your suggestions and did not work. Here is what i set up.

01.png
02.png
03.png
04.png
05.png
06.png
07.png
I'm about to go out the door, so I can't test right now. To me, it looks like you are seriously overcomplicating it. And again, I'll have to play a bit to test exactly how the break loop functions, but I'm not understanding why you have break loops inside loops with nothing else happening. But, perhaps I need to look more closely.

If this has not been solved later when I'm home, I'll give it a go and see if I can get something to work.
no, it won't work - because you messed up the loop and break loop conditions.
For example, in your very first picture, you probably wanted the set move route to continue until the button is pressed - that means the set move route needs to be outside the conditional branch where you break loop, but inside the loop.

In your second picture, you have a double break loop and conditions after the break loop - but the break loop command already stopped the loop and continued after the repeat.

And so on - I suggest next time, you design the logic in a flow chart before placing the commands, that usually prevents such mixups.
ok i know what you mean, i edited the script your suggestion and it works, until it hit the end of the vertical track. and it freezes.
update your screenshots to the current version and we can check again - the comments above where only examples, I didn't check for every error.
here the latest script for the car. I decided of using the switch to change direction of the car on the switch track, I decided to go for the gates instead.
To let you guys know, I finally fixed the problem. On the corners and switches you need to add a regular event, to tell the player what direction you need to go on what you direction you are facing. You also need to make a variable in your position that equals to the region ID. in this case its Region ID #3. this tells the loop when to break. (See pic for more Detail)
03.png
04.png
05.png
I tried sending this reply last night, but got blocked by the error message everyone was experiencing. (Yay for fixing urls!)

So, I played around just a little bit and got a small sample working. Of course, to implement it fully, you'd need to expand the system a bit more. But, I really feel like you are overcomplicating things. It's easy to do with events, especially systems like this.

The first thing I did was remove the vehicle aspect. I am using a car and roads in my test. I made a car event. When the player interacts with it, it changes the character's graphic to the car graphic. I used a switch to "erase" the car event's graphic. Normally you would use a self-switch to do this, but I used a switch, with the thought that you might need to turn it on again later, or leave it off.


Next I made only one event to trigger the action. You would need to put these more isolated events in spots where the minecart would start or stop, but I just did this one to test.

For the actual movement, I only tested one direction, but it works. The biggest issue is that you have to more hold the Esc/cancel button down instead of simply pushing it. Because of the way MV loops through events, I think this is going to be necessary no matter how you event it, and perhaps was part of your problem. But essentially, if the key press is not occurring at the exact split second (literally) that the program reads that "If" statement, it won't register, thus having to hold it down. I'm not sure if there is a solution, of if you would need to indicate that to the player somehow to hold down the cancel button until it stops.


I'm not sure I would use the region script the way you have - to process a common event each step of the way. If you set up your event similar to mine, the action will keep looping until the escape is pressed, even with that one event. I would perhaps instead use the region script around the roads/tracks with an impassible setting, to keep the cart on the tracks.

edit: I see you posted as I was finishing up my post. I'm glad you got something working.

Original thread: https://forums.rpgmakerweb.com/threads/mine-cart-problem.74428/