Open and Close Door object animation

Started by , Wed 02/03/2005 21:59:15

Previous topic - Next topic

DingDong

NOW I am having the problem of getting the door to close again. I got the door to open easily using no manual scripting just the drop down menus in the interact with object window. So when the character clicks on the door, it opens. But I want the player to have the option of closing it too! Someone please help me with this - this is the first thing I have really been stumped on!

I have object 0 (named "door" which is the closed door sprite), over a doorway in my very first room. You click on it, it runs my 8th loop, in view 2, and opens up (just 3 simple frames - closed, halfway open, all the way open). Now how do I make it so that when you click on it in the open position, it will close? I've searched high and low in the manual - which is terrible by the way about "getting to xxx later" and then never does; and searched the message boards but cannot find a solution that will work for me.

If I need to type script for the open and close interaction and animation, can someone give me some details on what to add to the script portions of the Room Script and the Interact with Object Script? Again, it's object 0 (the closed door sprite), View 2, Loop 8 (3 frame animation).

Thanks in advance.

strazer

Using the interaction editor:

Conditional - If a variable is set to a certain value (0)
  (Opening door animation)
  Game - Set variable value (1)
  Stop running more commands
Conditional - If a variable is set to a certain value (1)
  (Closing door animation)
  Game - Set variable value (0)

DingDong

Ok, I put that stuff in the interact with object editor for the door, but it just repeats the door opening animation when I click on the already open door. I think I set everything correctly, if I didn't I'm not sure what went wrong. Do I need to have a close door animation or can I run the opening animation backwards with AnimateObjectEx?

Is there anyone who can translate the instructions above into a script I can just edit and copy into my game? If not, can someone explain to me the basic steps of setting this "simple" interaction up?

strazer

Quote
or can I run the opening animation backwards with AnimateObjectEx?

Exactly.
Choose an unused GlobalInt between 0 and 499, then:

Code: ags

  if (GetGlobalInt(28) == 0) { // if the Globalint is 0 (the default)
    // open door:
    SetObjectView(0, 2);
    AnimateObject(0, 8, 0, 0); // run animation forwards
    SetGlobalInt(28, 1); // set GlobalInt to 1 so the door will be closed on next interaction
  }
  else { // if GlobalInt is not 0, i.e. 1
    // close door:
    AnimateObjectEx(0, 8, 0, 0, 1, 0); // run animation backwards
    SetGlobalInt(28, 0); // reset GlobalInt to 0 so door will be openend next time
  }

DingDong

Thanks so much! That worked. All I did was cut and paste it into my script (except I changed the speed from 0 to 10 to make the animation run slower) and it's going good. Now, I'm going to study it so I can figure out what is going on and understand it. This was the only thing stumping me so far...I've got 10 rooms, talking, interaction of objects, inventory, my own characters, scaling, lighting, strings, movies, sounds, points and a lot of other stuff down but I could NOT figure out how to open and close a door!  :D

Again, thanks!


SMF spam blocked by CleanTalk