Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Phemar on Sat 06/03/2004 07:25:18

Title: What's Wrong?
Post by: Phemar on Sat 06/03/2004 07:25:18

Can you see anything wrong with my script, besides the fact that it doesn't want to work and I don't know whats wrong?

function room_a() {
 // script for room: Repeatedly execute
 if (Said("look")) {
   DisplayMessage (0);
 }
 if (Said("look desk")) {
   if (gotball == 0) {
     DisplayMessage (1);
   }
   else {
     DisplayMessage (2);
     }
   }
 if (Said("look computer")) {
   DisplayMessage (3);
 }
 if (Said("Get [golf] ball")) {
   if (get_hotspot() != 4) {
     Display ("Move closer!");
     }
   else {
     Display ("You pick up one of the golf balls.");
     ObjectOff (0);
     AddInventory (1);
     }
   }
 }


What happens is that if you say something, it displays over and over again.

Like this
Like this
Like this
Like this
Like this
Like this
Like this
Like this
etc.

Help anyone?
Title: Re:What's Wrong?
Post by: Wolfgang Abenteuer on Sat 06/03/2004 07:42:31
Maybe you shouldn't put it in the repeatedly_execute of the room.  I'm guessing what happens is that when you press <Enter>, whatever you typed in is entered into the given string, and then the repeatedly_execute checks each game cycle to see if that string matches one of your Said() lines (which it will), thus repeating the line over and over again. *shrugs*

~Wolfgang
Title: Re:What's Wrong?
Post by: Scorpiorus on Sat 06/03/2004 12:36:16
Yeah, those kind of things should be typed-in within the room's on_call (int value) function

main global script:

function on_interface_click(int interface, int button) {

Ã, Ã, Ã, if (interface == GUINAME) {
Ã, Ã, Ã, Ã, Ã, Ã, if (button == TEXTBOXNUMBER) {
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, string input;
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, GetTextBoxText (interface, button, input);
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, ParseText (input);
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, string buffer;
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, if (SaidUnknownWord (buffer))
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Display("You can't use '%s' in this game.", buffer);
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, else if (Said("eat apple")) {
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Display("You'd love to, but you don't have one.");
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, }
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, else CallRoomScript(1);
Ã, Ã, Ã, Ã, Ã, Ã, }
Ã, Ã, Ã, }

}



room script:

function on_call(int value) {

Ã, Ã, Ã, if (value == 1) {

Ã, Ã, Ã, Ã, Ã, Ã, if (Said("look")) {
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, DisplayMessage (0);
Ã, Ã, Ã, Ã, Ã, Ã, }
Ã, Ã, Ã, Ã, Ã, Ã, if (Said("look desk")) {
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, if (gotball == 0) {
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, DisplayMessage (1);
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, }
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, else {
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, DisplayMessage (2);
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, }
Ã, Ã, Ã, Ã, Ã, Ã, }
Ã, Ã, Ã, Ã, Ã, Ã, if (Said("look computer")) {
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, DisplayMessage (3);
Ã, Ã, Ã, Ã, Ã, Ã, }
Ã, Ã, Ã, Ã, Ã, Ã, if (Said("Get [golf] ball")) {
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, if (get_hotspot() != 4) {
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Display ("Move closer!");
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, }
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, else {
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Display ("You pick up one of the golf balls.");
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, ObjectOff (0);
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, AddInventory (1);
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, }
Ã, Ã, Ã, Ã, Ã, Ã, }


Ã, Ã, Ã, }

}

Works this way?

~Cheers
Title: Re:What's Wrong?
Post by: Phemar on Sat 06/03/2004 16:00:26
It used to be in the on_call function, but then when I typed the stuff, it did't work. Then I saw the repeatedly execute funcyion and decide to try that.

I saw that you put callroomscript by the gui script there? what does that mean?

I just had an idea! I could put after every line:

SetTextBoxText (0, 0, "");

Would that work?

EDIT
Nope, the settextboxtext doesn't work.
Title: Re:What's Wrong?
Post by: Phemar on Sat 06/03/2004 16:18:22


Woah I added all your scorpio and now it doesn't respond at all. I understand the call room script, but [exclaim]huh?[/exclaim] it doesn't respond to my typing at all!
Title: Re:What's Wrong?
Post by: Scorpiorus on Sat 06/03/2004 16:21:00
QuoteI saw that you put callroomscript by the gui script there? what does that mean?
The CallRoomScript() function calls the on_call() function located in the current room. The on_call function processes all the commands related to the current room, therefore you can have two rooms reacting differently when you type-in "look" word.

Quote
I just had an idea! I could put after every line:

SetTextBoxText (0, 0, "");

Would that work?
if you want to erase the textbox text, just add:

function on_interface_click(int interface, int button) {

Ã, Ã, Ã, if (interface == GUINAME) {
Ã, Ã, Ã, Ã, Ã, Ã, if (button == TEXTBOXNUMBER) {
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, string input;
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, GetTextBoxText (interface, button, input);
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, SetTextBoxText (interface, button, "");
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, ParseText (input);
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, string buffer;
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, if (SaidUnknownWord (buffer))
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Display("You can't use '%s' in this game.", buffer);
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, else if (Said("eat apple")) {
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Display("You'd love to, but you don't have one.");
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, }
Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, else CallRoomScript(1);
Ã, Ã, Ã, Ã, Ã, Ã, }
Ã, Ã, Ã, }

}

QuoteWoah I added all your scorpio and now it doesn't respond at all. I understand the call room script, but [exclaim]huh?[/exclaim] it doesn't respond to my typing at all!
Are you sure you set  GUINAME and TEXTBOXNUMBER correctly?
Title: Re:What's Wrong?
Post by: Phemar on Sat 06/03/2004 16:59:55

Yeah, This my script:

if (interface == 0) {
   if (button == 0)
   {string forparser,unknownbuffer;
    StrCopy(forparser,"");
    GetTextBoxText(0,0,forparser);
    InterfaceOff(0);
    if (StrComp(forparser,""))
     {ParseText(forparser);
      if (SaidUnknownWord(unknownbuffer))
        Display ("I don't understand the word '%s'.",unknownbuffer);
        }
        else CallRoomScript(1);
     }
   }

// room script file
int gotball=0;

function get_hotspot () {
 return GetHotspotAt (character[GetPlayerCharacter()].x, character[GetPlayerCharacter()].y);
}

function on_call (int value) {
 // script for room: Repeatedly execute
 if (value==1) {
   if (Said("look")) {
     DisplayMessage (0);
   }
   if (Said("look desk")) {
     if (gotball == 0) {
       DisplayMessage (1);
     }
     else {
       DisplayMessage (2);
       }
     }
   if (Said("look computer")) {
     DisplayMessage (3);
   }
   if (Said("Get [golf] ball")) {
     if (get_hotspot() != 4) {
       Display ("Move closer!");
       }
     else {
       Display ("You pick up one of the golf balls.");
       ObjectOff (0);
       AddInventory (1);
       }
     }
   }
 }

 

Title: Re:What's Wrong?
Post by: Scorpiorus on Sat 06/03/2004 17:34:47
if (interface == 0) {
if (button == 0)
{string forparser,unknownbuffer;
StrCopy(forparser,"");
GetTextBoxText(0,0,forparser);
SetTextBoxText(0,0,"");
InterfaceOff(0);
if (StrComp(forparser,""))
{ParseText(forparser);
if (SaidUnknownWord(unknownbuffer))
Display ("I don't understand the word '%s'.",unknownbuffer);
//}
else CallRoomScript(1);
}
}
}

Just remove that brace ;)
Title: Re:What's Wrong?
Post by: Phemar on Sat 06/03/2004 18:52:09

Wow, Thanx. It totally works now.

Greatest thanks to scorpiorus!