Question: Filling in a Character's Name

Gooseberry
11 Apr 2020, 21:03What is the {} code for letting the player enter in a name for the character? I looked at text formatting, but I may have looked straight past it because it wasn't made clear to my simple mind lol.
I know about {player.alias} but that's only used after you put in the text fill, right?
Deckrect
11 Apr 2020, 21:37Well, for what you want, you will need this tutorial here:
https://docs.textadventures.co.uk/quest/asking_a_question.html
I have found it's presentation is a little ugly. You need using the command bar and make sure the player notices it is a pause for typing whatever the input you are asking for. In the case of something permanent as character name, perhaps you may fins useful adding a confirmation.
But in general terms, if naming a character is all you want for now, just copy and paste the first code you see in the link above and it will work perfectly.
mrangel
11 Apr 2020, 23:03I was going to say there isn't a text processor code for allowing the player to input something; but it might be a useful feature to add. I'll take a look in the morning, if I have more time to think about it. I think it would be nice (particularly for gamebooks) if you could have a "fill in the blank" type text box placed inline in the text, which would set a variable when it was completed.
Deckrect
11 Apr 2020, 23:04Actually, it would be great because is ecxactly what I need right now.
mrangel
12 Apr 2020, 16:04Actually, it would be great because is ecxactly what I need right now.
Off the top of my head… I'll probably need to do some debugging on this later.
To display a "fill in the blank" kind of space to put an input field in the text, we'll need a bit of javascript. In this case, a script that will run after addText
, to bind events to new text as it appears.
$(function () {
var originalAddText = addText;
addText = function (text) {
var latest = getCurrentDiv().children().last();
addText(text);
latest.nextAll().find('.inlineinput').each(function () {
var $this = $(this);
var changed = 0;
$this.change(
e => changed = $this.text().length > 0
).keydown(function (ev) {
if (ev.which === 13) {
changed = $this.text().length > 0;
ev.stopPropagation(); ev.preventDefault();
$this.blur();
}
}).blur(function (e) {
if (changed) {
ASLEvent('InlineValueEdit', $this.data('questattribute')+"="+$this.attr('contenteditable', 'false').text());
changed = 0;
}
}).attr('contenteditable', 'true');
});
};
});
Then a function to actually generate the HTML. For the text processor, we'd want to add an element to the scriptdictionary game.textprocessorcommands
:
<item key="inline:">
params = Tsplit (section + ":")
attr = ListItem (params, 1)
if (ListCount (params) > 2) {
default = ProcessTextSection (ListItem (params, 2), data)
}
else {
default = "";
}
game.textprocessorcommandresult = "<span class=\"inlineinput\" data-questattribute=\"" + attr + "\">" + default + "</span>"
</item>
And then a function to handle the entered value:
<function name="InlineValueEdit" parameters="params">
equal = Instr (params, "=")
if (not equal > 3) {
error ("Invalid object name in InlineValueEdit!")
}
attr = Left (params, equal-1)
value = Mid (params, equal + 1)
if (Instr (attr, ".") = 0) {
attr = "game." + attr
}
target = null
attr = Split (attr, ".")
for (i, 0, ListCount (attr)-2) {
segment = ListItem (attr, i)
if (target = null) {
target = GetObject (segment)
}
else {
target = GetAttribute (target, segment)
}
if (target = null) {
result = "Couldn't find object "
for (j, 0, i) {
result = result + ListItem (attr, j) + "."
}
error (Left (result, LengthOf(result) - 1) + " in InlineValueEdit.")
}
}
set (target, ListItem (attr, ListCount (attr)-1), value)
</function>
That's a bit horrible; but it basically takes a string like game.pov.alias=George
(handed to it by the javascript above) and breaks it down into parts.
I put it into a loop so you could use game.pov.alias
and have it work correctly. But really, this could probably be done with a simpler piece of code.
And I really need to get on with some actual work now… I've got a free book promotion and a charity promotion to organise, I'm supposed to be writing a novel, and I'm supposed to be doing a daily video series about how I'm writing a novel… and I've not done any of it today.
I'll come back to this later and try to make sure it works.
If it does work (which is possible), you could just include “Hello, my name is {inline:player.alias}, how can I help you”
in the output text; the player can click in the text box and press enter, and it will change their alias.
hegemonkhan
12 Apr 2020, 16:14set the desired 'PageX' Object's 'page type' Attribute to: [script] or [script + text]
add new script -> 'output' section/category (I think) -> 'print a message' Script -> (see below)
print [MESSAGE] TYPE_IN_WHAT_YOU_WANT_DISPLAYED_HERE
// or (if you want/need to use VARIABLES, and not just TEXT:
print [EXPRESSION] COMPLEX_EXPRESSION
// (COMPLEX_EXPRESSION: SEE_ASK_HOW_TO_SCRIPT_TEXT_WITH_VARIABLES_OR_JUST_VARIABLES_WITHOUT_TEXT)
add new script -> 'scripts' section/category (I think) -> 'get input' Script
-> then -> add new script -> 'variables' section/category -> 'set a variable or attribute' Script -> (see below)
set variable player.alias = result
// (this is storing your input to the 'alias' String Attribute of your Player Object)
// you can then use it within a text processor command (example in code):
msg ("Name: {player.alias}")
or, not using the text processor commands (an example):
msg ("Name: " + player.alias)
the 'msg' Script/Function in code is achieved through the GUI/Editor via:
add new script -> 'output' section/category -> 'print a message' Script ->
// an example:
print [EXPRESSION] "Name: " + player.alias
// replace 'player' with 'game.pov' (for example: 'game.pov.alias' instead of 'player.alias') if you changed the Player Object's 'name' ID String Attribute to something else other than the default 'player' for the Player Object's 'name' ID String Attribute