Hard Light Productions Forums

FreeSpace Releases => Scripting Releases => Topic started by: Axem on February 15, 2013, 10:32:32 pm

Title: Prompt Box: An easy way to get a user response
Post by: Axem on February 15, 2013, 10:32:32 pm
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!

(https://i.imgur.com/pu8RHVa.png)

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...

SEE HERE ABOUT THE PROMPT BOX NOW (https://www.hard-light.net/forums/index.php?topic=94909.msg1870764#new)

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

Original Post Below...
Hidden Text: Show
This make this easier for everyone! (Click for video) (http://www.youtube.com/watch?v=0vJOgPWDDBc)
(http://lazymodders.fsmods.net/axemart/FreeSpace/screen0044.jpg)

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
PromptBoxOpt1
PromptBoxOpt2
PromptBoxOpt3 - Use these to let the player choose a response
PromptBoxOpt4
PromptBoxOpt5

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: http://lazymodders.fsmods.net/files/promptBox_V103.rar
Hidden Text: Show
Title: Re: Prompt Box: An easy way to get a user response
Post by: General Battuta on February 15, 2013, 10:33:35 pm
sweet
Title: Re: Prompt Box: An easy way to get a user response
Post by: MatthTheGeek on February 16, 2013, 05:49:16 am
Now that's something plenty of modders will use, that's for sure.

inb4Freespace: the RPG
Title: Re: Prompt Box: An easy way to get a user response
Post by: Spoon on February 16, 2013, 05:36:30 pm
sweet
Title: Re: Prompt Box: An easy way to get a user response
Post by: Shivan Hunter on February 16, 2013, 06:09:06 pm
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...
(http://i.imgur.com/qLMtF.gif)
Title: Re: Prompt Box: An easy way to get a user response
Post by: JCDNWarrior on February 16, 2013, 07:55:33 pm
Wow. This is incredible stuff. I... I still need to process all of this in. This kind of thing is precisely the type of thing I've been wanting to have for, years - and now it's here I think I need to completely rework a bunch of things I've already done for my mod. Thanks for the excellent work and release, Axem! (and anyone else who helped him, in case)
Title: Re: Prompt Box: An easy way to get a user response
Post by: BritishShivans on February 17, 2013, 12:43:32 am
I wanted something like this. Training message stuff is cool and ****, but it's horrible for remapped keyboard stuff and etc. A mouse ignores all this stuff.

Thanks, Axem. You're awesome, and you should keep being awesome. Asides from JAD and other stuff, this is probably why I think of you as a FRED idol alongside Battuta. Now if only I'd get off my ass and keep practicing doing FRED stuff...  :nervous:
Title: Re: Prompt Box: An easy way to get a user response
Post by: Axem on February 17, 2013, 05:05:21 pm
Download link has been updated with a bug fixed. proBoxLock() would give off an error about not being a number when it was. I had added some error checking at the last minute and copy pasted some code and didn't change the variable it was supposed to be looking at. All fixed now!
Title: Re: Prompt Box: An easy way to get a user response
Post by: X3N0-Life-Form on February 19, 2013, 04:46:24 am
*grabs*
inb4Freespace: the RPG
Who's up for a Freespace: Torment campaign? :P
Also:
sweet
Title: Re: Prompt Box: An easy way to get a user response
Post by: fightermedic on March 20, 2013, 04:31:18 pm
Who's up for a Freespace: Torment campaign? :P
what can change the nature of a spaceship?
Title: Re: Prompt Box: An easy way to get a user response
Post by: An4ximandros on March 20, 2013, 04:36:48 pm
 I have seen Subspace move entire civilizations. I have seen Subspace forge empires that stretched as far as the universe has stars. And I have seen Subspace give life to beings who see themselves as more than a mere part of it.
Title: Re: Prompt Box: An easy way to get a user response
Post by: Mobius on March 20, 2013, 04:38:46 pm
This is amazing, earlier today I was thinking about a similar feature relying on image subtitles rather than actual HUD gauges (which are way handier, IMO). :D My source of inspiration was FFXIII-2. Don't shoot me, please. :blah:
Title: Re: Prompt Box: An easy way to get a user response
Post by: 666maslo666 on May 19, 2013, 03:20:10 pm
Is Prompt Box compatible with Cockpit Mod? When I use both the cockpit mod and prompt box, prompt box menu is invisible.

http://www.hard-light.net/forums/index.php?topic=84459
Title: Re: Prompt Box: An easy way to get a user response
Post by: Axem on May 19, 2013, 06:02:45 pm
That's pretty odd... I can't see why it would do that...
Title: Re: Prompt Box: An easy way to get a user response
Post by: Shivan Hunter on January 16, 2014, 09:59:05 pm
(http://i.imgur.com/rlrgDQy.jpg)

So, I'm getting a side effect here. After displaying the prompt box and getting a response, I (the player) can no longer set time compression in the mission. I cracked open the script and it seems like this happens because you're calling (set-time-compression 100) to reset it instead of (reset-time-compression), which unlocks the controls in addition to setting compression to 1x. I changed it and it works, but will there be any bugs if I'm using (reset-time-compression)?

Awesome script btw
Title: Re: Prompt Box: An easy way to get a user response
Post by: Axem on January 16, 2014, 10:19:06 pm
Nah, that should be fine.


(And thanks!)
Title: Re: Prompt Box: An easy way to get a user response
Post by: Boomer20 on February 12, 2014, 01:56:30 am
Question: What folder do I put the probox/line.eff files and what folder do I put the .png files? Completely clueless on where to put them.  :banghead:
Title: Re: Prompt Box: An easy way to get a user response
Post by: niffiwan on February 12, 2014, 02:08:59 am
I think they should all go in data/hud.
Title: Re: Prompt Box: An easy way to get a user response
Post by: Boomer20 on February 12, 2014, 02:26:03 am
Well I did some trial and error (why i didn't do that before I posted is beyond me.)
I put them in interface and its working fine with no problems and then I did the same with hud and no problems.
Does that mean it doesn't really matter?
If thats the case, apologies for necro-ing when I really should of just trial and errored.
Title: Re: Prompt Box: An easy way to get a user response
Post by: niffiwan on February 12, 2014, 03:32:57 am
If it works in both then it really doesn't matter :)
Title: Re: Prompt Box: An easy way to get a user response
Post by: Boomer20 on February 12, 2014, 04:30:07 am
So I've creating a simple mission based on Axem's checkpoint tutorial and the missions supplied with the shipsave and promptbox files. However upon starting my mission I get this error:

LUA ERROR: [string "promptBox-sct.tbm - On Game Init"]:80: attempt to index field 'Player' (a nil value)

------------------------------------------------------------------
ADE Debug:
------------------------------------------------------------------
Name:      (null)
Name of:   (null)
Function type:   (null)
Defined on:   0
Upvalues:   0

Source:      (null)
Short source:   
Current line:   0
- Function line:   0
------------------------------------------------------------------


------------------------------------------------------------------

stack traceback:
   [C]: ?
   [string "promptBox-sct.tbm - On Game Init"]:80: in function 'SetMsgGaugeVisible'
   [string "promptBox-sct.tbm - On Game Init"]:226: in function 'proBoxOff'
   [string "proBoxOff()"]:1: in main chunk
------------------------------------------------------------------

------------------------------------------------------------------

Normally I've been able to work these things out by myself but LUA stuff is rather foreign to me.
And Variables are very new to me so it might be something very obvious to the more experienced.

Edit: The prompt box works fine, it just comes up with this error upon start.
Title: Re: Prompt Box: An easy way to get a user response
Post by: Axem on February 12, 2014, 07:13:17 am
That's an annoying little bug that occurs when you try to turn the ProBox on exactly on mission start. Just tie the ProBox activation to a 1ms delay from mission start.

The reason why is that I try to lock the players weapons so they can click without firing but the player hook variable might not actually be ready on that first frame. I do plan to fix that issue in a v2 release.
Title: Re: Prompt Box: An easy way to get a user response
Post by: Boomer20 on February 12, 2014, 03:31:27 pm
I'm a little puzzled as why its occurring given I've set the prompt box to trigger when time-elapsed 1 second.
I've noticed playing my mission through that it only occurs when I start my mission and theres no save file for the checkpoint to trigger.
Once I've played through it and restarted it works fine until I go through the entire mission and reach the trigger that deletes the savefile. Then it goes back to giving the error.

EDIT: I've solved the problem, seems it was my Go to the start of the mission event. One of the triggers being the saveexist variable was set to zero when it was suppose to be 1. Granted it shouldn't have caused any problems anyway as no of the other event triggers were true but that seemed to be what the mission was tripping on.

EDIT2: That might have solved the when there's no savefile but when there is a savefile it trips up again. So I haven't fixed it. Given that it occurs straight away it seems as though it wants to activate the event the moment I start the mission even though it hasn't meet all the criteria. Any thoughts on whats wrong?
Title: Re: Prompt Box: An easy way to get a user response
Post by: Axem on February 12, 2014, 05:13:46 pm
The issue is also that proBoxOff() is probably getting called too early as well. That function, like proBoxOn(), needs the player hook variable to be active.

You can see how I set it up here.
(http://www.hard-light.net/wiki/images/thumb/Deaddrop13.png/600px-Deaddrop13.png)

So if there is no save that exists (which can occur before everything else is ready) AND a 1ms has elapsed (when we're all settled in), we can continue on our way.

Hope this helps!
Title: Re: Prompt Box: An easy way to get a user response
Post by: Boomer20 on February 12, 2014, 05:27:56 pm
Turns out when making it I missed the event-true after saveexist.  :banghead:
After that I got another problem of the promptbox not closing and breaking the mission but I worked that one out as well and it all works fine now.  :D
I like the prompt box and nice tutorial, a bit overwhelming when you first look at it, but after a few read throughs I managed to understand it, helped to learn about variables first though (which made it so much easier).
Thanks for the Help!
Title: Re: Prompt Box: An easy way to get a user response
Post by: Boomer20 on January 29, 2015, 12:26:45 am
Apologies for the double post/ Necro but I've stumbled on a major bug in a mission that involves the prompt box.

So in my mission I use the prompt box 3 times. Once as a checkpoint option and twice as a method of branching the mission out. In all instances there are two options you can make. Heres where the issue is..........

If you choose Option 2 in all instances it will work fine no problems BUT if you choose Option 1 in all instances they all do the exact same thing. Which is rather annoying when you are at the checkpoint and you want to start the mission from the beginning and then instead it boots the mission into a stage that wasn't wanted.

Any suggestions and are the anyways I can trace this issue myself to track where it is going wrong. Like I said it only occurs on the first Options, not the second.
Title: Re: Prompt Box: An easy way to get a user response
Post by: Axem on January 29, 2015, 07:13:56 am
Are you using variables to keep track of what prompt you are giving the player? I usually have a variable that I set when I give a prompt and then for the resulting action its "when proBoxValue = X and question = Y."

Without seeing the mission I can't really say what the problem is for sure, but it sort of sounds like that is what's happening.
Title: Re: Prompt Box: An easy way to get a user response
Post by: Boomer20 on January 29, 2015, 03:16:52 pm
I am using variables and proBoxValue = X etc

Would it be easier for me to put the mission up and you have a look at all?
Title: Re: Prompt Box: An easy way to get a user response
Post by: Axem on January 29, 2015, 03:26:06 pm
Yes, please. :) Or if you're worried about spoiling it, you can PM me a pastebin link!
Title: Re: Prompt Box: An easy way to get a user response
Post by: Boomer20 on January 29, 2015, 03:37:22 pm
Just PM'd you
Title: Re: Prompt Box: An easy way to get a user response
Post by: m!m on November 15, 2015, 08:01:06 am
While debugging the cursor behavior in antipodes I noticed that this script never calls io.setCursorHidden(true) after closing the prompt box. You might want to fix that :P
Title: Re: Prompt Box: An easy way to get a user response
Post by: Axem on November 15, 2015, 09:22:52 am
Actually because of the seemingly obtuse way that function worked (at least before), the variable it seemed to set would reset itself to true after the frame was done anyway. That's why io.setCursorHidden(false) had to be called every frame...

Is that going to change now?
Title: Re: Prompt Box: An easy way to get a user response
Post by: m!m on November 15, 2015, 09:45:15 am
We discussed this on IRC but I'll add it here for completeness.

Previously the state was reset every frame because :v: probably didn't bother putting the right calls at the various places in the code so it was handled in one place which set the mouse to be hidden when we are currently in the game play state. The approach of this script worked because the mouse was always drawn at the end of the frame so it didn't matter that the state switched from shown to hidden and back. Now that the OS is drawing the cursor (at least in antipodes) this leads to some complications because the point at which the cursor is drawn isn't determined by FSO anymore.

The solution for this particular problem is to just add a io.setCursorHidden(true) call when the PromptBox is closed. That will still be compatible with current builds and will also work with future antipodes builds.
Title: Re: Prompt Box: An easy way to get a user response
Post by: Axem on February 03, 2018, 09:03:56 pm
I just made a large update to the Prompt Box. It now uses the same style used in JAD2.2 and WoD (using images instead of hud gauges) and as well, has the addition of SCRIPTED SEXPS. If you've used the prompt box in your campaign before, you'll know how much work it was to set up. Turn on all these hud gauges, set how many responses to do etc etc etc.

But now it's all just ONE SCRIPTED SEXP. JUST ONE. A MAZ ING.

You don't even need to keep track of questions through sexp variables, you just define a reference when calling it, and check to that same reference later!

(https://i.imgur.com/pu8RHVa.png)

(Note: nightly after Jan 19 2018 is needed!)

See original post for deets.