Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Ultra Magnus on Tue 25/03/2008 21:31:48

Title: Text input, parsing and logging [SOLVED]
Post by: Ultra Magnus on Tue 25/03/2008 21:31:48
Hello.
After a bit of searching, I figured this issue was advanced enough to be here.
So, two questions regarding text input.

1) Is it possible to make the parser ignore everything except a few key words (placed in any order), short of adding the entire language to the ignore list?
I tried a few different things, but it usually ended up just ignoring everything and treating the text as valid regardless of whether a key word was present or not.

2) Is it possible to log input text and refer back to it later?
For example, if you ask the player to type in their name, could you then have a character refer to them by that name in dialogue later?

Thanks.
J.
Title: Re: Text input, parsing and logging
Post by: Radiant on Tue 25/03/2008 22:13:12
1) Yes, but it is easier to not use the parser, and use regular string functions.

2) Yes, by storing it in strings.
Title: Re: Text input, parsing and logging
Post by: Ultra Magnus on Tue 25/03/2008 22:19:27
Thanks for answering my questions.
I do, however, have a follow-up question...

How?

:)
Title: Re: Text input, parsing and logging
Post by: Radiant on Tue 25/03/2008 22:55:09
This'll take a bit of reading.

Open up the script editor, type in "String" and hit F1. That should take you to the help page with all the string functions.
Title: Re: Text input, parsing and logging
Post by: Pumaman on Tue 25/03/2008 23:55:37
Yes, for (1) probably the best thing is not to use the built-in parser, but just to use some String.Contains checks to see if they've typed particular words in.

As for (2), you can declare yourself a String variable, and then set it to the contents of a text box that the user has typed in.

If you need more help with doing these things, let us know and we can move this thread to the Beginners Tech Forum.
Title: Re: Text input, parsing and logging
Post by: Ultra Magnus on Thu 27/03/2008 03:52:51
Okay, I give up.

#1 was easy enough once I knew what I was looking for.
However, #2 is still giving me a headache.
The manual's sending me round in circles and no matter how many times I search the forums using numerous different ways to say the same thing, the best answers I'm getting are either 4 years old using functions that don't exist any more, or simply made up of links to the non-existent BFAQ.

So yeah, if you could shunt this thread over to the beginner's board, I would appreciate it.
And sorry for posting it in the wrong place to begin with.

Okay, so now I don't care how much I look like a complete noobish retard.
What am I doing wrong?

(http://img507.imageshack.us/img507/319/helpqw1.gif)

1) This is clearly the wrong way to do the variable-inside-a-dialogue thing, right?
How do I fix that?

2) How do I stop his reply popping up before I've even activated the text box?

Thanks for any help.
J.

(P.S. - Sorry if my tone seems a bit harsh, but I've been struggling with this relatively minor issue for the past 2 days and I'm about ready to chuck it in. Plus it seems like it should be so easy, which makes me feel like an idiot for not being able to do it.)
Title: Re: Text input, parsing and logging
Post by: Gilbert on Thu 27/03/2008 03:59:32
Can you actually post the codes you used?
Title: Re: Text input, parsing and logging
Post by: Ultra Magnus on Thu 27/03/2008 04:14:48
Sorry, I'm going snowblind. ::)

Dialog:-
@2
ZIGGY: "My name's Ziggy."
ZIGGY: "What's yours?"
run-script 10
ZIGGY: "Nice to meet you, ("%s", namestring)".
return


Global.asc...
@ the top:-
String namestring;
export namestring;


Dialog request section:-
function dialog_request (int person) {

<trimmed unrelated stuff>

  else if (person==10) {
    gNameinput.Visible = true;
  }
}


@ the bottom:-
function btnNameOK_OnClick(GUIControl *control, MouseButton button)
{
gNameinput.Visible=false;
namestring=txtNameinput.Text;
}


Global.ash:-
import String namestring;

I think that's everything related to this.
This is all after numerous attempts with different scripts, so I have no idea what's right or wrong any more.

And txtNameinput is the name of the text box in the GUI (as shown in the pic), by the way.

Thanks.

(I forgot to mention that I'm using 3.0, by the way.)
Title: Re: Text input, parsing and logging
Post by: Radiant on Thu 27/03/2008 08:48:16
Quote from: Ultra Magnus on Thu 27/03/2008 04:14:48
ZIGGY: "Nice to meet you, ("%s", namestring)".

I'm reasonably sure that this code doesn't work in dialog scripts, because it is intended to work in the global script or room script. So what you could do instead is something like this:


run-script 1


And then put in your global script,

function dialog_request (int data) {
  if (data == 1) character[ZIGGY].Say ("Nice to meet you, %s", namestring);
}

Title: Re: Text input, parsing and logging
Post by: Pumaman on Thu 27/03/2008 14:12:58
Making the GUI visible won't pause the game, so the rest of your dialog script will continue to run before the user has typed anything in.

The easiest solution is probably to remove the "Nice to meet you" line from your dialog script, and put this in your btnNameOK_OnClick function instead:

cZiggy.Say("Nice to meet you, %s", namestring);
Title: Re: Text input, parsing and logging
Post by: Ultra Magnus on Fri 28/03/2008 01:53:50
So the recommended workaround would be something like...

Room script:-
function cZiggy.Talk()
{
cZiggy.Say("Hi, my name's Ziggy");
cZiggy.Say("What's yours?");
gNameinput.Visible = true;
}


Global:-
function btnNameOK_OnClick(GUIControl *control, MouseButton button)
{
gNameinput.Visible=false;
namestring=txtNameinput.Text;
cZiggy.Say("Nice to meet you, %s.", namestring);
dZiggy1.Start();
}


...instead of jumping straight into the dialogue script, and then jumping in and out of dialogue with the character.Say function whenever I want someone to use the players name.
Have I got that right?
It seems to work well enough.

Also, is there any way of adding speech marks to a text string?
Just using cZiggy.Say(""Hi, my name's Ziggy.""); obviously gives an error.
It's purely a stylistic choice, but I just thought I'd ask.

Thanks for the help.
J.
Title: Re: Text input, parsing and logging
Post by: Pumaman on Fri 28/03/2008 18:03:44
You can add a speech mark by using a backslash before it. So:

cZiggy.Say("\"Hi, my name's Ziggy.\"");
Title: Re: Text input, parsing and logging [SOLVED]
Post by: Ultra Magnus on Sat 29/03/2008 04:01:10
Cool stuff.
Thanks a heap.
Title: Re: Text input, parsing and logging [SOLVED]
Post by: WHAM on Tue 12/01/2010 15:06:36
Sorry to bump ye-olde-thread, but I realized that there was one thing it doesn't answer: To have a character say a line with a string variable attached, we have a line of code as follows:


cEgo.Say("Hello, my name is %s.", namestring);


However, is it possible and how do I get the same character to state an Int-type variable in the same conditions.

For example, I need a character to say "I have 10 rounds of ammunition left", where the number "10" is drawn from an integer type variable. (I tried cEgo.Say("I have %i bullets.", ammocount); -but to no avail.

Thanks! (Sorry if this should've been a new thread, I just though it would be useful to have all similiar info in one thread for future reference)

-WHAM
Title: Re: Text input, parsing and logging [SOLVED]
Post by: ThreeOhFour on Tue 12/01/2010 15:10:48
Have you tried replacing the %i with a %d?
Title: Re: Text input, parsing and logging [SOLVED]
Post by: WHAM on Tue 12/01/2010 15:12:24
Quote from: Ben304 on Tue 12/01/2010 15:10:48
Have you tried replacing the %i with a %d?

Apparently not... Why is it a "%d" and not "%i"? if %s goes for "String" then why not "%i" for integer!? Who created these rules and why!? Argh!

Thanks anyway, this worked like a charm.  ;D

-W
Title: Re: Text input, parsing and logging [SOLVED]
Post by: ThreeOhFour on Tue 12/01/2010 15:17:10
Hah, no idea. But in future, you might keep the String formatting (http://www.americangirlscouts.org/agswiki/String_formatting) section of the manual in mind. :)
Title: Re: Text input, parsing and logging [SOLVED]
Post by: Khris on Tue 12/01/2010 16:31:54
I guess d is short for double, as in values up to +/- 2^31 instead of +/- 2^15.
Title: Re: Text input, parsing and logging [SOLVED]
Post by: Snarky on Tue 12/01/2010 17:36:13
I think it actually stands for decimal, and means that the number should be printed in decimal (rather than binary, octal, hexadecimal, ...) format. In oldschool C (where this convention comes from) there was no real difference between variable types: they were all just chunks of memory of various sizes. An int, for example, could be a number, a boolean, a pointer, a couple of characters, etc. So the % formatting instructions told the print function how to interpret each variable.

(This is not 100% true, since the mathematical operators depended on the variable type, especially to distinguish floating point numbers from integers, but it more or less applies to string formatting, at least.)
Title: Re: Text input, parsing and logging [SOLVED]
Post by: monkey0506 on Tue 12/01/2010 17:53:43
The d does in fact stand for decimal. The reasoning for using a d (http://en.wikipedia.org/wiki/Printf#printf_format_placeholders) (see "Type") goes back to the 1970s (http://en.wikipedia.org/wiki/Printf#1970s:_C.2C_Lisp). Some languages support both d and i but AGS likes to kick it old-skewl.

And Khris don't be silly, you can't store +2^31 in an integer. You can only store +(2^31 - 1). :P