So this will need a number of different parts working together to get the results you want. The button part is pretty easy, either using actual buttons or a styled label that is made to act like a button using the setLabelClickCallback function. Either way, your button needs to then call some sort of initialization function, which will create a table of directions, a table of valid targets, and any other relevant variables, like the mentioned actions you may want to take in a room.
Once it has all your variables made in such a way that your other functions can access them, it should kick off the cycle by grabbing the first entry from the directions table, enabling triggers to look for your targets, clear/create a table to record any found targets, moving the appropriate direction, and looking in the room if that isn't something that is done automatically when you move.
Your triggers, if they see a valid target, should record any matches by adding them to the appropriate table, and then when your script sees your prompt, it will look at that table to either move on if there are no targets, or attack the target of your choice, perhaps using particular actions you have setup in advance. Either way, you will want to disable the triggers looking for targets here.
Once you attack a target, you want to enable another trigger that will capture the death of your target, letting your script know that it is time to once again look at the room and look for targets, with the same steps here as when you are moving. Again, if there are targets, fight them, if not, move on.
Once your script reaches for directions to move in but gets nothing, it knows that it has finished, and can close things out.
There will 100% be multiple parts of this that are used in different contexts, so for consistency, I strongly recommend breaking things into smaller functions that perform just the specific block of actions that you need. For instance, have a function that preps to look for enemies (enabling triggers, clearing the target table, etc.), have a function that performs the 'end of look' decision making (disable target triggers, look for found enemies in the table, and either attack or move on as appropriate). If at all possible, you never want the same chunk of code repeated anywhere.
Here is an example of tables of targets and directions from a script I have seen used that does what you are talking about, for a wide list of selectable areas.
Code: Select all
["training ground"] = {
["dirs"] = {
"n", "w", "w", "e", "e", "e", "e", "n", "w", "w", "w", "w", "n", "e", "e", "e",
"e", "n", "w", "w", "w", "w", "n", "e", "e", "e", "e", "w", "w", "s", "s", "s",
"s", "s",
},
["allowed_mobs"] = {
["green dummy"] = "A practice dummy wearing green clothing is affixed to a pole here.",
["yellow dummy"] = "A practice dummy wearing yellow clothing is affixed to a pole here.",
["red dummy"] = "A practice dummy wearing red clothing is affixed to a pole here.",
["purple dummy"] = "A practice dummy wearing purple clothing is affixed to a pole here.",
["black dummy"] = "A practice dummy wearing black clothing is affixed to a pole here.",
["white recruit"] = "A recruit with a white sash is here, training.",
["cyan recruit"] = "A recruit with a cyan sash is here, training.",
["blue recruit"] = "A recruit with a blue sash is here, training.",
["jade recruit"] = "A recruit with a jade sash is here, training.",
["brown recruit"] = "A recruit with a long sash is here, training.",
["magenta recruit"] = "A recruit with a magenta sash is here, training.",
}
For the "allowed_mobs", what you see is the words used to target the enemy on the left, and how they appear in the room on the right.