on_call Function [SOLVED]

Started by Atelier, Fri 08/01/2010 16:45:46

Previous topic - Next topic

Atelier

I'm having trouble with the on_call function. I'm using the text parser and so want to call room-specific inputs. Here is the code in my global script:

Code: ags
function InputBox_OnActivate(GUIControl *control) //Input box is my text box.
{
   if (player.Room == 1) CallRoomScript(1); //When the player presses enter and is in room 1.
   if (player.Room == 2) CallRoomScript(2); //And so on.
}


And here is my room script (function at very top):

Code: ags
function on_call (int value) {
   if (value == 1) {

   if (Parser.Said("look tree")) Display("A tree.");
   if (Parser.Said("eat tree")) Display("That would give me indigestion."));
   //etc
   }
}


But when I type any of those two in the text box and enter, it doesn't respond at all. Is there anything wrong with my code on the outset?

Thanks,
AtelierGames

tzachs

Two potential problems I can see here:

1. I don't see in the code how you associated your textbox with the parser. You have to call Parser.ParseText(InputBox.Text), otherwise Parser.Said(...) will always return false.

2. There's no reason to put the room number as a parameter to the CallRoomScript. Since the on_call function should be written for each room you want to use (inside the room script), you already know which room you are in. The parameter should indicate the task you want to perform, not the room...

Khris

Well, first of all, instead of writing an if line for every room, you can do
Code: ags
  CallRoomScript(player.Room);

(It continues to amaze me how people manage to not make this connection.)

Second of all, there's no reason to do an if check inside on_call; in order for the first room's on_call to be called, the parameter has to be 1.

You need to seriously rethink your way of processing local and global parser lines.
In the global script, check if the player addressed something global or room-specific, then send the command to the room script.

Regarding your problem, you need to do
Code: ags
Parser.ParseText(InputBox.Text);
first in order for Parser.Said to work.

Atelier

Thank you very much both; everything works perfectly now with great effect!

SMF spam blocked by CleanTalk