Make a conditional If statement in a Move Route that changes the graphic of the event.

I want to use a if then statement in the move route of an event to chance the graphic of the event and have it run once so the graphic changes when it switches to an event page and then you can trigger it with the action button. I will have many of these events all wit their own self variables from the self data script i found and all will change the graphic differently. I DO NOT WANT A TON OF PUBLIC VARIABLES for each event as they would all need one per graphic per event so like 15 x 50 variables is too much. so far i have this:


(self_metadata("CropType") == "Wheat") ? set_graphic("$Wheat", 0) : nil


I tried a bunch of different ways including...


if (self_metadata("CropType") == "Wheat") then set_graphic("$Wheat", 0) end


what to do...
In your move route, use a script command:


set_graphic("$Wheat", 0) if self_metadata("CropType") == "Wheat"


I'm not familiar with the self data script you're using, so everything after the if is based on the assumption that you have looked up the correct way to test the value of the CropType metadata.  What I am sure of is that, as a one-liner in a move route's Script command, the command has to come first, and the condition after.
I had to finagle it a bit. the self_metadata call couldn't be referenced so i used the global reference version and got it to work: 


set_graphic("$Wheat", 0) if $game_self_metadata[["Forest_of_Yeldarb", "Plot01", "CropType"]] == "Wheat"


Edit: It didn't work after all. and it isn't trowing any errors...
Where are you putting this command?  If you put it on the event and then make another page active, then the sprite that's on the other page will be shown.  You need to execute this script call AFTER the new page is active.
I got it to work. I was using the map and event names not the ids. the new code is:

set_graphic("$Wheat", 0) if $game_self_metadata[[7, 1, "CropType"]] == "Wheat"
haha!  It took a while, but you feel good when it's finally working 🙂
now i need a piece of code that outputs the id of the current event that is activating the move route. like:

set_graphic("$Wheat", 0) if $game_self_metadata[[7, this.event_id, "CropType"]] == "Wheat"



But obviously this.event_id doesn't work.
If you're doing it inside a move route, just try @event_id instead.  Steam won't let me open Ace because it thinks it's already running, so I need to reboot before I can check it for you, and I can't reboot because I'm uploading something that's going to take a while.


If @event_id doesn't work, try @id instead.


You can also use $game_map.map_id instead of 7, so you don't have to hardcode the map id.  This makes it easier to copy/paste the same event onto the same or other maps, without having to change things.
@id and  $game_map.map_id worked. Thanks so much. I had been working on this for a while. new code is:

set_graphic("$Wheat", 0) if $game_self_metadata[[$game_map.map_id, @id, "CropType"]] == "Wheat"
Do you have a link to the metadata script?  I can give you a small script to add, which will make that whole $game_self_metadata[[$game_map.map_id, @id, "CropType"]] a whole lot easier to type - it'll be more like metadata("CropType") is all you need to enter.  In fact, the script may already have an easier way to access it.

Original thread: https://forums.rpgmakerweb.com/threads/make-a-conditional-if-statement-in-a-move-route-that-changes-the-graphic-of-the-event.59371/