Talk with character if two object is visible

Started by fiaschetta, Mon 06/11/2006 03:34:45

Previous topic - Next topic

fiaschetta

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?

R4L

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?

Gilbert

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

fiaschetta

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...

Gilbert

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;

fiaschetta

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:
Code: ags

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?

Ashen

#6
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:
Code: ags

if  (oM1.Visible == false) {

not
Code: ags

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:
Code: ags

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.)
I know what you're thinking ... Don't think that.

Khris

Code: ags
  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*.

fiaschetta

#8
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?

Scorpiorus

#9
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

SSH

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
12

Ashen

#11
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?
I know what you're thinking ... Don't think that.

SMF spam blocked by CleanTalk