Text input, parsing and logging [SOLVED]

Started by Ultra Magnus, Tue 25/03/2008 21:31:48

Previous topic - Next topic

Ultra Magnus

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.
I don't mean to sound bitter, cold, or cruel, but I am, so that's how it comes out.

I'm tired of pretending I'm not bitchin', a total frickin' rock star from Mars.

Radiant

1) Yes, but it is easier to not use the parser, and use regular string functions.

2) Yes, by storing it in strings.

Ultra Magnus

Thanks for answering my questions.
I do, however, have a follow-up question...

How?

:)
I don't mean to sound bitter, cold, or cruel, but I am, so that's how it comes out.

I'm tired of pretending I'm not bitchin', a total frickin' rock star from Mars.

Radiant

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.

Pumaman

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.

Ultra Magnus

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?



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.)
I don't mean to sound bitter, cold, or cruel, but I am, so that's how it comes out.

I'm tired of pretending I'm not bitchin', a total frickin' rock star from Mars.

Gilbert

Can you actually post the codes you used?

Ultra Magnus

#7
Sorry, I'm going snowblind. ::)

Dialog:-
Code: ags
@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:-
Code: ags
String namestring;
export namestring;


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

<trimmed unrelated stuff>

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


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


Global.ash:-
Code: ags
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.)
I don't mean to sound bitter, cold, or cruel, but I am, so that's how it comes out.

I'm tired of pretending I'm not bitchin', a total frickin' rock star from Mars.

Radiant

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:

Code: ags

run-script 1


And then put in your global script,
Code: ags

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


Pumaman

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);

Ultra Magnus

#10
So the recommended workaround would be something like...

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


Global:-
Code: ags
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.
I don't mean to sound bitter, cold, or cruel, but I am, so that's how it comes out.

I'm tired of pretending I'm not bitchin', a total frickin' rock star from Mars.

Pumaman

You can add a speech mark by using a backslash before it. So:

cZiggy.Say("\"Hi, my name's Ziggy.\"");

Ultra Magnus

I don't mean to sound bitter, cold, or cruel, but I am, so that's how it comes out.

I'm tired of pretending I'm not bitchin', a total frickin' rock star from Mars.

WHAM

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:

Code: ags

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
Code: ags
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
Wrongthinker and anticitizen one. Utterly untrustworthy. Pending removal to memory hole.

ThreeOhFour

Have you tried replacing the %i with a %d?

WHAM

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
Wrongthinker and anticitizen one. Utterly untrustworthy. Pending removal to memory hole.

ThreeOhFour

Hah, no idea. But in future, you might keep the String formatting section of the manual in mind. :)

Khris

I guess d is short for double, as in values up to +/- 2^31 instead of +/- 2^15.

Snarky

#18
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.)

monkey0506

The d does in fact stand for decimal. The reasoning for using a d (see "Type") goes back to the 1970s. 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

SMF spam blocked by CleanTalk