Help with event rotation

Hi!


I need some help.


I've added the mouse plugin, and it seems that I can click on some event and I can make it print the message in the javascript console.


So I know that clicking on the event works every time.


The event is using an actor image, and I set it up as a starting point looking down (the direction).


Now I want that every time I click on the event, it should turn in clock wise direction, first click to the left, second time to go facing up, third click it should go to right and fourth click it should return to the original position (that would be facing down).


The problem is it not working as it should, every click is registered in the console, but it always prints that is facing right over and over again. Also is not really rotating.


I managed to get it rotating if I move my actor around it, it moves only one time, but still can't say why this depends on the actor.


Please help, thanks!


My code is below...

Spoiler
◆Comment:click_activate!
◆Script:console.log("clicked");
◆If:This Event is facing Down
◆Script:console.log("clicked event=down");
◆Set Movement Route:This Event
: :◇Turn Left
◆
:Else
◆If:This Event is facing Left
◆Script:console.log("clicked event=left");
◆Set Movement Route:This Event
: :◇Turn Up
◆
:Else
◆If:This Event is facing Up
◆Script:console.log("clicked event=up");
◆Set Movement Route:This Event
: :◇Turn Right
◆
:Else
◆If:This Event is facing Right
◆Script:console.log("clicked event=right");
◆Set Movement Route:This Event
: :◇Turn Down
◆
:End
◆
:End
◆
:End
◆
:End
◆Exit Event Processing













issue.png
There should be a much easier way to do this - MV already has mouse support by default, so you can click on the event without having to use any script options.


if you want the event to rotate in a specific order, then you can simply make several event pages. First event page is the event looking down and set to action button, in the contents turn self switch A on. Create a new event page with the condition set to self switch A is on, set the event image to right/left (whatever you want), action button as well, then turn self switch A off, and turn self switch B on. Create a new event page for self switch B etc.


Keep doing this until the final event page, where you turn off all self switches, and it should cycle back to the beginning.
by default, all events turn into the direction of the player when activated - your mouse script doesn't change this, and it happens before the click is processed.


To prevent that, you need direction fix checked - which would also block turning.


Solution: check direction fix, but in the move route commands turn it off directly before the turn command and on again after that turn.
Right, forgot about the direction fix! Definitely need that as well.
@Arise...


Try putting a 'Wait' command after each 'Set Movement Route', to give the system time to do the turn and 'forget' the mouse click..?


Be wary, too, of 'This Event'; it may pay to designate specifically the Event you wish to control (EV001 in your example...).


Just sayin'; hope this helps.
Andar's solutions proved working miraculously, I still can't wrap my head around his explanation... 🙂


Last question for @Celianna: how should I do the clicking with the mouse on the tiles without using my Actor character? He is not going to move in order to interact with the event...


Final code is like:

Spoiler
Code:
◆Comment:click_activate!
◆Script:console.log("clicked");
◆If:This Event is facing Down
  ◆Set Movement Route:This Event (Wait)
  :                  :◇Direction Fix OFF
  ◆Set Movement Route:This Event (Wait)
  :                  :◇Turn Left
  ◆Set Movement Route:This Event (Wait)
  :                  :◇Direction Fix ON
  ◆
:Else
  ◆If:This Event is facing Left
    ◆Set Movement Route:This Event (Wait)
    :                  :◇Direction Fix OFF
    ◆Set Movement Route:This Event (Wait)
    :                  :◇Turn Up
    ◆Set Movement Route:This Event (Wait)
    :                  :◇Direction Fix ON
    ◆
  :Else
    ◆If:This Event is facing Up
      ◆Set Movement Route:This Event (Wait)
      :                  :◇Direction Fix OFF
      ◆Set Movement Route:This Event (Wait)
      :                  :◇Turn Right
      ◆Set Movement Route:This Event (Wait)
      :                  :◇Direction Fix ON
      ◆
    :Else
      ◆If:This Event is facing Right
        ◆Set Movement Route:This Event (Wait)
        :                  :◇Direction Fix OFF
        ◆Set Movement Route:This Event (Wait)
        :                  :◇Turn Down
        ◆Set Movement Route:This Event (Wait)
        :                  :◇Direction Fix ON
        ◆
      :End
      ◆
    :End
    ◆
  :End
  ◆
:End
◆Exit Event Processing
@Arise no need to make three set move route commands for one move command each - you can combine all three commands (fix off, turn, fix on) into a single move route.
Thanks, you are right about move comand on same line!


Only thing is I'm new to this kind of "scripting" language and instead of moving around like a fish in the water I feel more like an elephant in a porcelain store. 🙂  


Hence the "amateurish" style of my writing code.
Then I suggest you follow the link to the starting point in my signature.


Yes, those tutorials will take time - but it is time very well spend, because you'll improve your development speed and experience a lot that way.


(and it's called eventing, not scripting, because scripting is changing the engines on an even deeper level (plugin writing)
Question, if I do this in my own game, would I need to make all the ifs to check direction? Would a Turn 90º Right not work?
If you want to rotate in all four directions then yes, you need 4 ifs, if your starting location could be in any direction.


You dont really need 4 ifs, you need actually 3 ifs and an else, but all the ifs must be with an else clause also I think, unless you arrange them in order... because you dont want after one if condition to get triggered again by the next if condition.


What exactly is your concern with the above posted eventing code?
Well, I was thinking about instead of putting the three ifs and turning in the next direction just putting to turn right 90 degrees.


Wouldn't that make it more efficient? Or does it not work like that with the mouse/touch?
Oh yes, it works just fine if you only want the animation. Code below for posterity.


The ifs are good only if you want to do extra actions/scripting based on the current position.

Spoiler
Code:
◆Comment:click_activate!
◆Set Movement Route:This Event (Wait)
:                  :◇Direction Fix OFF
:                  :◇Turn 90° Right
:                  :◇Direction Fix ON
◆Exit Event Processing

Original thread: https://forums.rpgmakerweb.com/threads/help-with-event-rotation.68352/