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: on "MouseEntry" and if-command  (Read 6711 times)

0 Members and 1 Guest are viewing this topic.

Eyes_Only

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 18
    • View Profile
on "MouseEntry" and if-command
« on: April 15, 2009, 09:11:05 PM »

Hi guys,

I've got a new Problem. I've got a table. In it's script I wrote:

Code: [Select]
on "MouseEntry"
{
if (Game.SelectedItem =="keycard")
{
Game.Msg("mouse entry");
this.SetCursor ("sprites\system\cursor_interact.sprite");
}
}

In my keycard item script I wrote:

Code: [Select]
on "MouseEntry"
{
this.SetCursor ("Medien\cursor_nina\cursor_full.png");
}

on "LeftClick"
{
Game.SelectedItem = "keycard";
}

on "RightClick"
{
actor.Talk ("Das ist eine Schlüsselkarte.");
}

But when I put the mouse onto the table, the cursor doesn't change. You know any help? If I remove the if-command everything worls fine. Can it be that the engine doesn't get the Game.SelectedItem command?
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: on "MouseEntry" and if-command
« Reply #1 on: April 15, 2009, 09:21:46 PM »

It surely should "get" it. What if you put Game.Msg(Game.SelectedItem) in there?
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Eyes_Only

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 18
    • View Profile
Re: on "MouseEntry" and if-command
« Reply #2 on: April 15, 2009, 09:39:58 PM »

Hi,

nothing happens. It seems to me as if the engine doensn't execute the if-command, because when putting the cursor with the selected item over the table, nothing happens.

I tried something: When I write: if (Game.SelectedItem =="[item]") it's ok and the cursor changes. How can this be???

« Last Edit: April 15, 2009, 09:46:43 PM by Eyes_Only »
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: on "MouseEntry" and if-command
« Reply #3 on: April 15, 2009, 09:55:21 PM »

Oh I see Game.SelectedItem actually returns the item object, not just item name, which is a little inconsistent, because you set the property using name...

Anyway, something like this will work:

Code: WME Script
  1. on "MouseEntry"
  2. {
  3.   var SelItem = Game.SelectedItem;
  4.   if(SelItem != null && SelItem.Name == "keycard")
  5.   {
  6.     // something here...
  7.   }
  8. }
  9.  
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Eyes_Only

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 18
    • View Profile
Re: on "MouseEntry" and if-command
« Reply #4 on: April 15, 2009, 09:58:12 PM »

Ok I will try that. The engine reports [item] because in game.script there is defined:
Code: [Select]
var Item = Game.SelectedItem; right?


« Last Edit: April 15, 2009, 10:05:50 PM by Eyes_Only »
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: on "MouseEntry" and if-command
« Reply #5 on: April 15, 2009, 10:03:12 PM »

No, "[item]" is the text representation of a "game object of the type 'item'".
Similarly the following code:

Code: WME Script
  1. var desk = Scene.GetNode("desk");
  2. Game.Msg(desk);
  3.  

Would display "[entity]", because the desk is an entity object.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Eyes_Only

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 18
    • View Profile
Re: on "MouseEntry" and if-command
« Reply #6 on: April 15, 2009, 10:05:58 PM »

Great, the code worked fine. But there is one problem left, when I click the right mouse button, the item is deselected and put back in the inventory. Because of game.script:

Code: [Select]
on "RightClick"
{
  // if inventory item selected? deselect it
  if (Game.SelectedItem != null)
  {
    Game.SelectedItem = null;
    return;
  }

But when I then hover the table with the cursor, it although shows me the changed cursor (and not the standard one) but not the Game.Msg () command. Do I have to deselect the item someway?
« Last Edit: April 15, 2009, 10:21:21 PM by Eyes_Only »
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: on "MouseEntry" and if-command
« Reply #7 on: April 16, 2009, 01:30:57 PM »

You might, for example, send an event to the object under cursor when you deselect the item. That way the object could catch the event and restore standard cursor image.

In game script you'd add:

Code: WME Script
  1. var ActObj = Game.ActiveObject;
  2. if(ActObj != null) ActObj.ApplyEvent("item-deselected");
  3.  

And the desk script would handle the event:

Code: WME Script
  1. on "item-deselected"
  2. {
  3.   this.SetCursor("whatever.sprite");
  4. }
  5.  
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Eyes_Only

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 18
    • View Profile
Re: on "MouseEntry" and if-command
« Reply #8 on: April 16, 2009, 07:08:55 PM »

Hmm, that doesn't work:

In game.script I added:

Code: [Select]
on "RightClick"
{
  // if inventory item selected? deselect it
  if (Game.SelectedItem != null)
  {
    Game.SelectedItem = null;
    return;
  }

  var ActObj = Game.ActiveObject;
  if(ActObj != null) ActObj.ApplyEvent("item-deselected");

With this it's the same like before. The cursor is still the changed one.

When I write:

Code: [Select]
on "RightClick"
{
  // if inventory item selected? deselect it
  if (Game.SelectedItem != null)
  {
    Game.SelectedItem = null;
    return;
    var ActObj = Game.ActiveObject;
    if(ActObj != null) ActObj.ApplyEvent("item-deselected");
  }

or:
Code: [Select]
on "RightClick"
{
  // if inventory item selected? deselect it
  if (Game.SelectedItem != null)
  {
    Game.SelectedItem = null;
    var ActObj = Game.ActiveObject;
    if(ActObj != null) ActObj.ApplyEvent("item-deselected");
    return;
  }
 
then the rightclick event doesn't work anymore. Neither the mouse menu nor the righclick events in the object scripts.
 
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: on "MouseEntry" and if-command
« Reply #9 on: April 16, 2009, 08:03:30 PM »

Ok, so let's analyze it a little, so that you better understand how things work under the hood:

Code: WME Script
  1. on "RightClick"
  2. {
  3.   // if inventory item selected? deselect it
  4.   if (Game.SelectedItem != null)
  5.   {
  6.     Game.SelectedItem = null;
  7.     return;
  8.   }
  9.  
  10.   var ActObj = Game.ActiveObject;
  11.   if(ActObj != null) ActObj.ApplyEvent("item-deselected");
  12.  
 

What does this script do? "If there is a selected item, deselect it and return". So in this case the script returns before ever reaching the added lines. Same case with the second version.


Now the third version looks better:

Code: WME Script
  1. on "RightClick"
  2. {
  3.   // if inventory item selected? deselect it
  4.   if (Game.SelectedItem != null)
  5.   {
  6.     Game.SelectedItem = null;
  7.     var ActObj = Game.ActiveObject;
  8.     if(ActObj != null) ActObj.ApplyEvent("item-deselected");
  9.     return;
  10.   }
  11.  
 

"If there is a selected item, decelect it and if there is some active object under cursor, send an event to it and return".
Looks allright. You are using the SciTE editor bundled with WME to edit scripts, are you? In the Tools menu, there is an invaluable command called 'Compile', which checks your script for syntax errors (Ctrl+F7). If you use this command, you'll get:

Quote from: SciTE
game.script(91) : Duplicate declaration of variable 'ActObj'

It means there is a syntax error in your script, therefore the engine is not able to execute it, therefore none of the functions handled by this script will work (including the menu and a lot of other things).


From the error description it should be obvious what's wrong. The variable ActObj is declared twice, which is illegal.

Code: WME Script
  1.   // if inventory item selected? deselect it
  2.   if (Game.SelectedItem != null){
  3.     Game.SelectedItem = null;
  4.     var ActObj = Game.ActiveObject; // <-- here
  5.     if(ActObj != null) ActObj.ApplyEvent("item-deselected");
  6.     return;   
  7.   }
  8.  
  9.   var ActObj = Game.ActiveObject// <-- and here
  10.  
  11.   // is the righ-click menu visible? hide it
  12.   if(WinMenu.Visible == true) WinMenu.Visible = false;
  13.   else if(ActObj!=null)
  14.   {
  15.  

So simply move the declaration to the beginning, so that both branches of the script can use it:

Code: WME Script
  1.   var ActObj = Game.ActiveObject;
  2.  
  3.   // if inventory item selected? deselect it
  4.   if (Game.SelectedItem != null){
  5.     Game.SelectedItem = null;   
  6.     if(ActObj != null) ActObj.ApplyEvent("item-deselected");
  7.     return;   
  8.   }
  9.  
  10.   // is the righ-click menu visible? hide it
  11.   if(WinMenu.Visible == true) WinMenu.Visible = false;
  12.   else if(ActObj!=null)
  13.   {
  14.  

Sorry for the lengthy post, but when people post in the forum, it's usually hard to tell what their experience with scripting is. Hopefully this will help understanding some of the concepts, and if anything, the syntax-check function in SciTE was worth pointing out.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Eyes_Only

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 18
    • View Profile
Re: on "MouseEntry" and if-command
« Reply #10 on: April 16, 2009, 08:22:37 PM »

Thank for yout post.

Quote
In the Tools menu, there is an invaluable command called 'Compile', which checks your script for syntax errors (Ctrl+F7). If you use this command, you'll get:
Quote from: SciTE
game.script(91) : Duplicate declaration of variable 'ActObj'

That's what I also found out.
Therefore I did something like this:

Code: [Select]
// if inventory item selected? deselect it
if (Game.SelectedItem != null){   
Game.SelectedItem = null;   
var ActObj = Game.ActiveObject; 
if(ActObj != null) ActObj.ApplyEvent("item-deselected");   
return;     


//var ActObj = Game.ActiveObject;

// is the righ-click menu visible? hide it
if(WinMenu.Visible == true) WinMenu.Visible = false;
else if(ActObj!=null)
{


I put the second var ... as comment.
Ok, so far. Now the bad news: Also your new posted script doesn't work. Still the same changed cursor. And no standard one. I want to use a mouse control as it is used in "The Art of murder" which is, I know, made with WME. Perhaps you know how they realized it?
Logged

Eyes_Only

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 18
    • View Profile
Re: on "MouseEntry" and if-command
« Reply #11 on: April 16, 2009, 08:37:45 PM »

I solved it. Great. Juhuuuu!!!  ;D ;D ;D ;D ;D ;D

in game.script I added:

Code: [Select]
on "RightClick"
{
var ActObj = Game.ActiveObject;
var EntTable = Scene.GetNode ("table"); <-- this here
  // if inventory item selected? deselect it
  if (Game.SelectedItem != null)
  {
    Game.SelectedItem = null;
EntTable.ApplyEvent ("item-deselected"); <-- and this here
return;

  }

And now it works fine - for so far.

I also testet your  method mnemonic and with this, it only worked, when I was deselecting the item ON the table.

Anyway. Many many thanks mnemonic for your work. Very nice support within the forum. If you perhaps have another idea (for example with the ActObj variable) I'm also willing to know. But thanks a lot.  ::thumbup

Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: on "MouseEntry" and if-command
« Reply #12 on: April 16, 2009, 08:54:49 PM »

While it works, it's not generic at all. What if you need to change cursor for 20 different objects all around your game?
I would recommend adding a "MouseLeave" event handler to the desk script instead, and reset the default cursor in it. That will solve the problem of deselecting the item while not hovering the mouse over the desk.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Eyes_Only

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 18
    • View Profile
Re: on "MouseEntry" and if-command
« Reply #13 on: April 16, 2009, 10:02:25 PM »

Thank you,

I thought that I could then add the amount of wanted objects in the game.script. A lot of work but it should work.
But I will keep in mind what you said.

Thanks a lot
Logged
 

Page created in 0.092 seconds with 21 queries.