What is your name?

wdele
22 May 2013, 15:18Hello,
I would like to know how to create a function 'what is your name?' to be able to return the name of the user with a message like ''Nice to meet you, [name]". Does anybody know how to do this?
I know it has something to do with get input and things like that, but I have no idea how to create such a function like this. Could anybody post the code of this so I can split it out later and see how it works, and of course integrate in my (our) game?
Thank you in advance,
William
I would like to know how to create a function 'what is your name?' to be able to return the name of the user with a message like ''Nice to meet you, [name]". Does anybody know how to do this?
I know it has something to do with get input and things like that, but I have no idea how to create such a function like this. Could anybody post the code of this so I can split it out later and see how it works, and of course integrate in my (our) game?
Thank you in advance,
William
Liam315
22 May 2013, 15:55It's fairly straightforward, but it depends if you want to store the name for later use as well. To print the message by itself without storing it your script needs to:
1. Print a message saying What is your name?
2. Get Input then:
Print an expression saying "Nice to meet you, " + result + "."
Which in code looks like this:
As you can see, for get input scripts you can refer to whatever the player typed in with the expression [result]
If you want to store that name for later use, you'll need to somewhere to store it and that can depend on the nature of your game. The best place (so long as you don't change the character you are playing during the game) would probably be in Player.alias. In this case you need to use the script called set objects attribute (named by an expression). The object is the player, the attribute alias, and result would be what you are setting it to. Your code would then look like this.
You'll notice I changed the script slightly for the second one, this is just to demonstrate how you would be referring to the stored name for the rest of your script, i.e. game.pov.alias.
Hope this helps.
1. Print a message saying What is your name?
2. Get Input then:
Print an expression saying "Nice to meet you, " + result + "."
Which in code looks like this:
msg ("What is your name?")
get input {
msg ("Nice to meet you, " + result + ".")
}
As you can see, for get input scripts you can refer to whatever the player typed in with the expression [result]
If you want to store that name for later use, you'll need to somewhere to store it and that can depend on the nature of your game. The best place (so long as you don't change the character you are playing during the game) would probably be in Player.alias. In this case you need to use the script called set objects attribute (named by an expression). The object is the player, the attribute alias, and result would be what you are setting it to. Your code would then look like this.
msg ("What is your name?")
get input {
set (game.pov, "alias", result)
msg ("Nice to meet you, " + game.pov.alias + ".")
}
You'll notice I changed the script slightly for the second one, this is just to demonstrate how you would be referring to the stored name for the rest of your script, i.e. game.pov.alias.
Hope this helps.

wdele
22 May 2013, 16:12Thanks! This worked out great! And now I would like to know whether the player is a man or a woman... So the player object can change to man or woman.
Liam315
22 May 2013, 17:02Battery is about to die on my laptop so this will have to be brief. Because you will want to limit the options, using a menu is a better way to go for this. The code populates a list with your options first, then runs the menu displaying the newly created list.
That isn't the only way to do it though. Depending on how these choices will affect your code you may find it easier to set them as a boolean attribute (e.g. the attribute is male, which can be true or false).
choosegender = NewStringList()
list add (choosegender, "Male")
list add (choosegender, "Female")
ShowMenu ("What is your gender?", choosegender, false) {
if (result = "Male") {
set (game.pov, "gender", "Male")
}
else {
set (game.pov, "gender", "Female")
}
msg ("> " + result)
}
That isn't the only way to do it though. Depending on how these choices will affect your code you may find it easier to set them as a boolean attribute (e.g. the attribute is male, which can be true or false).

wdele
22 May 2013, 18:16Thanks!
Sora574
23 May 2013, 00:38@Liam: I'm sorry, this just bothered me
... using the 'set' command isn't necessary in most cases, especially when the attribute name is known (like now). It's much simpler to use something like [game.pov.attribute = "something"] than it is to use [set (game.pov, "attribute", "something")]

HegemonKhan
23 May 2013, 01:27What has been asked thus far (input name and input gender), falls under "character creation", which we've already got here:
http://quest5.net/wiki/Character_Creation
if you need help with understanding the coding~scripting or whatever (such as explaining and~or showing it via the GUI-Editor instead), just ask for help, and we'll continue to help you further.
---------------------------------
for using a game player~user 's input, you need this:
to create and store~save it (we have to attach it to some permanent object to do this):
then to use it wherever you want, you need this:
object_attribute_name.object_attribute_whatever
so for example:
--------------------------------------
for creating a set of choices to choose from, there's a few ways to do this:
***
show menu:
(see above posts for the longer process of manually creating the list first and then "calling upon" the list, that you've created, in the "show menu" function)
or
you can use the "split" function command, it automatically creates the list with only one simple line instead (much nicer, hehe)
split ("choice_one; choice_two; choice_etc" , ";")
in full:
****
another way is to create your own type of list-menu (such as for example, if you don't like the window that comes up with the "show menu" or for whatever other reasons for doing it this way too, as shown below):
or you can use lists or dictionaries in the same way, but these are a bit more difficult to learn how to use.
The "switch" function command is pretty simple (hopefully) to understand it. The "switch" is just a more tidy~organized and faster way of doing (instead of having~doing) many individual "if" scripts.
------------------
how the "get input" (and all the code "definers" too) work:
Algebraic Substitution (though you've got to think about it in the correct way, as it's a bit tricky to grasp correctly)
here's a conceptual model of how it works:
HK<=>result<=>game.pov.alias
input == output
HK => result => game.pov.alias == game.pov.alias => result => HK
(this is mostly the same structure as how computers "talk" to one another, except that it goes both ways, unlike the above, which is only going from left="input" to right="output")
( the 7 layered OSI model: http://www.petri.co.il/images/osi_model.JPG )
[ (game player~user 's) input: "HK" -> result -> game.pov.alias ] -> [ game.pov.alias -> result -> HK : (game engine's) output ]
(game player~user 's) input: "HK" -> result -> game.pov.alias
(game engine's) output: game.pov.alias -> result -> HK
http://quest5.net/wiki/Character_Creation
if you need help with understanding the coding~scripting or whatever (such as explaining and~or showing it via the GUI-Editor instead), just ask for help, and we'll continue to help you further.
---------------------------------
for using a game player~user 's input, you need this:
to create and store~save it (we have to attach it to some permanent object to do this):
get input {
object_attribute_name.object_attribute_whatever=result
}
then to use it wherever you want, you need this:
object_attribute_name.object_attribute_whatever
so for example:
<game name="HK Game Testing">
// (blah blah blah other code lines)
<start type="script">
character_creation_function
</start>
// (blah blah blah other code lines)
</game>
<function name="character_creation_function">
msg ("What is your name?")
get input {
player.alias // (or you can do: game.pov.alias) (game.pov = your currently controlled Player Object) (your default player object is "player", but you can create more player objects too and switch~change control between them)
}
</function>
<object name="friend_1">
<alias>John</alias>
<displayverbs="simplestringlist">chat</displayverbs>
<chat type="script">
msg ("You say hello, and " + this.alias + " returns the greeting, \"Hello " + game.pov.alias + "!\")
</chat>
</object>
--------------------------------------
for creating a set of choices to choose from, there's a few ways to do this:
***
show menu:
(see above posts for the longer process of manually creating the list first and then "calling upon" the list, that you've created, in the "show menu" function)
or
you can use the "split" function command, it automatically creates the list with only one simple line instead (much nicer, hehe)
split ("choice_one; choice_two; choice_etc" , ";")
in full:
show menu ("your_question", split ("choice_one; choice_two; choice_3; etc_etc_etc" , ";"), true_or_false__for_whether_you_want_to_be_able_to_cancel_your_choice_aka_go_back) {
(etc etc etc script)
}
****
another way is to create your own type of list-menu (such as for example, if you don't like the window that comes up with the "show menu" or for whatever other reasons for doing it this way too, as shown below):
msg ("Type the number of the choice you want")
msg ("(1) choice_one, (2) choice_two, (3) choice_three, ... etc etc etc")
get input {
switch (result) {
case ("1)" {
msg ("choice_one_response") // you can do whatever script you want, I'm only using the "msg" script for an example
}
case ("2") {
msg ("choice_two_response") // you can do whatever script you want, I'm only using the "msg" script for an example
}
case ("3") {
msg ("choice_three_response") // you can do whatever script you want, I'm only using the "msg" script for an example
}
}
}
or you can use lists or dictionaries in the same way, but these are a bit more difficult to learn how to use.
The "switch" function command is pretty simple (hopefully) to understand it. The "switch" is just a more tidy~organized and faster way of doing (instead of having~doing) many individual "if" scripts.
------------------
how the "get input" (and all the code "definers" too) work:
Algebraic Substitution (though you've got to think about it in the correct way, as it's a bit tricky to grasp correctly)
here's a conceptual model of how it works:
HK<=>result<=>game.pov.alias
input == output
HK => result => game.pov.alias == game.pov.alias => result => HK
(this is mostly the same structure as how computers "talk" to one another, except that it goes both ways, unlike the above, which is only going from left="input" to right="output")
( the 7 layered OSI model: http://www.petri.co.il/images/osi_model.JPG )
[ (game player~user 's) input: "HK" -> result -> game.pov.alias ] -> [ game.pov.alias -> result -> HK : (game engine's) output ]
(game player~user 's) input: "HK" -> result -> game.pov.alias
(game engine's) output: game.pov.alias -> result -> HK