MV Returning Variables to RPGM event from a plugin/script

I'd like to be able to evaluate the results of something, and return that to the event, but I'm not quite sure the best way to do so.
My implementation:
I've got a few "mini game" sort of plugin scripts written. When called, they open their interface, users can either cancel (backing out), fail (however a game determines failure) or succeed (however the game determines that). Any of those three close out the scene and return the game play to the normal loop.
IDEALLY, I want to do something like putting the mini game in a script call at the start of an if loop; if (miniGame==true) {...} essentially. If the player wins, the script returns true. If the player fails (or backs out), it returns false, and then we proceed from there.
To MY eye, I'm not 100% how to proceed within RPGM. I'm wondering about setting up a callback arrangement, but I've never been that good with those so I'm not sure how to proceed. Any thoughts?
If you mean that you're programming your game loop through the event editor and the event "returns" a true or false, RPG maker does not support that because events are not functions. What you want to do instead is for that event to set a switch to ON or OFF.

1703143474885.png


EDIT: Or if you mean that your script call will call your minigame which returns a true/false similar to the screenshot, I still recommend storing that boolean variable into an index belonging to $gameSwitches.
@Gensun that part wont work if the function don't exist,

@daMooseNeo do you want the way in a plugin or evented?
if you want it evented, what kind of mini game is it?

a switch can be ON and OFF and reset, but to win with a scrore,
use a variable value to check for win or lose.

but in order to help you om this mini game, we need to know what
this mini game is and how it works in order to set this up correctly.

evented or plugin depends what you exactly seek.
Okay...first question is do your mini-games actually work? Like, can you call the function to start them in the game and the player can play them?

IDEALLY, I want to do something like putting the mini game in a script call at the start of an if loop; if (miniGame==true) {...} essentially. If the player wins, the script returns true. If the player fails (or backs out), it returns false, and then we proceed from there.
That's not really a good way to try to implement it. You're talking about putting everything else the engine wants to do on hold and running your mini-game as a sort of side process. Not only is it complicated, it is quite possibly going to cause significant problems.

Why don't you simply choose one of your game switches to represent this and set it in your code?

When the player does whatever is necessary to succeed, you add the line $gameSwitches.setValue(X, true) and in the condition for failure as well as the processCancel() for your scene you set it to false instead. (or just set it to false as soon as the mini-game is initiated, and only change it to true if the player wins).

Then you can use regular event commands in the rest of the game to check that switch.
Okay...first question is do your mini-games actually work? Like, can you call the function to start them in the game and the player can play them?
Yea, they work perfectly. Its a pretty basic setup I have now that plays a variation on Lights Out and a combination Wordle/Fallout 3+ terminal hacking. I use the selectable menu because really we're just picking and "toggling" values on a board, so it works well. They load up, run, and close out just fine. My only real issue now is the Lights Out occasionally spits out an unsolvable board, so I need to bone up on my mathematics and/or review a best approach to other variants.

About the uses; a good deal of my game is going to be generated procedurally. The goal is to make these items spawnable without needing a lot of overhead to find particular variables and shuffle stuff around. Using the in-game switches and variables could get conceptually sticky, at least to my mind. I swore I had written about the proc-gen aspect, but it appears I didn't or had in a previous draft as I was sorting out the ask but deleted it, so apologies because that does make a big difference in the why of it all. Al ot of this COULD be solved with some simple switches. By having the game be able to return a basic true/false from the call, the generated event itself can track anything it needs to know via self switches~ IE find a treasure chest with a jammed lock? We open a mini game, play, and return. On success, we award the items, throw self switch A, and A displays the open chest. On failure, we display a failure message and they can go again or maybe we throw self switch B, and B shows a busted chest.

I'm already using something similar, but that is already a simple true/false eval; I've written in a D&D-style ability, skill check, etc. system and I have a simple "skill check" function that will accept a stat to check and a difficulty, handle the die roll and bonuses, and report back a success or fail; an NPC in my test town currently mocks me for my low stats when I can't pass the ability checks.
Another NPC intertwines with this: they ask for help breaking into something, and offer a few choices. First is a skill check; a simple pass/fail check. Next is a mini game trigger, which launches the mini game. WITHIN the mini game I can run a success/fail check easily, and pop a game message to that effect, but what I'm trying to do now is step that up a bit and allow the event to handle it itself via that return true or false.
As a design aside, knowing feelings toward mini games, the example is deliberate; when mini games are presented in the game, you can either run a relevant skill check and take those results or play the mini game and accept that outcome. Even wrote up some functions that allow demonstrating your odds of success on the skill checks to help decision making; currently the base character has a 45% chance of helping the old guy break into something via a skill check, and we get to see that, and we have around a 65% chance of impressing the NPC, which we also see~ I feel better about doing the mini game than taking the roll of the die on the old guy 🙂

ALL SAID though, ATT_Turan, you've gotten me a bit inspired about an approach. I'm already taking us out of the normal flow using the separate scene and menu system so when you said that, it occurred to me that wait, that's not ENTIRELY unusual. Messages put a lot of stuff on hold while they process and wait for the user input, choices put things on hold for an entirely different set of user input, and often then proceed with messages and more code, and things like battles put the rest of the world on hold.
So, at the moment, I'm sifting through the game interpreter elements regarding wait modes and the messages, choices, etc. If I can configure a custom wait mode, I think I can get what I want out of it.
So, at the moment, I'm sifting through the game interpreter elements regarding wait modes and the messages, choices, etc. If I can configure a custom wait mode, I think I can get what I want out of it.
Cool - good luck to you.

I still don't understand why it's necessary - as you say, if you've constructed a new scene that should already put a hold on other scenes, so it's really unclear exactly what is going on in your game that you think you need to stop or record or whatever you're trying to do.

As far as responding to the outcome of your mini-game, as I mentioned previously RPG Maker provides the tools for you to do that pretty easily.

Using the in-game switches and variables could get conceptually sticky, at least to my mind.
Why? They're just variables and switches like anything else you might use in your code.

Al ot of this COULD be solved with some simple switches.
And that's what's already there?

From a JavaScript perspective, I don't see what the difference for you is between saying, like,
Code:
outcome = did_the_player_pick_the_lock;
return outcome;
and
Code:
outcome = did_the_player_pick_the_lock;
$gameSwitches.setValue(15, outcome);

You just seem to be hung up for some reason on returning a value and working off of that, when that's not how it has to work.

But good luck with your project!
Well, maybe I'm missing something~ If the gap in the logic appears for you, I'd be happy to hear it.
From the proc gen mapping side, I'm using the last run of the Sanshiro script (with the extra mods from DreamX and SkillSan) and as a foundation and expanding it. Last I knew it was pretty commonly used, but if I'm wrong the short of it is: on your map you place your tiles for general space, floor, path, roof, wall, and debris, and then place your events for entering and exiting on specific map positions. After that, you can setup whatever other events you like, and set appearance rates. When the map is generated, the rules are followed, events copied and placed, and the map is traversable.
So from that standpoint, I'll have my exemplar script on the map, which then gets copied 0 to dozens of times around the map.
My concern about using specific switches and variables is that when I have a dozen of these guys on a map, I'm checking the same variable for completeness or value across an unknown number of instances, with a potential for one to interfere with the other(s).
"Talking" it out loud now, I suppose there's a scope concept I'd been skipping; the value only really matters if the player succeeds, and shouldn't be needed long term~ We might be able to reset it after handling things and flipping the local switches. Interact with the Event -> Play the game -> Get the Result -> Flip The Switch On Success -> Return -> Check the Switch -> Handle The Success -> Flip a self switch -> Reset the Switch.
As long as that pans out, yea, I was probably over thinking things~ We'll give it a spin.

[EDIT/Update] So, that did do the trick~ Tossed a parameter for picking a switch in the plugin script for the mini games and pull that, we're pretty good~ Just need to remember to reset the switch after completing the event success portion of the local script so it doesn't bork something else down the line~ May still run down the custom wait, but that's more out of curiosity now than necessity~
You can check out Game_Interpreter.prototype.clear which is a function called any time an event ends. You can alias that to reset that switch any time an event ends, reducing chances of errors in the future.
You can check out Game_Interpreter.prototype.clear which is a function called any time an event ends. You can alias that to reset that switch any time an event ends, reducing chances of errors in the future.
THAT is a spiffy tip, thanks!

Original thread: https://forums.rpgmakerweb.com/threads/returning-variables-to-rpgm-event-from-a-plugin-script.164031/