Please login or register.

Login with username, password and session length
Advanced search  

News:

For WME related articles and tutorials visit WME Resource Center.

Author Topic: On look, on book, on right click scripts  (Read 5766 times)

0 Members and 1 Guest are viewing this topic.

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
On look, on book, on right click scripts
« on: October 28, 2008, 03:58:37 AM »

Am following the WME Book demo and have met a new problem.  I can't get these scripts to work.  I don't know how to look at an item.  : )  How do you do that?  Do I have to have a "look at" script or is it in the "const.inc" script or someplace else?

Basically Molly and Sally can both go to and pick up the book and put it in their individual inventories--and they do have individual inventories.  But I don't know how to make them look at the book or give the book to each other.  They refuse.   I don't have any script errors--just don't have the action I expected. 

This is the script on the book.  Neither Molly nor Sally nor the book have a rightclick script--does that make sense?

#include "scripts\base.inc"

on "LeftClick"
{
        actor.GoToObject(this);
      actor.TakeItem("book");   
}


on "LookAt"
{
  actor.Talk("Guess I should read through this...");
}

////////////////////////////////////////////////////////////////////////////////
on "Take"
{
  Game.SelectedItem = "book";
}


This is my Molly script--Sally's is about the same:

#include "scripts\base.inc"

on "LeftClick"
{
   if (Game.MainObject == molly) actor.Talk("I am already selected!");
   else
   {
      actor = molly;
      Game.MainObject = actor;
      Game.InventoryObject = actor;
   }
}

on "book"
{   
   if (actor == molly) actor.Talk("It's always important to read WME documentation! I'll do it now!");
   else
   {
      Game.SelectedItem = null;
      sally.DropItem("book");
      molly.TakeItem("book");   
      molly.Talk("Thank you");
   }
}

This is my game script--

#include "scripts\base.inc"
#include "scripts\keys.inc"

// store some of the game's attributes in global variables for convenience
Keyboard = Game.Keyboard;
Scene = Game.Scene;

// load the "caption" window
var win = Game.LoadWindow("interface\system\caption.window");
global WinCaption = win.GetControl("caption");

// load our main actor
molly = Game.LoadActor("actors\molly\molly.actor");
sally = Game.LoadActor("actors\molly\sally.actor");

actor = molly;
actor = sally;

Game.MainObject = actor;
Game.InventoryObject = actor;

// run the "game loop" script
Game.AttachScript("scripts\game_loop.script");

Game.InventoryVisible = true;

// which scene to load?
Game.ChangeScene(Game.StartupScene);


////////////////////////////////////////////////////////////////////////////////

on "LeftClick"
{
  var ActObj = Game.ActiveObject;
  if(ActObj!=null)
  {
    if(Game.SelectedItem != null && Game.SelectedItem!=ActObj)
    {
      var Item = Game.SelectedItem;
      if(ActObj.CanHandleEvent(Item.Name)) ActObj.ApplyEvent(Item.Name);
    }
    else
        ActObj.ApplyEvent("LeftClick");
  }
  else
  {
    Scene.ApplyEvent("LeftClick");
  }
}

on "RightClick"
{
  if (Game.SelectedItem != null){
    Game.SelectedItem = null;
  }
}
////////////////////////////////////////////////////////////////////////////////
on "Keypress"
{
  // on Esc or F1 key
  if(Keyboard.KeyCode==VK_ESCAPE || Keyboard.KeyCode==VK_F1)
  {
    // load and display the main menu window
    WinCaption.Visible = false;
    var WinMainMenu = Game.LoadWindow("interface\system\mainmenu.window");
    WinMainMenu.Center();
    WinMainMenu.GoSystemExclusive();
    Game.UnloadObject(WinMainMenu);
  }
}


////////////////////////////////////////////////////////////////////////////////
on "QuitGame"
{
  // on Alt+F4 (window close)
  // load and display the quit confirmation window
  WinCaption.Visible = false;
  var WinQuit = Game.LoadWindow("interface\system\quit.window");
  WinQuit.Center();
  WinQuit.GoSystemExclusive();

  // and if the user selected Yes
  if(WinQuit.xResult)
  {
    // quit the game
    Game.QuitGame();
  }
  // otherwise just unload the quit window from memory
  else Game.UnloadObject(WinQuit);
}

« Last Edit: October 28, 2008, 04:16:25 AM by Catacomber »
Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: On look, on book, on right click scripts
« Reply #1 on: October 28, 2008, 08:55:51 PM »

Hi Cat,

could you please always specify the chapter you're stuck on. Would help me track your problem down faster. I don't see anywhere in my code on "LookAt" event (LookAt is a custom event tied to
the demo contextual menu but I don't remember using it myself).
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Re: On look, on book, on right click scripts
« Reply #2 on: October 28, 2008, 09:05:11 PM »

Sorry, Metamorphium, I'm working through Chapter 6.  You don't use look at but I was trying to find out some solution to my problem and was reading a different tutorial in the documentation as well.  You only reference handlers "on book" and "on leftclick" and I think "on rightclick".  I could be missing more of the on rightclick code, trying to figure it out but I could use some help.
Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Re: On look, on book, on right click scripts
« Reply #3 on: October 28, 2008, 09:22:38 PM »

I found this "right click" script in a tutorial but it seems like a lot of stuff--is it necessary to go anywhere outside the WME book to do the projects?  This is where I got the "look at" from.

on "RightClick"
{
  // if inventory item selected? deselect it
  if (Game.SelectedItem != null)
  {
    Game.SelectedItem = null;
    return;
  }
 
  var ActObj = Game.ActiveObject;
 
  // is the righ-click menu visible? hide it
  if(WinMenu.Visible == true) WinMenu.Visible = false;
  else if(ActObj!=null)
  {
    // if the clicked object can handle any of the "verbs", display the right-click menu
    if(ActObj.CanHandleEvent("Take") || ActObj.CanHandleEvent("Talk") 
    || ActObj.CanHandleEvent("LookAt"))
    {
      // store the clicked object in a global variable MenuObject
      MenuObject = Game.ActiveObject;
      var Caption = WinMenu.GetWidget("caption");
      Caption.Text = MenuObject.Caption;
 
      // adjust menu's position
      WinMenu.X = Game.MouseX - WinMenu.Width / 2;
      if(WinMenu.X < 0) WinMenu.X = 0;
      if(WinMenu.X+WinMenu.Width>Game.ScreenWidth) 
         WinMenu.X = Game.ScreenWidth-WinMenu.Width;
 
      WinMenu.Y = Game.MouseY - WinMenu.Height / 2;
      if(WinMenu.Y<0) WinMenu.Y = 0;
      if(WinMenu.Y+WinMenu.Height>Game.ScreenHeight) 
          WinMenu.Y = Game.ScreenHeight-WinMenu.Height;
 
      // and show the right-click menu
      WinMenu.Visible = true;
 
      // stop the actor from whatever he was going to do
      actor.Reset();
    }
    else ActObj.ApplyEvent("RightClick");
  }
}


 
« Last Edit: October 28, 2008, 09:24:18 PM by Catacomber »
Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: On look, on book, on right click scripts
« Reply #4 on: October 28, 2008, 09:31:13 PM »

yes. You're on the right track. Basically "LookAt" is something you call custom event. In WME you can create any event you wish and there are a few methods how to work with them.

For example you can make your own event.

Code: WME Script
  1. on "cat"
  2. {
  3.   Game.Msg("I'm a cat");
  4. }
  5.  

then you attach it to some entity, object, Scene whatever.

Let's put it in some scene_init.script for now.

If you want to check if the event is registered, you can call:

Code: WME Script
  1. if (Scene.CanHandleEvent("cat")) Scene.ApplyEvent("cat");
  2.  

So that's how you can easily register a brand new event and how to call it. :)
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Re: On look, on book, on right click scripts
« Reply #5 on: October 28, 2008, 09:34:07 PM »

Lightbulb turning on over cattish ears.  : )

But I still have to get Molly and Sally to exchange the book.  Will go over the chapter again tonight.  Thank you.
Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Re: On look, on book, on right click scripts
« Reply #6 on: October 29, 2008, 02:05:44 AM »

I'm at the end of Chapter 6--

My problem seems to be that the book is stuck in the inventory.  I can't use it once it's there.

I still can't get Molly or Sally to exchange the book and can't see what I'm doing wrong.  Should I have "on book" in there?   I have "on book"  in Molly.script and Sally.script.  Nothing happens when I right click anywhere--is it supposed to?  Everything else is OK--no script errors but this is a real problem.   :-\

« Last Edit: October 29, 2008, 02:42:32 AM by Catacomber »
Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Re: On look, on book, on right click scripts
« Reply #7 on: October 29, 2008, 02:45:05 AM »

SOLVED!!!!  ^^

The problem was in the book script--I thought the script on the book under items and in scenes had to be the same.

 :-*

What a dingcat.  : )  Halfway through--on to Dialogues!!!!!!  Phew!  The good thing is that stuff I had to struggle a little bit to understand before is second nature now--don't even have to think about it.  : ) 
« Last Edit: October 29, 2008, 03:29:11 AM by Catacomber »
Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Re: On look, on book, on right click scripts
« Reply #8 on: October 29, 2008, 03:23:00 AM »

Got through the dialogue section without any problem.  Really nice.  On to Chapter 8!!!!   :)
Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Re: On look, on book, on right click scripts
« Reply #9 on: October 29, 2008, 04:10:40 AM »

Metamorphium, it's better when I find my own mistakes but it's very comforting to know that you're there in case I can't. 
Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  

kypho

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 33
    • View Profile
Re: On look, on book, on right click scripts
« Reply #10 on: October 29, 2008, 02:52:00 PM »

one thing I would like to tell, which meta already told...you can make new items, let's say ironbar* and then put to some entity (npc or item):

on "ironbar"
{
//your code here for example he says something, takes the ironbar, whatever -> makes you get some open passage or item
//(whatever you imagination brings)
}

so you can make code which uses some of your inventory items :)

*this only to make meta's text more understable

-Kypho the beginner
Logged

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Re: On look, on book, on right click scripts
« Reply #11 on: October 29, 2008, 02:58:41 PM »

Thank you, Kypho.  That is something I would use often.   :) :)
Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Re: On look, on book, on right click scripts
« Reply #12 on: October 30, 2008, 03:03:07 AM »

Am following the WME book and am 1/3rd through Chapter 8 - - Starting our first real game -- and -- I'm not having any problems!!!!

 ;D ;D ;D  Hard work and sweat in early chapters paid off as well as help from this forum.  So far, so good.  I can't believe the Dream Scene works perfectly!  It's so cool.  Molly splits out of herself and talks to her alternate identity.  Poor Molly, I know what's coming.  :-\
« Last Edit: October 30, 2008, 03:59:53 AM by Catacomber »
Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  
 

Page created in 0.063 seconds with 21 queries.