FreeSpace Releases > Scripting Releases

Prompt Box: An easy way to get a user response

(1/7) > >>

How many times has this happened to you?

"During a mission, I just asked the player a question. How do I get a response out of him?"

Normally the answer to that question has been "Well you just throw up a training message and ask him to press 1,2,3 or 4!" C'mon bro, this isn't 1999 anymore. Everyone has, at the very least, a mouse to select things.

The PromptBox is now better than ever! For even you FREDders! With the magic of scripted sexps, all that ugly script-eval stuff is a thing of the past. Now you just call a single sexp, and then check a single sexp for a response. And that's it!

Note to use scripted sexps, you need a nightly after January 19, 2018 (or 3.8.2 or 3.10 or 4.0 whatever the next official release number is)! The prompt box should be mostly backwards compatible if you already have it in your campaign. This version does not use any hud gauges, so it may look kind of small on monitor setups larger than 1080p. I'll figure out a way to fix that later...


Includes a sample mission so you can see how the scripted sexp works.

Original Post Below...
Hidden Text: ShowThis make this easier for everyone! (Click for video)

For those of you that didn't go "Did that years ago", there's a link at the end to all the files you'll need to set this up in your own campaign, including a test mission!

Here's how it works. The LUA script included just does the complicated stuff. It'll do all the hud gauge appearing and all the mouse stuff. It also has a function that FRED can take the line number that the player has just clicked. If you're fine with the included files, then you don't need to touch the lua script at all.

On the FRED side, you need to call different functions to activate certain parts of the script, set the custom gauge lines to whatever you like, and the mission logic to properly use everything together.

Custom HUD Gauges:
You can use set-hud-text or set-hud-message to have these gauges display text. The LUA script will take care of making them visible/invisible.
PromptBox - Use this to pose your choice to the player
PromptBoxOpt3 - Use these to let the player choose a response

LUA Script Functions to use in FRED:
Use these with script-eval:
proBoxInit() - Initialize the Prompt Box system. This is called on every gameplay start, so it shouldn't be required unless you need to reset everything for some reason.
proBoxAllowPause() - Will "pause" the game when the PromptBox is active. Actually this just slows the game down to 1% time compression, but it should give you plenty of time still.
proBoxDisallowPause() - Undoes the above
proBoxOn() - Forces the PromptBox to be on. If proBoxAllowPause() was called before, it will "pause" the game. This will also sort of steal your mouse focus. This is a lot more noticable when you do not have the pause option on.
proBoxOff() - Forces the PromptBox to be off. This will restore time compression and any other settings.
proBoxModeFree() - Puts PromptBox into free mode, where the player can call or dismiss the PromptBox with 'Alt-C' (Super note, this is NOT bindable, LUA doesn't care what is or isn't bound)
proBoxModeLock() - Undoes the above. This can be handy to temporarily lock out the player from bringing up the interface while you have a long talk session going.
proBoxSet(integer) - Sets the Prompt Box settings. The integer you put in between the brackets will be number of options that will be available to click. Inputting 1 through 5 will allow clicking on 1-5 lines. The lines are activated from the top going down. So proBoxSet(3) will make the top three lines clickable. An input of 0 will obviously not allow any clicking. An input of -1 is a shortcut, it will clear all the lines of text and reset time compression to normal. This is mostly used internally, though if you want to use it, go ahead.
proBoxLock(integer) - Allows you to lock a specific line (line integer). Stops it from being clickable, even if it would be allowed.
proBoxClear() - A shortcut that just clears all the text on the lines.

Use these with script-eval-num:
(These return values, to be used with arithmetic operators like '=')
proBoxValue() - Returns a value from 0 to 5. 1 through 5 if an allowable line has been clicked, 0 when nothing special has happened.
proBoxInFreeMode() - Returns 1 if you are in Free Mode, 0 if you are not.

Boy! That sounds like a LOT of work...

It's not really. Most of those functions are for the insane FREDders that want to pull off a free environment so they can talk to anyone at all.

If you want to use it in the most simple ways, just look in the included mission. From "CHOICE 1 - Choose Sidekick" to "Continuing On" is all you need to ask the player to make a simple choice.

If you want to use it in the most complicated ways... well... you can look in the mission and try to decipher what I did.

Basically what you want to keep in mind is "how can I make sure there is only one path to every response." You can do this through variables (to check who we are talking to), bit-wise operations (to check what options we've chosen before) and invisible mostly-unused stats like simulated hits (its a great ship-specific variable!). Another thing is to completely avoid using is-event-trues and chains in your repeating events. Beyond that... it's... kind of complicated. If you've got any specific questions on why I did certain things, I can certainly try to explain.

DOWNLOAD: Text: Show

General Battuta:

Now that's something plenty of modders will use, that's for sure.

inb4Freespace: the RPG


--- Quote from: General Battuta on February 15, 2013, 10:33:35 pm ---sweet

--- End quote ---

Shivan Hunter:
Whoa, so I'd seen this in a screenshot from you before but I never realized it actually paused the mission to force a response- that's pretty amazing. IIRC those training-msg choices are used a bit in BP...


[0] Message Index

[#] Next page

Go to full version