Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Helme on Sun 22/11/2009 14:10:22

Title: Use a shorter command for often used chain of commands
Post by: Helme on Sun 22/11/2009 14:10:22
Sorry for the unspecific topic.

I use a specific 'Take/use'-Animation very often in my games. So I often have to copy commands like this in my script:
player.LockView(65);
player.Animate(2, 5, eOnce, eBlock);
player.UnlockView();

I'm sure there's a simple way to make this more easygoing for me. I would like to replace chains of command like these by a shorter command like: player.takeright;
What do I have to do?




Title: Re: Use a shorter command for often used chain of commands
Post by: NsMn on Sun 22/11/2009 14:14:55
The magic word is extender functions. Just declare funktions like this:


function Take(this Character*, int Loop){
   //script
}

Now you can use Character.Take.
Title: Re: Use a shorter command for often used chain of commands
Post by: ThreeOhFour on Sun 22/11/2009 14:18:05
You want to create a custom function like this:

Put this above all the places in the script you are going to use it (ie, at the top of your globalscript):


function takeright()
{
 player.LockView(65);
 player.Animate(2, 5, eOnce, eBlock);
 player.UnlockView();
}


Then, when you want this to happen, you can call it easily:


function oBee_Interact()
{
 player.Say("I will take this bee!");
 takeright;
}


Also, at the top of all your room scripts put: Scratch that, put it in the script header :P


import function takeright();


So you can call it from within your room scripts and not just your global script.

Hope this works and helps :)

Edit: Yeah, and extenders are rad as well :P
Title: Re: Use a shorter command for often used chain of commands
Post by: Helme on Sun 22/11/2009 14:45:20
Thanks for the help.

I'm not sure what the script header exatly is. When I imported this into one room, it worked for this room:
import function takeright();

But it doesn't seem to work If I just put it into the global script.

@Ben: How could you know that you have to take a bee with you in my next game ;)
Title: Re: Use a shorter command for often used chain of commands
Post by: NsMn on Sun 22/11/2009 14:49:33
Script header is the file GlobalScript.ash.
Import the function there and you can use it in every room.
I'm surprised you actually managed to make games without even knowing that  ;)
Title: Re: Use a shorter command for often used chain of commands
Post by: Helme on Sun 22/11/2009 14:54:53
Great! It works!

Quote from: NsMn on Sun 22/11/2009 14:49:33
I'm surprised you actually managed to make games without even knowing that  ;)

I'm surpried that I ask this questions after I completed 4 games  ::)
Title: Re: Use a shorter command for often used chain of commands
Post by: ThreeOhFour on Sun 22/11/2009 14:56:41
Quote from: Helme on Sun 22/11/2009 14:45:20
@Ben: How could you know that you have to take a bee with you in my next game ;)

HAH!

As for being able to make games without knowing what a script header is:

I've never put anything into the script header before in my life.

:)

Good to hear it all works, Helme :)
Title: Re: Use a shorter command for often used chain of commands
Post by: Helme on Sun 22/11/2009 19:50:29
Man... I could have saved so much time for Cold Meat ::)