A simple way to check whether or not a callroomscript has had no response?

Started by bspeers, Fri 06/03/2009 02:50:10

Previous topic - Next topic

bspeers

Hey there techies.

Maybe this is a basic question, but I'm trying to script a text parser and I'd like to have an easy way to check for generic nouns and verbs in sentences that have no written response, without writing out each individual response.

Note that this the answer isn't simply anyword" or "rol" as I'm not asking about generalizing whole words, but more of contextual check.

In simple terms, I want the player to be able to type "look house."  If there is a response in callroomscript, then I want that response to play.  If not, I want a generic response such as "There is no house here."

Right now, the only way I can see this working is by putting all my parser text in the global script with if statements such as:

Quote
Code: ags

if (cChar1.room == 1) {
Display ("Okay, you're standing in the house.");
}

else if (cChar1.room == 2) {
Display ("The house looks enormous.");
}

else {
Display ("There is no house here.");
}


However, this seems exceedingly awkward and bulky.  Surely there is a way to check whether a whole class of words have come up with a callroomscript response and then respond based on this?

What I would like to do, ultimately, in bad psedocode:

Code: ags

if (Parser.Said ("look %s", thinglooked)) {
if ((Parser.FindWordId != -1) && (calllroomscript was null)) {
Display ("There is no  '%s' here", thinglooked);
}
}


That way, every time you looked at anything in the game that was in the dictionary and didn't have an in-room response, you would get a generalized "that isn't here" type message.

Is this possible?  Is it something simple I missed?

Please treat me like a noob on this, since the last version of AGS I used had graphical scripts in it.  I'm an oldbie newbie.
I also really liked my old signature.

Trent R

Have you read the manual on callroomscript? It tells you what you need to know. Put function on_call (int value) into your room script. To check if it's been run (acutally, it seems like it gets set if you call on_call at all--so you may way to use another variable in addition) check game.roomscript_finished==1

[Edit]: I realized I misread your question. I'd use the callroomscript as the example in the manual. But inside each if (value==1) set another variable that tells you that a response was printed to the screen. If not, then you can print a generic response.


Note that I haven't used a parser, so I may have gotten some things wrong.
~Trent
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

bspeers

All you've done is rephrased my question.  I'm trying to figure out how to detect whether a response has printed on the screen without putting an individual script in each room.

I thank you for trying to help, but it's the bit
Quotethat tells you that a response was printed to the screen
AND would allow me to distinguish whether a class of phrases was said and then print a "somewhat" generic response.  Everything else is well covered in the manual, and is actually already running in my game.

There is no documented "did something print on the screen" check that I am aware of, at least as far as I am aware.
I also really liked my old signature.

Masked Guardian

I think i can help you with this, if i got it right what you want to do. Let's take the "look at the house" input.

You've stored this in a String variable, e.g. with the name input.

So input is equal to "look at the house".

You can have an array with a certain size, as much as the objects that exist in your game. Let's say there are house,tree

So to global script:  bool arti[2];, String artiS[2], artiS[0]="house", artiS[1]="tree", int arti_size=2


On room load, you will give values to these according to their existence. E.g. if in room 1 doesn't exist house but exist tree:

arti[1]=false;
arti[2]=true;


To Ok's button script or wherever you plan:

Code: ags

int check=arti_size-1;
bool flag=true;

while(check!=-1 && check==true) {

if( bool input.EndsWith( artiS[check] ) == true && arti[check]==false ) {
  flag=false;
}

check--;
}

if(flag==false) {
   Display("There is not any %s there", artiS[check+1] );
}

else if(check==-1) {  //means that the last typed word isn't something of the standard words
   ***i'll describe this below
}

else {
  Run room Script
}




*** I didn't find any function that takes a certain part from a String e.g. the last word. I will try to create one. Place it where *** is above:

Code: ags

bool flag2=false;
int length=input.length-1;
String unword;

while(flag2==false && length!=-1) {

chat t=input.Chars[length];

if(t=='  ') {    //I don't actually know how handles AGS the "empty" character, it might be '\o' or '\n' or 'r'
   flag2=true;
}

else {
   unword.AppendChar(t);  //I hope it accepts char variable
}

length--;

}

Now, if the word was "house", then unword will be "esuoh", but with the functions i mentioned it's easy to mirror it.

String unword_mirror;
int i=unword.length-1;
while(unword_mirror.Length!=unword.Length) {
unword_mirror.AppendChar(unword.Chars[i]);
i--;
}
Display("There is not any %s there", unword_mirror ); 

*****************************************************************************************************



Uph.. big post. I just hope i haven't said anything stupid and that the above were helpful :)

Khris

Are you asking for:
Code: ags
int on_call(int p) {
  if (bla) Display("The house looks enormous.");
  else if (bli) Display("The front door is red and pretty huge.");
  else if ....
  else return 0;  // no output yet, print generic response
 
  return 1; // no generic response, a Display was called already
}


Code: ags
if (Parser.Said ("look %s", thinglooked)) {
  if ((Parser.FindWordId != -1) && (!CallRoomScript(1)))
    Display ("There is no  '%s' here", thinglooked);
}



RickJ

@KhrisMUC - I think that's what he is after but it won't work that  way because on_call() isn't called right away.  It is queued to run the next time the room script runs and so the global script will never see the return value.

Something like the following would work and is perhaps what bspeers is looking for:

Code: ags

// Room Script

int on_call(int p) {
  if (ThingLooked=="house") Display("The house looks enormous.");
  else if (ThingLooked=="front door") Display("The front door is red and pretty huge.");
  else if ....
  else GiveDefaultResponse(ThingLooked);  // no output yet, print generic response 
}


Code: ags

// Global Script

// Global variable 
String ThingLooked;
Export ThingLooked;

// Global function for default responses
function GiveDefaultResponse(String thing) {
    Display ("Looking at the '%s' won't help", thinglooked);
}

// Example
ThingLooked = "garden";
if (Parser.Said ("look %s", ThingLooked)) {
   if (Parser.FindWordId!=-1) CallRoomScript(1);
   else Display ("The '%s' doesn't exist", ThingLooked);
}


Trent R

Quote from: bspeers on Fri 06/03/2009 13:02:11
All you've done is rephrased my question.
Did you read my edit? I basiaclly said what Khris wrote code of, but as Rick says, that probably won't work.

QuoteI'm trying to figure out... without putting an individual script in each room.
That's what the on_call does.... ::)

QuoteThere is no documented "did something print on the screen" check that I am aware of, at least as far as I am aware.
I think you'd have to write your own Display/Say function. You could try dynamically resizing a GUI and print to a Label, or using Overlays is another option.

Hopefully this post isn't as nearly a waste of time and space as its predecessor.  :D
~Trent
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

bspeers

Trent R, you're not getting it, there's a communication barrier between us somehow.  None of your advice was useful or on point, but it must be my phrasing.  Your quotes were taken out of context, unecessarily sardonic and ignorant.

I am trying to COMBINE on_call with a global script that checks for a class of terms.

However, I do appreciate that you tried to help.

RickJ, on the other hand, thanks for that.  That does make sense.  I'll try setting my scripts up and report back if they worked.
I also really liked my old signature.

Trent R

To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

bspeers

Oh.  My apologies.  I thought you were rolling your eyes in exasperated sarcasm.

Sorry!

Anyway, I didn't quite find the optimal solution, but mixing various ideas came up with something that works.  I'm still not sure if there's a way to separate nouns and verbs easily so as to isolate one class from another, but my workaround provided by all of you and a bit of playing around seems to work with minimal additional effort.

Thanks folks!
I also really liked my old signature.

SMF spam blocked by CleanTalk