Need Help Scripting Door

Started by BilboFrogHermit, Mon 05/10/2009 21:44:26

Previous topic - Next topic

BilboFrogHermit

I'm a total noobie at this so bear with me... I need to know how to script a simple door that opens and closes when my character interacts with it.  I have sprites loaded and a view set up.  I have made the door a character and set up it as an object.  How do I make the character walk up and open or close the door?

I've looked on the vids and tutorials but can't find anything specifically about this.  If I'm missing a resource, lemme know.

discordance

You don't really need to make the door a character. An object should work just fine.

Something like this is all you need:

Code: ags

//in the interaction function for the door
player.Walk(x,y,eBlock);     //whatever the coordinates you want the player to walk to
oDoor.SetView(1);     //or whatever the correct view is
oDoor.Animate(0,5,eBlock);   //first number is the loop to run; second number is the frame delay


That should be all you need.

Crimson Wizard

Quote from: BilboFrogHermit on Mon 05/10/2009 21:44:26I have made the door a character and set up it as an object.
I am sorry, this phrase sounds a bit confusing to me; are you saying you made a door AND a character, or that you made door be represented by a "character"-class object?

Regardless,
Quote from: BilboFrogHermit on Mon 05/10/2009 21:44:26
How do I make the character walk up and open or close the door?
Select the door in the room. You should notice its properties appeared in the properties table (right-bottom of the AGS window).
Click on "thunderbolt" icon (yellow thingie). An "Events" page should open. Find "Interact with" line, select it and click on "..." button (appears to the right).
A function is created for player interaction with door. You'll be automatically moved to room script.

There you should type corresponding commands, depending on what you need exactly to happen.


EDIT: Looks like discordance already made a sample script above.

Khris

You might also want to create a room variable: at the top of the room script, outside any function, add
Code: ags
bool door_open;

This adds a boolean var/flag which can hold true or false and is local to the room.
Then you can use a script like this:
Code: ags
// inside the interact with door function

  player.Walk(x, y, eBlock);
  player.FaceLocation(player.x, player.y - 1, eBlock);  // make player face up
  if (door_open) {
    oDoor.Animate(...);   // close door by playing the opening loop backwards
    RemoveWalkableArea(x);  // make floor near door unwalkable
    door_open = false;  // update status variable
  }
  else {
    oDoor.Animate(...);   // open door by playing the opening loop
    RestoreWalkableArea(x);  // make floor near door walkable
    door_open = true;  // update status variable
  }


SMF spam blocked by CleanTalk