Jumping within a function
UnclearImage86
27 Jun 2017, 04:51I played Alien: Isolation, and it made me want to make my own Alien fan game. I've been using Quest for about 3 days now, and got alot figured out. But I'm having an issue within a function I made 'usePCAirlock' (It's the computer terminal right inside the ship by the Airlock you start in)
I'm trying to set it up like Alien: Isolation, you use a computer terminal and it pops up a couple options. When you chose an option more options pop up. Generally it's emails/ story related stuff. Which I want to happen, but I can't figure out how to open (choose) a directory, then open an email/ message within it. Then let you go back (or up in the IF/THEN) one choice, and choose again.
Here's my code so far, but I'm using the GUI as much as I can.
function name="usePCAirlock"
ClearScreen
TextFX_Typewriter ("Wayland-Yutani Corporation main airlock terminal", 15)
msg ("1: Computer Logs | 2: Maintenance Controls | 3: Step away from PC")
get input {
if (result = "1") {
msg ("Computer Logs")
msg ("1: one 2: two 3: BACK")
get input {
if (result = "1") {
msg ("one")
wait {
}
}
else if (result = "2") {
msg ("two")
wait {
}
}
else if (result = "3") {
usePCAirlock
}
}
}
else if (result = "2") {
}
else if (resuilt = "3") {
}
}
/function
Short of making more functions for each option (which seems really dumb) I don't know how to label and goto within a script/ function/ or IFTHEN

DarkLizerd
27 Jun 2017, 05:25Maybe, just guessing here and maybe some could explain this better....
Build a "PC command tree"
(main menu: player hits "1")
PC.command="1"
call function PC(result) result=1
msg ("1: Computer Logs | 2: Maintenance Controls | 3: Step away from PC")
(player hits "1")
PC.command="11"
call function PC("11)
msg("Computer: Logs")
(player hits "3")
PC.command="1"
The function PC uses the (11) to find what to display:
Switch ("11") ... Use the variable that is passed
(Don't recall the switch structure right now, but...)
=1 then msg ("1: Computer Logs | 2: Maintenance Controls | 3: Step away from PC")
=2 then msg (" Maintenance Controls: Menu....... ")
=3 then msg(" You are done with the terminal.")
=11 then msg("Computer logs: One")
=12 then msg("Computer Logs: Two")
=21 then msg("Maintenance: Item One")
=22 then msg("Maintenance: Item Two")
and so on...
hegemonkhan
27 Jun 2017, 05:39unfortunately, I think (Pixie or other good programmers will probably correct me) there's only two/three ways to do it:
-
each layer is its own Function/Script_Attribute(+Delegate optionally), letting you 'call/do/invoke/rundelegate/RunDelegateFunction' back-to/goto the desired layer, which you already thought-of/realized to do
-
use recursive Function/Script_Attribute(+Delegate optionally)
-
also maybe you can use the 'while' Function too...
to 'call' (do/activate/re-do/re-activate/call/re-call/use/re-use) a Function, is very easy in code:
NAME_OF_FUNCTION // if no Parameters
NAME_OF_FUNCTION (ARGUMENT/S) // if got Parameters
VARIABLE = NAME_OF_FUNCTION // if got a return type (The Function returns a value)
in the GUI/Editor:
add new script -> 'scripts' section/category -> 'call a function' Script -> Name box: NAME_OF_FUNCTION, (if got Parameters) add parameters/arguments box -> set up the arguments (inputs)
'do/re-do/invoke/re-invoke/use/re-use/activate/re-active/call/re-call' Script Attributes, in code:
invoke (NAME_OF_OBJECT.NAME_OF_SCRIPT_ATTRIBUTE)
invoke (NAME_OF_OBJECT.NAME_OF_SCRIPT_ATTRIBUTE, NAME_OF_OBJECT.NAME_OF_DICTIONARY_ATTRIBUTE) // the Dictionary Attribute's 'keys' and 'values' will be used as Parameters (Variables) and Arguments (inputs/values)
// 'do' is more powerful/useful than 'invoke' as you can concatenate with it, unlike 'invoke'
do (NAME_OF_OBJECT, "NAME_OF_SCRIPT_ATTRIBUTE")
do (NAME_OF_OBJECT, "NAME_OF_SCRIPT_ATTRIBUTE", "NAME_OF_OBJECT.NAME_OF_DICTIONARY_ATTRIBUTE") // the Dictionary Attribute's 'keys' and 'values' will be used as Parameters (Variables) and Arguments (inputs/values)
Script Attributes + Delegates:
Delegates enable your Script Attributes to have/use Parameters and/or a return type (enables them to act like Functions).
http://docs.textadventures.co.uk/quest/types/using_delegates.html
http://docs.textadventures.co.uk/quest/elements/delegate.html
http://docs.textadventures.co.uk/quest//functions/rundelegatefunction.html
http://docs.textadventures.co.uk/quest//scripts/rundelegate.html
http://docs.textadventures.co.uk/quest/functions/hasdelegateimplementation.html
let me know if you need help with any of these things
UnclearImage86
27 Jun 2017, 06:10So am I re-using the UsePC function and passing "1" as the parameter to have it automatically jump to the function as if the played chose '1'??
so
UsePCAirlock("1")
?
How do I pass an input as a parameter, or modify the function to recognize that order.
EDIT: I appreciate you linking all that, I'm trying to read it. I think I need to pass an argument to the call function but I can only add parameters.
hegemonkhan
27 Jun 2017, 10:42this might be of some help for you:
http://textadventures.co.uk/forum/samples/topic/4988/character-creation-crude-code-and-sample-game
in the GUI/Editor:
when you do the 'call function' Script:
add new script -> 'scripts' section/category -> 'call function' Script -> (see below)
Name text box: NAME_OF_FUNCTIOn // this is the Function you're going to activate/run/execute (as first time or a subsequent time)
Add (Parameter/Argument: regardless of what it says here) big box: these are your inputs/values (your Arguments, as this is a 'function call', the USE of the Function, and not creating/defining the Function, which would involve adding/naming the Parameters and/or specifying the return type, if you want/need them)
here's an example for you:
(used some creativity, probably not the best design, but it works... except it'll probably require you to still type in inputs... for the 'get input' Functions... grr... almost works... well, I can re-design it so tht it does work... it'll be a bit more messy... though, meh)
<game name="example_game">
<attr name="start" type="script">
usePCAirlock ("0", "0")
</attr>
</game>
// how Parameters (local Variables used by the Function's scripting) and Arguments (inputs/values that are stored into the Function's Parameters) work:
// usePCAirlock ("ARGUMENT_POSITION_1", "ARGUMENT_POSITION_2")
// <function name="usePCAirlock" parameters="PARAMETER_POSITION_1,PARAMETER_POSITION_1">
// PARAMETER_POSITION_1: string_parameter_1 // for this example of mine
// PARAMETER_POSITION_2: string_parameter_2 // for this example of mine
// the Arguments (inputs/values) are matched up to their position matching Parameters (Variables)
// so, effectively, this is what is going on:
// PARAMETER_POSITION_1: string_parameter_1 <=== ARGUMENT_POSITION_1: YOUR_STRING_INPUT/VALUE_1
// PARAMETER_POSITION_2: string_parameter_2 <=== ARGUMENT_POSITION_2: YOUR_STRING_INPUT/VALUE_2
<function name="usePCAirlock" parameters="string_parameter_1,string_parameter_2">
ClearScreen
TextFX_Typewriter ("Wayland-Yutani Corporation main airlock terminal", 15)
msg ("1: Computer Logs | 2: Maintenance Controls | 3: Step away from PC")
get input {
ClearScreen
if (string_parameter_1 = "1" or result = "1") {
msg ("Computer Logs")
msg ("1: one 2: two 3: BACK")
get input {
ClearScreen
if (string_parameter_2 = "1" or result = "1") {
msg ("one")
wait {
}
} else if (string_parameter_2 = "2" or result = "2") {
msg ("two")
wait {
}
} else if (result = "3") {
usePCAirlock ("1", "0")
}
}
} else if (string_parameter_1 = "2" or result = "2") {
msg ("Maintenance Controls")
msg ("1: one 2: two 3: BACK")
get input {
ClearScreen
if (string_parameter_2 = "1" or result = "1") {
msg ("one")
wait {
}
} else if (string_parameter_2 = "2" or result = "2") {
msg ("two")
wait {
}
} else if (result = "3") {
usePCAirlock ("2", "0")
}
}
} else if (result = "3") {
msg ("You turn off the computer and step away from it")
}
}
</function>
JenniferKline
27 Jun 2017, 14:53Not sure if I got the gist, but wouldn't this be best for a Print Menu option? Seems its messages with trying to get various inputs, but there is a built in function for menus. I don't use it much.
Edit: Ah, actually, nevermind. I get it now.
UnclearImage86
27 Jun 2017, 17:31I appreciate all the answers, it's a lot of information I can learn and study. While what you suggested may be the most efficient way of doing it I decided to jump functions.
I have two functions
(usePCAirlock is now Airlock_PC because I can't make folders and I want my assets to be organized.)
Airlock_PC shows the
IF/THEN
1: Communication logs (call function Airlock_PC1)
2 Maintenance Controls (currently does nothing, will unlock a door)
3: Step away from computer (clear screen ; ShowRoomDecription)
Other / Wrong inputs : "::ERROR::" return to Airlock_PC
Airlock_PC1 shows
IF/THEN
1: Statement from management about new Security Protocols
2: Message from this terminal to maintenance about lights and people freaking out
Other / Wrong inputs : "::ERROR::" return to Airlock_PC1
While this may not be the most efficient way of handling this, it's what I got to work. Stacking all my scripts in a function, then calling that function. I used the GUI as much as possible, again this is my first week with Quest :D.
So thank you everyone for your help, and especially Hegemonkhan.
EDIT: Oh yeah, after you open one of the communications you can read it and after a keypress you return to Airlock_PC1 which is why I needed the functions in the first place. So you don't start at the main menu, but instead can read one communication, and then immediately access another.

TinFoilMkIV
28 Jun 2017, 03:24What I would personally do, is make an actual object for the terminal (if you didn't already) and have each menu/screen a script attribute of the terminal itself. An attribute can be a script on it's own. So you have an attribute for each "screen" the player can wind up in, then you simply call the scripts as they're needed.
ie: "main menu" - shows options and such, like e-mails
"e-mails" - list e-mails player can open. when an e-mail is closed, call this same script, resulting in sending the player back to the e-mail menu when they close the mail they're reading.
When the player is done, just do nothing, the whole thing ends and they go back to normal game stuff.
When you want to send them back to the previous menu, simply call the function for the previous menu.
While this can result in a lot of functions, it keeps them relatively organized, as they're kept within the object itself. As a bonus you can use standardized terms, such as "main menu" and since it's specific to the object you won't end up pulling a menu for a different terminal.
hegemonkhan
28 Jun 2017, 04:24the only problem with that is they can still do menus/looping within the Script Attributes (no different if you were using Functions), which still leaves the fundamental design problem, though encapsulating it to an Object (+Script Attributes+Delegates: if you need to pass inputs/arguments/parameters to the Script Attribute and/or have them return a value, specifying the return type), is most definately better design, especially for the us humans and our sanity/organization. Maybe though there's less overhead between an Objects' Script Attributes and/vs Functions.
I think for new people, that Functions are a easier to understand, than using Objects and Script Attributes (and Delegates), as Functions are more standalone, and it's hard for people to wrap their brain around more abstract OOP/OOD/encapsulation and interconnectedness of designing.
The Pixie
28 Jun 2017, 07:41The way I would do it is have each menu screen as a room (make sure the player cannot get to to these rooms). The menu for a room would be a list of exits, which takes you to the next screen/room, with its own list of exits.
https://github.com/ThePix/quest/wiki/Modelling-a-computer-system
Also, I would strongly advise using ShowMenu
, rather than GetInput
.
http://docs.textadventures.co.uk/quest/functions/showmenu.html

DarkLizerd
28 Jun 2017, 08:50I like that idea!!!
Just like the player moves room to room...
You would do the same in the terminal...
hegemonkhan
28 Jun 2017, 13:44never thought of using room/exit movement instead of scripting (Functions/Script Attributes) ... could make these things easier to do
very creative/ingenius Pixie!