Please login or register.

Login with username, password and session length
Advanced search  

News:

This forum provides RSS feed. To query recent posts use this url. More...


Author Topic: Rookie Question about actor.Talk and LeftClick, LeftDoubleClick  (Read 5330 times)

0 Members and 1 Guest are viewing this topic.

Pixelschmied

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 16
    • View Profile
    • www.seelentanz.com
Rookie Question about actor.Talk and LeftClick, LeftDoubleClick
« on: January 21, 2008, 09:03:01 PM »

Hello WMs,

I have a door in my scene and if you "LeftClick" the actor "WalkTo" to this door and speaks a sentence. The same with "LeftDoubleClick" and "RunTo" with the same sentence. All works fine, but I have a question: It is possible that I set only once this sentence, because I do not want to do everything twice, because it's the same thing. I hope you can understand what I mean.

My door script look like this:

Code: WME Script
  1. on "LeftClick"
  2. {
  3.         actor.WalkTo(220, 621);
  4.         actor.TurnTo(DI_UP);
  5.         actor.Talk("This door is closed!");
  6. }
  7.  
  8. on "LeftDoubleClick"
  9. {
  10.         actor.RunTo(220, 621);
  11.         actor.TurnTo(DI_UP);
  12.         actor.Talk("This door is closed");
  13. }
  14.  


My idea was e.g.

var = WasClicked = 0;
and within on "LeftClick" and "LeftDoubleClick" I set the WasClicked +1
and after all I will ask if(WasClicked == 1)
{
actor.Talk("This door is closed!")
}

I don't know how I should do it. Thank you in advance for your help.

Logged

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: Rookie Question about actor.Talk and LeftClick, LeftDoubleClick
« Reply #1 on: January 21, 2008, 09:14:41 PM »

first of all, you'd need a global variable for this. I'd do this code like this:

Code: [Select]
#include "base.inc"

global doorTested;

function handleDoor()  // I hate triplicating code, let's keep it tidy
{
       actor.TurnTo(DI_UP);
       if (!doorTested) actor.Talk("This door is closed!");
       doorTested = true;
}

on "LeftClick"
{
    actor.WalkTo(220, 621);
        handleDoor(); 
}

on "LeftDoubleClick"
{
actor.RunTo(220, 621);
        handleDoor(); 
}

Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

Pixelschmied

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 16
    • View Profile
    • www.seelentanz.com
Re: Rookie Question about actor.Talk and LeftClick, LeftDoubleClick
« Reply #2 on: January 21, 2008, 09:28:25 PM »

Thank you very much for your help metamorphium. It works all fine and will continue to try to learn.
Logged

Pixelschmied

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 16
    • View Profile
    • www.seelentanz.com
Re: Rookie Question about actor.Talk and LeftClick, LeftDoubleClick
« Reply #3 on: January 23, 2008, 01:38:23 AM »

Hallo WMs,

I play around with this code-snippets above and I noticed - I hope I declare right-  that the function is not always invited. It sometimes works only one time, on another twice or it makes no problem. Confusing or? Perhaps I have too much coffee drunk :o.

I change into the function handleDoor() the global variable doorTested from = true to false, tested araound and now it is working always.

All have a good night,

Pixelschmied

Logged

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: Rookie Question about actor.Talk and LeftClick, LeftDoubleClick
« Reply #4 on: January 23, 2008, 09:12:12 AM »

problem might be if you click "out of the action". Which means that the variable is not set and you can get this behavior. You can fix this by this:

Code: [Select]

function handleDoor() 
{
       actor.TurnTo(DI_UP);

       if (!doorTested)
       {
          doorTested = true;
          actor.Talk("This door is closed!");
       }
}


Now when actor talks, you're sure he won't be talking again, as the variable has been set already.
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

Pixelschmied

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 16
    • View Profile
    • www.seelentanz.com
Re: Rookie Question about actor.Talk and LeftClick, LeftDoubleClick
« Reply #5 on: January 23, 2008, 10:10:32 AM »

Hello metamorphium,

thank you for your fast response. I think that I understand it. When the actor talk only once then the variable "doorTested" is set to true, and thus is the condition met. If I want the character always talk his sentence when "LeftClick" or "LeftDoubleClick" the e.g. door, I can make it as above because the variable is set to false and therefore the value is not set.

Is the way right? If so, then I see light at the end of the dungeon ;)

Nice day,
Pixelschmied

Logged

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: Rookie Question about actor.Talk and LeftClick, LeftDoubleClick
« Reply #6 on: January 23, 2008, 11:40:43 AM »

yes, but if you want him always to say the line, you don't need this variable at all.  ;)
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

Pixelschmied

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 16
    • View Profile
    • www.seelentanz.com
Re: Rookie Question about actor.Talk and LeftClick, LeftDoubleClick
« Reply #7 on: January 23, 2008, 12:47:19 PM »

Hello metamorphium,

ah ok, because the value of the variable will not changed. I see even a more little light shines on  :) Thanks a lot for your help and quick-teaching.

With bravest coding greets,

Pixelschmied

Logged
 

Page created in 0.124 seconds with 25 queries.