mjrgh / PinballY

A table browser and launcher ("front end") for virtual pinball cabinets.
Other
47 stars 22 forks source link

new coin feature: launch table only with credit #189

Open MicJeRon opened 3 years ago

MicJeRon commented 3 years ago

The ability to start a selected table only after inserting a coin (credit) would give the coin option a real practical use.

mjrgh commented 3 years ago

You could do this with Javascript, actually. (And this is just the sort of thing that I'm not inclined to turn into a native feature, because (1) Javascript implementation is feasible, (2) it lets you make it work the way you want rather than being stuck with whatever I come up with, and (3) if I implemented everything like this natively, it would bloat out the Options dialog even more than it already is.)

This could make a good Worked Example at some point, and if you want to write something up along those lines and send it to me, I'd be more than happy to consider including it. Here's a basic outline of how I'd see implementing it. I think you want to listen for command events (see Javascript scripting > Events > Event Types > CommandEvent) and intercept command.PlayGame commands. When you see one, check the credit balance - you can access that through optionSettings.getFloat("CreditBalance") (see Javascript scripting > System Objects > optionSettings). If it's zero, you'd cancel the command (to prevent the launch) and pop up a UI message instead. There are numerous ways to show messages; I'd probably want to do some kind of graphics overlay and sound effect, but that's a whole other can of worms. An easy way to get something working initially would be use mainWindow.message() (see Javascript scripting > System Objects > Window Objects > mainWindow), which pops up one of the standard error/information type message boxes (PinballY-style, not Windows dialog-box style).

If you wanted to consume one credit on a successful launch, you'd just use optionSettings.set("CreditBalance", n), and let the PlayGame command proceed as normal.

MicJeRon commented 3 years ago

Thank you for the detailed answer. Well, unfortunately I can not implement it for me because I don't have the knowledge in this. But I can try to take away the worry that an implementation here would blow up something unnecessarily. As I understand it, one additional checkbox "Allow start table without credit" or "Allow start table only with credit" would be sufficient. And only with this checkbox the current implementation of the coin feature really makes sense to me. It would raise the pure simulation character to a practical feature for everyone uses a coin counter.