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: Help: High Level Events  (Read 6427 times)

0 Members and 1 Guest are viewing this topic.

Javi-Wan Kenobi

  • Supporter
  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 34
    • View Profile
Help: High Level Events
« on: October 30, 2006, 11:01:45 AM »

Hi
First, , I apologize if my english is not as good as I'd like.

I don't know if that's been already asked, so I ask it because I need an answer. I'm completely lost.
I've read several times that the engine has Low Level Events -such as "LeftClick", "MouseEntry", etc, already implemented in the engine- and High Level Events -such as "LookAt", "Take", etc, wich are created by the designer.
But I've searched everywhere the way to create these "customized" high level events and I haven't found it.
Someone can illuminate me, please?
Logged

Javi-Wan Kenobi

  • Supporter
  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 34
    • View Profile
Re: Help: High Level Events
« Reply #1 on: October 30, 2006, 01:12:21 PM »

If someone can help me, maybe he can give me a more accurate answer about what I need.
The idea is to do a sort of "point&wait" game, in wich "click" is never needed.
So I think I need a high level event that, using the "MouseEntry" low-level event and some waiting time without "MouseLeave", allows the player interact as with a normal "LeftClick" event.
I'm not asking for the entire code for that event, but some tips and general ideas will be welcomed .
Logged

adonf

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 124
    • View Profile
Re: Help: High Level Events
« Reply #2 on: October 30, 2006, 02:31:01 PM »

for your first question:

you define a custom event callback function in your object's script like you do for standard events. for example if your object called "gabbleblotchit" reacts to the event "plurdle", just define

Code: [Select]
on "plurdle"
{
    // do something here
}

in gabbleblotchit.script or whatever script is ran on gabbleblotchit, you trigger the even by calling

Code: [Select]
var obj = Scene.GetNode("gabbleblotchit_033");
if (obj.CanHandleEvent("plurdle")
{
    obj.ApplyEvent("plurdle");
}



as for your second question, something like this could work:

Code: [Select]
var bCanTrigger = false;

on "MouseEntry"
{
    bCanTrigger = true;
    Sleep(1000); // trigger after one second
    if (true == bCanTrigger)
    {
        this.ApplyEvent("MouseAction");
    }
}

on "MouseLeave"
{
    bCanTrigger = false;
}

// your custom event that is triggered when the mouse spends 1 second in the object
on "MouseAction"
{
    // do something here
}

but there might be race conditions if you enter and leave the objects several times, I don't know. I don't know if scripts can be reentrant too (ie. triggering "MouseLeave" while "MouseEntry" is still running might not work...)
Logged
I am the Milkman. My milk is good.

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Help: High Level Events
« Reply #3 on: October 30, 2006, 09:14:35 PM »

Another solution, assigning the following script to Game (in ProjectMan) simulates LeftClick events when the mouse pointer stands still at some object for 1 second:

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

var WaitStart;
var WaitObj = null;


while(true)
{
  if(Game.ActiveObject != WaitObj)
  {
    WaitObj = Game.ActiveObject;
    WaitStart = Game.CurrentTime;
  }
  else if(WaitObj != null)
  {
    if(Game.CurrentTime - WaitStart >= 1000)
    {
      WaitObj.ApplyEvent("LeftClick");
      WaitStart = Game.CurrentTime;
    }
  }
  Sleep(100);
}
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Javi-Wan Kenobi

  • Supporter
  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 34
    • View Profile
Re: Help: High Level Events
« Reply #4 on: October 30, 2006, 09:17:29 PM »

Thanks. Really. This has been really helpful.
I supose that if I want to make "MouseAction" the main interaction event, that code (or similar) must be in a global file such as "game.script", it isn't?
Logged

Javi-Wan Kenobi

  • Supporter
  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 34
    • View Profile
Re: Help: High Level Events
« Reply #5 on: October 31, 2006, 10:01:46 AM »

A little question about your suggestion, Mnemonic.
For that code to work as expected, is neccesary that the mouse pointer stands TOTALLY still, or it can be slightly moving over the object?
« Last Edit: October 31, 2006, 10:03:43 AM by Javi-Wan Kenobi »
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Help: High Level Events
« Reply #6 on: October 31, 2006, 10:35:12 AM »

It can be moved within the bounds of the object.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Javi-Wan Kenobi

  • Supporter
  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 34
    • View Profile
Re: Help: High Level Events
« Reply #7 on: October 31, 2006, 11:35:36 AM »

Ok, thanks
Logged

Javi-Wan Kenobi

  • Supporter
  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 34
    • View Profile
Re: Help: High Level Events
« Reply #8 on: November 06, 2006, 09:41:07 PM »

Mnemonic, if you don't mid, I need a little more help, please.
The code you give me works perfectly when trying to interact with an object in the room (actors and entities). Can I do something similar to interact with GUI elements, such as buttons in windows, or the options in the menu (LookAt, Take, Talk...), etc...?
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Help: High Level Events
« Reply #9 on: November 06, 2006, 10:13:39 PM »

To make the code work for buttons, you'd need to do modify it like this:

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

var WaitStart;
var WaitObj = null;


while(true)
{
  if(Game.ActiveObject != WaitObj)
  {
    WaitObj = Game.ActiveObject;
    WaitStart = Game.CurrentTime;
  }
  else if(WaitObj != null)
  {
    if(Game.CurrentTime - WaitStart >= 1000)
    {
      if(WaitObj.Type=="button") WaitObj.Press();
      else WaitObj.ApplyEvent("LeftClick");
      WaitStart = Game.CurrentTime;
    }
  }
  Sleep(100);
}

But this will only work for non-system-exclusive windows, because system exclusive windows freeze the scripts including this one.

If you need to apply the same system to system exclusive windows, it will be more tricky. You'd need to attach the script to each of the windows. Also, in this window script you'll need to replace Game.CurrentTime with Game.WindowsTime (background: system exclusive windows freeze the internal game timer, therefore we can't use it anymore for checking the elapsed time, we must use the Windows timer instead).
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Javi-Wan Kenobi

  • Supporter
  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 34
    • View Profile
Re: Help: High Level Events
« Reply #10 on: November 06, 2006, 10:52:08 PM »

I will try it. Thanks a lot.
Logged

Javi-Wan Kenobi

  • Supporter
  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 34
    • View Profile
Re: Help: High Level Events
« Reply #11 on: February 24, 2007, 02:47:48 PM »

Hi.
I need a way to change the line
Quote
if(Game.CurrentTime - WaitStart >= 1000)
into something like
Quote
if(Game.CurrentTime - WaitStart >= WaitTime)
where "WaitTime" is a global variable that you can change in a options menu.
I've tried several ways but I didn't find a good one.
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: Help: High Level Events
« Reply #12 on: February 24, 2007, 03:35:44 PM »

in the options script put:


global WaitTime;

then somewhere assign WaitTime = SomeValue;

In your script with that condition do again:

global WaitTime;
if(Game.CurrentTime - WaitStart >= WaitTime)

Alternatively you can save yourself a hassle by putting global WaitTime; into your base.inc file

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

Javi-Wan Kenobi

  • Supporter
  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 34
    • View Profile
Re: Help: High Level Events
« Reply #13 on: February 24, 2007, 04:08:03 PM »

Thanks
Logged
 

Page created in 0.215 seconds with 24 queries.