In another thread, I asked if anyone had successfully used the Alert() method, which is an option when using beanshell expressions. Someone said some module had, but I don’t remember which one and where, so I decided to post this because I can’t figure out how to get it to work.
I have a game where each player has money (credits), which they are constantly spending and earning. The cardboard version has a lot of cardboard credit tokens to handle this, but I found It to be a PITA to manage credits in the electronic version. So instead each player has a global property in their own map window that is the total credits they currently have (“credits”). They also have a bunch of buttons (a keypad) they can push to add or subtract amounts to their credits. For example, to spend 70 credits, they might press the “=50” and “-20” buttons. I show the credits in a static piece that has a text trait for “credits.”
Sometimes though I find a player may accidentally spend more credits than they have, and I thought, gee, wouldn’t it be nice if I popped up an alert window saying “Stop! You don’t have enough credits for that!” Note that the global property is numeric, and its minimum value is negative (e.g. -1000).
So in a keyboard button (for example, the “-10” button, but I would have to do something similar for all negative buttons), I would set a global property trait where I incremented/decremented that player’s credits (hopefully) like this:
Credits = { if (credits < 10, alert(“Not enough money”), -10}
This would work, or could work or might work, if alert() returned a 0 or any numeric value, but it doesn’t, and I don’t know what it returns. Actually, when I tested this, I found no matter what credits was, I got the same, single result: credits got decremented by 10 AND the alert popped up. Yes, both true and false results. Also an error message showed up in the chat window.
I then tried fooling it by assuming alert() might return the “” string or null, so I replaced alert() with 0+alert() and “0”+alert(), but vassal would have none of it. So since most/all places I would use alert() require expressions, particularly numeric expressions, I can’t figure out a way to make it work. If it truly is not possible, I’d request a vassal enhancement to have alert() return something useable—zero, for example.
I am at wit’s end here. A virtual lollipop to anyone who can get alert to work in this scenario.