Please login or register.

Login with username, password and session length
Advanced search  

News:

Forum rules - please read before posting, it can save you a lot of time.

Author Topic: How do you script a key to open a door?  (Read 7374 times)

0 Members and 1 Guest are viewing this topic.

Lord Scrotor

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 7
  • I'm NOT a llama!
    • View Profile
How do you script a key to open a door?
« on: April 14, 2003, 04:54:59 PM »

Hi, I'm fairly new to this program.  I've gone through all the tutorials.  I can't seem to find any info on how to script for a key and door scenario.  Anyone have any idea how to set then interaction up.  Basically make it check that you are using the key on the door, etc.
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re:How do you script a key to open a door?
« Reply #1 on: April 15, 2003, 08:17:33 AM »

It depends on how your project is set up. But if you used the WME demo or the standard template to start your project (and you probably did :)) then it works like this:

When you select an inventory item (clicking it in the inventory), the mouse pointer will represent the item. Now, when you click the item on another interactive object within the scene, an "event" is applied to that object. And the name of the event equals to the name of your item.

So, in your case, if the name of the item is "key", all you need to do is to add the following event handler to the door script:

Code: [Select]
on "key"
{
   actor.Talk("I'm using a key on the door!");
}
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Lord Scrotor

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 7
  • I'm NOT a llama!
    • View Profile
Re:How do you script a key to open a door?
« Reply #2 on: April 15, 2003, 04:38:26 PM »

Cool, How do I make sure that the program remembers to keep the do unlocked?
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re:How do you script a key to open a door?
« Reply #3 on: April 15, 2003, 06:04:51 PM »

Just create a global variable and assign is a true value when the player uses the key on the door.

Code: [Select]
global DoorUnlocked;

...

on "key"
{
  if(DoorUnlocked) actor.Talk("I already unlocked the door!");
  else DoorUnlocked = true;
}
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Adventureforall

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 26
  • I'm a llama!
    • View Profile
Re:How do you script a key to open a door?
« Reply #4 on: June 06, 2003, 08:14:16 PM »

I'm trying to use the
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re:How do you script a key to open a door?
« Reply #5 on: June 06, 2003, 08:33:39 PM »

This should work:

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

global DoorUnLocked=false;


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

on "look"
{
  GoToObject ();
  actor.Talk ("It's a door");
  actor.Talk ("It's leading to my garden and my car");
}



////////////////////////////////////////////////////////////////////////////////
on "take"
{
  GoToObject ();
  actor.Talk ("i can't unlock the door with my bare hands");
}

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


on "carkeys"
{
  GoToObject ();
  actor.Talk ("I can't open the door with my car keys");
}

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

on "housekeys"
{
  if(DoorUnLocked) actor.Talk("i will unlock the door");
  else DoorUnLocked=true;
}
////////////////////////////////////////////////////////////////////////////
function GoToObject()
{
  actor.GoTo(234, 601);
  actor.TurnTo(DI_LEFT);
}

There are two problems in your code:
1) you are declaring the "DoorUnLocked" twice; that's not allowed
2) your variable is called DoorUnLocked (with a capital L), but in your code, you are referencing a variable "else DoorUnlocked=true;" (with a lower case L); WME script is case-sensitive, you must preserve the correct case in variable names
« Last Edit: June 06, 2003, 08:34:12 PM by Mnemonic »
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Adventureforall

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 26
  • I'm a llama!
    • View Profile
Re:How do you script a key to open a door?
« Reply #6 on: June 06, 2003, 08:42:33 PM »

Hey Thanx, It look likes its working, now a go to try, to finished te script, if every things works a let you now.
Logged

Adventureforall

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 26
  • I'm a llama!
    • View Profile
Re:How do you script a key to open a door?
« Reply #7 on: June 06, 2003, 08:59:22 PM »

Now i'm trying the next thing : If door is lock say "I will unlock the door" set DoorUnLock to true, if door is unlock (true) say "The door is already unlocked".

so i changed the script above a little bit
on "housekeys"
{
  if(DoorUnLocked = false) actor.Talk("i will unlock the door");
  global DoorUnLocked=true;

  else;
  actor.Talk("The door is already open");
}

Does anyone know a internet site where i can learn a lot of scripting, in the MS-Dos yeas, i used to write complete text adeventures games in Basic, but this scripting is a little bit diverence.
Logged

odnorf

  • w00t?
  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 7
  • Offline Offline
  • Gender: Male
  • Posts: 1456
  • Lamp dog!
    • View Profile
Re:How do you script a key to open a door?
« Reply #8 on: June 06, 2003, 10:02:42 PM »

Hm... the script you are using isn't correct. It should be

Code: [Select]
on "housekeys"
{
  if(DoorUnlocked) actor.Talk("The door is already open");
  if(!DoorUnLocked) {
     actor.Talk("I will unlock the door");
     DoorUnlocked = true;
  }
}

Quote
Does anyone know a internet site where i can learn a lot of scripting, in the MS-Dos yeas, i used to write complete text adeventures games in Basic, but this scripting is a little bit diverence.

I don't but if you do a search for c, c++, php, javascript examples and tutorials you may find something.
« Last Edit: June 06, 2003, 10:05:09 PM by odnorf »
Logged
fl*p

Adventureforall

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 26
  • I'm a llama!
    • View Profile
Re:How do you script a key to open a door?
« Reply #9 on: June 07, 2003, 06:18:30 AM »

hey thanx.
Logged
 

Page created in 0.189 seconds with 19 queries.