Simple scripting question regarding opening and closing animation of object...!

Started by KyriakosCH, Fri 24/06/2016 13:49:25

Previous topic - Next topic

KyriakosCH

Hi!

I made a new animation to open an object (a closet), and scripted that in using the setview command. I wanted to ask how i can make it so that the object loops backwards (i know the command for backward animating of a loop) IF you interact with the object when it is already Open :)

I know this is a very basic question, but spending a little time on the dynamic help in AGS i wasn't able to find an easy answer. Tried a bit with IF command but am way too much a novice in scripting currently... :D

(my script lines are just two currently, object(x)setview(y); object(x)animate(a,b); The animation works fine in game, and just need the way to do what i described above :) )
This is the Way - A dark allegory. My Twitter!  My Youtube!

Mandle

There are many ways to do this but the easiest to understand and manage is probably to just set a bool variable: "DoorIsOpen" (or whatever you want to name it), set it initially to "false" (if door is closed at start of game)...(Maybe it's best to do this in Global Variables if you are as new to scripting as you say)...

Then you just do something like:

Code: ags

if (DoorIsOpen==false)
{
 //Animate object forwards
 DoorIsOpen=true;
}
else
{
 //Animate object backwards
 DoorIsOpen=false;
}


And put this code in the function for "Interact door".

(I didn't include the actual code to animate the object, but you know how to do this: It fits in where my comments show)


KyriakosCH

Given the bool being some parameter defined (opencloset etc), and i still do not know how to do that (will soon find out :D ) i did this my own novice scripting way, so if you want to see something funny...:

(the interact line is just a relic, the other object is named Closet, and uses view 3, the sequence to open ;) )



At least it already works!!!
This is the Way - A dark allegory. My Twitter!  My Youtube!

Mandle

Quote from: KyriakosCH on Fri 24/06/2016 14:59:53
Given the bool being some parameter defined (opencloset etc), and i still do not know how to do that (will soon find out :D )

Open the Global Variables window in the main menu.

Right-click on the menu.

Create your variable.


Mandle

No worries! I had a look at your code: This is also a viable solution. Good on you for working it out!

Khris

As was pointed out there are many ways to do this, and my preferred one is to use the available information about the game's state to decide what's going to happen, in this case the frame of the object.

Which means one can do this:
Code: ags
function Closet_Interact() {
  if (Closet.Frame == 0) {
    // closet is closed
    ...
  }
  else {
    // closet is open
  }
}

This will even work if opening the closet for the first time is what sets the view, because Object.Frame returns is 0 if no view was set.

KyriakosCH

^Thanks! :D

Helps to have more elegant options, despite the 'just write the same commands 1000 times' working too :D
This is the Way - A dark allegory. My Twitter!  My Youtube!

SMF spam blocked by CleanTalk