Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: fiaschetta on Mon 06/11/2006 03:34:45

Title: Talk with character if two object is visible
Post by: fiaschetta on Mon 06/11/2006 03:34:45
I want that my characheter says "Hello" when two object in the room are OFF..

my script is:

if (Objectoff (0)) {
if (Objectoff (1)) {
Displayspeech (PG,"OK");
}
}

I put this script in "Repatedly Execute" but when i play whit object on, my PG say always "HELLO"....
What is my error?
Title: Re: Event when "Object On"
Post by: R4L on Mon 06/11/2006 03:44:45
Try this:

if ((oObject.Visible == false) && (oObject2.Visible == false)){
DisplaySpeech(PG,"OK");
}

oObject would be the script name of the object that has to be off, so if the object was named One, and the other was Two, then the script would be this:

if ((oOne.Visible == false) && (oTwo.Visible == false)){
DisplaySpeech(PG,"OK");
}

This is what you mean right?
Title: Re: Event when "Object On"
Post by: Gilbert on Mon 06/11/2006 04:09:56
Additional info: ObjectOn()/ObjectOff() were used to set the visibility of objects, and for checking their visibility, moreover, they're old functions which were obsoleted since AGS's migration to object-oriented scripting in V2.7, now, you can set and check using the single object.Visibility property, just do as R4L mentioned (unless you're still using V2.6X, they you need to use the IsObjectOn() function).
Title: Re: Event when "Object On"
Post by: fiaschetta on Mon 06/11/2006 04:23:21
Quote from: R4L on Mon 06/11/2006 03:44:45
Try this:

if ((oObject.Visible == false) && (oObject2.Visible == false)){
DisplaySpeech(PG,"OK");
}

oObject would be the script name of the object that has to be off, so if the object was named One, and the other was Two, then the script would be this:

if ((oOne.Visible == false) && (oTwo.Visible == false)){
DisplaySpeech(PG,"OK");
}

This is what you mean right?

Ok, go!
But, i put the script in "Reapatedly execute"... and my pg says always "OK" but i want that he says "OK"  and stop...
Title: Re: Event when "Object On"
Post by: Gilbert on Mon 06/11/2006 06:42:20
If you want that to happen only once, use a variable to track it, something like:

Put on top of the script, outside of all functions:
int plobjmeets=0;

Then change teh part of detection codes to:
if ((oOne.Visible == false) && (oTwo.Visible == false)&&(plobjmeets==0)){
Ã,  DisplaySpeech(PG,"OK");
Ã,  plobjmeets=1;
}

If you want the text to be displayed again when they meet a second time after they parted you need to track whether they had parted as well:
if ((oOne.Visible == false) && (oTwo.Visible == false)}{
Ã,  if (plobjmeets==0)){
Ã,  Ã,  DisplaySpeech(PG,"OK");
Ã,  Ã,  plobjmeets=1;
Ã,  }

} else plobjmeets=0;
Title: Talk with character if two object is visible
Post by: fiaschetta on Thu 16/11/2006 01:17:51
I have a room with 2 object (initially invisible) and 1 charachter..

When i talk with heÃ,  (when the 2 object are invisible) he says: "No"
When i talk with he (when object 1 is visibile and the object 2 is not) he says: "Yes!"
When i talk with he (when object 1 and 2 are visible) he says: "Hello!"

Now, i called (script-name) the object1= M1 and the object2= M2...

My script in "Talk with character" is:

ifÃ,  (oM1.Visible = false) {
DisplaySpeech (PG,"No");
}
if (oM1.Visible = true ) {
Ã,  if (oM2.Visible = true) {
DisplaySpeech (PG,"Yes");

}
else if (oM1.Visible = true){
Ã,  if (oM2.Visible = false){
DisplaySpeech (PG, "Hello");

}
}
}
}


But, when i test the gameÃ,  go out a windows that says: "Undefined symbol oM2"

What is my error?
Title: Re: Talk with character if two object is visible
Post by: Ashen on Thu 16/11/2006 01:44:15
Topics merged, since it's kind of a continuation of the same question.

For checking variables, you need to use '==', so for example it'd be:

if  (oM1.Visible == false) {

not

if  (oM1.Visible = false) {


But that'd generate a different error, so maybe that's just how you've typed it here.

You can also cut down on the braces a little by combining some of the condition, like Gilbot and R4L have done:

if  (oM1.Visible == false) {
  DisplaySpeech (PG,"No");
}
else if ((oM1.Visible == true ) && (oM2.Visible == true)) {
  DisplaySpeech (PG,"Yes");
}
else if ((oM1.Visible == true) && (oM2.Visible == false)){
  DisplaySpeech (PG, "Hello");
}



Other than that, the code looks OK - the only thing I can suggest is to make sure the script-name is set properly and you haven't maybe set M2 as the Name, not the Script-Name, or it's just 'M', or some other typo.

One thing - you've got the conditions the wrong way round. With that code it'll display "Yes" when both objects are visible, and "Hello" when object 1 is visible, object 2 isn't. (Opposite way to what you said you want.)
Title: Re: Talk with character if two object is visible
Post by: Khris on Thu 16/11/2006 03:31:27
  if (oM1.Visible) {
    if (oM2.Visible) cPg.Say("Hello!");
    else cPg.Say("Yes!");
  }
  else if (!oM2.Visible) cPg.Say("No");

:=

@fiaschetta:
By default, everything inside repeatedly_execute() is run 40 times *per second*.
Title: Re: Talk with character if two object is visible
Post by: fiaschetta on Thu 16/11/2006 09:52:36
Quote from: Ashen on Thu 16/11/2006 01:44:15
Other than that, the code looks OK - the only thing I can suggest is to make sure the script-name is set properly and you haven't maybe set M2 as the Name, not the Script-Name, or it's just 'M', or some other typo.

One thing - you've got the conditions the wrong way round. With that code it'll display "Yes" when both objects are visible, and "Hello" when object 1 is visible, object 2 isn't. (Opposite way to what you said you want.)


Ok, but ags debug says that "oM1" is undefined symbol... why?
Title: Re: Talk with character if two object is visible
Post by: Scorpiorus on Thu 16/11/2006 10:00:17
Just as Ashen already suggested make sure you gave a Script Name to both objects:

First Object script name: M1
Second Object script name: M2
Title: Re: Talk with character if two object is visible
Post by: SSH on Thu 16/11/2006 12:04:45
I think the problem is that the character interaction code is in the Global script, and the objects are only defined in the Room script. So, what can you do?

There are various possibilities.

1. use object numbers instead of names, so replace oM1 and oM2 with object[1] and object[2] (assuming they are objects 1 and 2 in the room)
2. declare some Object * variables in the main script , export/import them and in the player enters room interaction fo the room, run a script that sets the global objects to point to your room objects.
3. Have some global variables set whenever the objects are turned on or off to keep their state saved throughout the game, in any room

In cases 1 and 2, you should add a check to the character interaciotn code which makes sure you are in the correct room
Title: Re: Talk with character if two object is visible
Post by: Ashen on Thu 16/11/2006 12:44:34
Right, yes.
Script-o-names for objects (e.g. oM1, oM2) are only good in the Room script for the room they're in. Since fiaschetta said the error was with oM2, it didn't occur to me that the 'Talk with character' interaction would be in the Global Script (oM1 is mentioned first, so that should've caused an error too).
If it is in the Global Script, then SSH's suggestions are the way to go. If not - where IS the code you posted, in your script?