Adding player name in game.

danbrysmi
01 Nov 2014, 00:35
What would I have to put in my game so that it asks for a name, and then the name can be easily used in text.

E.g. (start of game)
What is your name?
>Dave
Hello Dave.

(later on in game)
Dave suddenly decided to refer to himself in third person.

This would change depending on what name was entered in at the start of the game.

I looked at the tutorials and script stuff and tried to do this code but it didn't work...

msg ("What is your name?")
get input {
set (player, "name", result)
msg ("Hello" + result + "!")
}

I got the first 2 lines from the get input script in the help tab, but I guessed at the last 2 lines, which I think are the problem. I tried to make the result of the question an attribute called "name" which belonged to"player".
Then I tested the response bit with the 4th line.

Any help or advice would be greatly appreciated, but I am a beginner when it comes to programming, so fancy terms might confuse me :)

If someone showed me the code I should use,I would love it!

Thank you so much for reading my many lines!

HegemonKhan
01 Nov 2014, 03:29
you almost got it...

the 'get input' command sets automatically~internally (hidden from you):

result = your_typed_in_input_during_game_play

and use 'ALIAS' Attribute, instead of 'NAME' Attribute (as 'NAME' is your ID Attribute, which already is called, 'player', as~for your Object's ID~NAME), too:

set (player, "alias", result)

msg ("Hello " + player.alias + "!")

msg ("What is your name?")
get input {
set (player, "alias", result)
msg ("Hello " + player.alias + "!")
}


or

msg ("What is your name?")
get input {
player.alias = result
msg ("Hello " + player.alias + "!")
}


the full algebraic substitution conception:

player.alias = result = HK (my typed-in input during game play)
player.alias <---> result <---> HK

result <=== HK
player.alias <=== result
thus: player.alias = HK

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

helping links:

http://docs.textadventures.co.uk/quest/
http://docs.textadventures.co.uk/quest/guides/
http://docs.textadventures.co.uk/quest/ ... ation.html (this is direct help for doing this)
http://docs.textadventures.co.uk/quest/ ... input.html
http://docs.textadventures.co.uk/quest/scripts/set.html

hopefully this is helpful for you! :D

-----------

if you just want to use your input locally (just for that script, no where else):

msg ("What is your name?")
get input {
msg ("Hello " + result + "!")
}


---------

the basic syntax is this:

Object_name.Attribute_name = Value_or_Expression
~OR~
Variable_name_string = Value_or_Expression

--

Globally (this 'saves' it, thus you can 'load' and use it anywhere, so long as the Object it is attached to, still exists):

an Attribute Variable:

Object_name.Attribute_name = Value_or_Expression

examples:

HK.strength_integer = 100
HK.damage_double = 56.2
HK.dead_boolean = false
HK.favorite_color_string = "black"
HK.favorite_color_list_stringlist = split ("black;red", ";")
HK.head_object = helmet

HK.physical_damage_integer = HK.weapon_damage_integer * HK.strength_integer / 100 - orc.armor_class_integer * orc.endurance_integer / 100

--

Locally (you can't use this in another script):

a Variable Variable:

variable_string_name = Value_or_Expression

strength_integer = 100
damage_double = 56.2
dead_boolean = false
favorite_color_string = "black"
favorite_color_list_stringlist = split ("black;red", ";")
head_object = helmet

my use of the underscores and writing the type of attribute as a part of label for my attributes~variables~objects~etc, is just my own labeling convention~pattern~system that I like using, hehe. You can label your things however you want to for how you label your attributes~variables~objects~etc

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

third person and~or etc:

http://docs.textadventures.co.uk/quest/ ... ticle.html
http://docs.textadventures.co.uk/quest/ ... ender.html

hope this helps! :)

danbrysmi
01 Nov 2014, 09:16
Thank you! You've been really helpful :D

jaynabonne
01 Nov 2014, 09:56
Just to throw in my two cents... You can easily output the player's alias at any point using the text processor syntax:

msg("Hello {player.alias}!")

msg ("{player.alias} suddenly decided to refer to himself in third person.")


Much easier than getting into string concatenation and all that. (And why make things harder for yourself than you need to? :) )

Note that you couldn't use that notation for a local variable like "result", but for object attributes, it's a snap.