Please login or register.

Login with username, password and session length
Advanced search  

News:

IRC channel - server: waelisch.de  channel: #wme (read more)

Author Topic: Catching mouse left click while executing script  (Read 5783 times)

0 Members and 1 Guest are viewing this topic.

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Catching mouse left click while executing script
« on: February 13, 2011, 04:34:00 PM »

We are trying to make a dialogue window, where the player will select the proper dialogue option and then the dialogue will be slowly written on the dialogue box. Here is my test code so far:
Code: [Select]
var text = new String("This is a test for writting the dialogue on the dialogue window.");
var tempText = new String("");
var dialogue = notepadWindow.GetControl("textDiagolueUp");
for(var i = 0; i < text.Length; i = i + 1){
tempText = tempText + text.Substring(i, i);
dialogue.Text = tempText;
Sleep(100);
}

Now I am trying to do two things. First, while the dialogue is written, if the player presses left mouse button I want the dialogue text to be completed instantly.

Then, when the dialogue is finally shown, I want to wait again for the left mouse button to be pressed to write the next piece of dialogue for the second participant.

Any ideas on how to achieve this?
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Catching mouse left click while executing script
« Reply #1 on: February 13, 2011, 04:52:40 PM »

When the player clicks the mouse button, a "LeftClick" event handler is called in game.script. So basically you'll need two pieces of script to communicate together, the LeftClick handler and the text display routine. To communicate I'd use global variables. The text display function would use a global variable to signalize that text rendering is in progress, and the LeftClick handler would use it first to check whether it should control the text, or whether standard click handling should happen. If the former is the case, the LeftClick handler would use another global variable to tell the text routine to display complete text.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Re: Catching mouse left click while executing script
« Reply #2 on: February 13, 2011, 04:59:48 PM »

Well it seems very obvious now  ::)

To add to your response, I guess the "wait for mouse to click to continue dialogue" could be implemented like this:

Code: [Select]
while(!finished_dialogue){
     sleep(10);
}
using another global variable.

Thanks for your constantly quick responses.
Logged

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Re: Catching mouse left click while executing script
« Reply #3 on: February 13, 2011, 09:24:39 PM »

Unfortunately it doesn't work. I should mention that the dialogue interface is a window which opens with window.GoSystemExclusive(). Perhaps the event is caught somewhere else?
Logged

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Re: Catching mouse left click while executing script
« Reply #4 on: February 13, 2011, 09:49:40 PM »

I tried placing the following piece of code inside dialogue.scirpt (which is attached on the dialogue window through window editor):

Code: [Select]
on "LeftClick"
{
var ActObj = Game.ActiveObject;
if(insideDialogue == true){
dlgMouseClicked = true;
return;
}
if(ActObj != null){
ActObj.ApplyEvent("LeftClick");
}
}

This seems to work but after clicking 4-5 times the game gets stuck and I have to manually close it through task manager. It also gets stuck if I click somewhere in the dialogue window as soon as I open it.
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Catching mouse left click while executing script
« Reply #5 on: February 16, 2011, 12:52:57 PM »

Hm, it's hard to tell what's wrong there. Is it necessary to use GoSystemExclusive for captions? That one is intended mainly for system windows (save/load, settings etc.), because it freezes the game.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Re: Catching mouse left click while executing script
« Reply #6 on: February 16, 2011, 01:20:41 PM »

Hm, it's hard to tell what's wrong there. Is it necessary to use GoSystemExclusive for captions? That one is intended mainly for system windows (save/load, settings etc.), because it freezes the game.

It's not actually "captions". We have a dialogue interface, with portraits of the two "participants" (our actor and another NPC) shown above and below the screen, where the dialogue will be written next to their portraits. We will have not only dialogue choices for the user to choose but also items that the player will show or ask about. I used .GoSystemExclusive() because I wanted the game to freeze, so that clicking will not make the player move around.

If you have something else to propose I will be more than happy to hear it. As for why the game hangs, perhaps it is a bug of the engine? I can send you some source to check it out if you are willing to help me further.
Logged

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Re: Catching mouse left click while executing script
« Reply #7 on: February 17, 2011, 08:50:28 PM »

The following piece of code was causing the problem.

Code: WME Script
  1. if(ActObj != null){
  2.     ActObj.ApplyEvent("LeftClick");
  3. }
  4.  

When clicking on the window (not one of the buttons, static etc.) the ActObj was the window itself. So it called its leftclick event handler and it got stuck in an infinite loop.
Logged
 

Page created in 0.05 seconds with 25 queries.