getting 2 different responses to the same interaction [urgent]

Started by nofnit, Wed 10/06/2009 11:09:19

Previous topic - Next topic

nofnit

Well, I'm working on a very simple point and click game and I'm having trouble on the following:
I have an object (oespelho) which should have a reaction to the first time the player clicks on it in interact mode, then a different one from then on. I've been trying with variables but I've gotten so lost I decided to just ask.
It's sort of an urgent matter.
Thank you in advance.

Sofia

GuyAwesome

Try Game.DoOnceOnly (check the manual for usage). That should do what you want, but if you need more than two reactions (like first time to something, second time something else, THIRD time another thing, etc), you're going to need to sort out using variables. If you still can't figure them out once the urgency has passed ;), post what you've got and someone will probably be able to put you right.

Mazoliin

Variables is the right way to go, but it would be nice to know what you tried?
Anyway, this is how one would do:
Code: ags

//Top of script
int oespelho;

//In the oespelho interaction part
if (oespelho == 0){
  //First interaction
  oespelho = 1;
}
else {
  //Other interaction
}


EDIT:
GuyAwesome's right. DoOnceOnly is best for these sort of things.

nofnit

Thanks for the answers.
I'll be honest with you, i'm as new as they get on AGS, and i'm embarassed to show you what i've been trying because it must be really silly... but i'll do it anyway, just don't make fun... I sort of chose a variable that made the least bit of sense...and it obviously doesn't...

function oespelho_Interact ()
{
  if (oespelho.Graphic == 8) {
  cdaniel.Say("Vamos la ver o que temos aqui...");
  cdaniel.Walk(403, 518, eBlock);
  object[0].Graphic = 27 ;
  cdaniel.Say("E um espelho de corpo inteiro."); }
if (oespelho.Graphic == 27) {
  cdaniel.Say("Hm...Tenho uma ideia.");
  cdaniel.Move(400, 343);
}

I did notice that DoOnce Only, but after reading the manual I still couldn't understand how to use it so i tried all sorts of insane ideas untill i was exhausted, so i just asked for help. Can you just give me an example on how to use it? Meanwhil i'll try the one mazoliin suggested.

Thank you

GuyAwesome

Assuming object[0] is the same object as oespelho, that should kind of work - kind of, becuase it looks like it'll run the second part, immediately after the first, the first time you click (because you've changed the grahic so it meets the next conditon). So
Code: ags

function oespelho_Interact ()
{
  if (oespelho.Graphic == 8) {
    cdaniel.Say("Vamos la ver o que temos aqui...");
    cdaniel.Walk(403, 518, eBlock);
    object[0].Graphic = 27 ;
    cdaniel.Say("E um espelho de corpo inteiro.");
  }
  else if (oespelho.Graphic == 27) {  // 'else if', so it runs one or the other, not both back-to-back
    cdaniel.Say("Hm...Tenho uma ideia.");
    cdaniel.Move(400, 343);
  }
}


Should work, assuming the object and graphic numbers are right, but Mazoliin's way might work better (and is good practice for using variables in general :)). As for DoOnlyOnce, the manual doesn't really show you what to do AFTER it's been done once, but something like
Code: ags

function oespelho_Interact ()
{
  if (Game.DoOnlyOnce("oespelhoInteract")) {
    cdaniel.Say("Vamos la ver o que temos aqui...");
    cdaniel.Walk(403, 518, eBlock);
    object[0].Graphic = 27 ;
    cdaniel.Say("E um espelho de corpo inteiro."); 
  }
  else {  
    cdaniel.Say("Hm...Tenho uma ideia.");
    cdaniel.Move(400, 343);
  }
}



And, although you edited your post while I was typing:
Quote
cdaniel.RunInteraction = (1);

That's not how that function works, which'd cause problems as well. It should be
Code: ags

cdaniel.RunInteraction(1);

Will run the cursor mode 1 (Look) interaction for the character. Use the CursorMode enum values (eModeLook, eModeInteract, eModeTalk, etc) instead of the number, to make it easier to see which mode should be used.

nofnit

Thank you so very much, you saved my day! I have a hard time understanding this sort of thing without concrete examples and the manual only took me so far... (and see, that RunInteract bit, that's one of the insane things i was talking about...after i've tried all the reasonable stuff and i can't make it work i just go on to using nonsense... :-[)
I can honestly say this is the best help I've ever gotten in any forum! Thank you!

*

Trent R

Ways to use your existing code:
1) Add an else if to the second if statement (like Guy's first block of code)
2) Remove the second if and replace it with an else (like Guy's second block of code)
3) Add a return command at the end of the first if statement, which terminates the rest of the script

Also, the only time you need to use the object[] array is in the global script. Otherwise, you can just use it's script name (oespelho).

Another thing of mention, you can format sections of code (like above) by putting it between [ code ] [ /code ] brackets (minus the spaces).


~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

SMF spam blocked by CleanTalk