Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Lewis on Fri 25/11/2016 11:45:49

Title: Defining 'interact animation' function to call easily from various scripts
Post by: Lewis on Fri 25/11/2016 11:45:49
Hi folks. Returning to AGS after a long hiatus and I appear to have forgotten how to do a really simple thing. A whole morning of searching and experimenting has yielded nothing.

I want to be able to easily call an 'interact' animation from room scripts and dialogs. From memory, I needed to define a new function in the global script then call it from the room script. From reading, it seemed I needed to import the function in the header script too.

So I did this in the global script:

Code (ags) Select
function interact_faye_down()
{
    player.ChangeView(6);
    player.Animate(0, 0, eOnce, eBlock, eForwards);
    player.Animate(0, 0, eOnce, eBlock, eBackwards);
    player.ChangeView(4);
}

function interact_faye_left()
{
    player.ChangeView(6);
    player.Animate(1, 0, eOnce, eBlock, eForwards);
    player.Animate(1, 0, eOnce, eBlock, eBackwards);
    player.ChangeView(4);
}

function interact_faye_right()
{
    player.ChangeView(6);
    player.Animate(2, 0, eOnce, eBlock, eForwards);
    player.Animate(2, 0, eOnce, eBlock, eBackwards);
    player.ChangeView(4);
}

function interact_faye_up()
{
    player.ChangeView(6);
    player.Animate(3, 0, eOnce, eBlock, eForwards);
    player.Animate(3, 0, eOnce, eBlock, eBackwards);
    player.ChangeView(4);
}


(Actually, to start with I tried to create a function with a definable string of up/down/left/right and used if/else conditions, but this didn't seem to work, so I tried breaking it down like this to see if I had any more joy.)

Then, in the header script, I've got:

Code (ags) Select
import interact_faye_down;
import interact_faye_left;
import interact_faye_right;
import interact_faye_up;


But I'm getting the following error whenever I try to compile:

expected variable or function after import, not 'interact_faye_down'

Banging my head against the wall because I've done this in two previous games, as second nature, but years ago. Any help desperately appreciated. Thanks!
Title: Re: Defining 'interact animation' function to call easily from various scripts
Post by: Crimson Wizard on Fri 25/11/2016 12:04:37
You must define the full declaration of imported symbol, or other scripts would not know what is this and how to use it.

Code (ags) Select

import function interact_faye_down();
import function interact_faye_left();
import function interact_faye_right();
import function interact_faye_up();
Title: Re: Defining 'interact animation' function to call easily from various scripts
Post by: Lewis on Fri 25/11/2016 12:12:30
*slaps forehead* -- knew it would be super simple.

Thanks!
Title: Re: Defining 'interact animation' function to call easily from various scripts
Post by: Khris on Fri 25/11/2016 12:32:25
Regarding using a single function:
//header
enum Loop {
  eLoopDown, // numbering starts at 0
  eLoopLeft,
  eLoopRight,
  eLoopUp
};
import function interact_faye(Loop loop);

//script
function interact_faye(Loop loop)
{
    player.LockView(FAYEINTERACT);
    player.Animate(loop, 0, eOnce, eBlock, eForwards);
    player.Animate(loop, 0, eOnce, eBlock, eBackwards);
    player.UnlockView();
}