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?
The magic word is extender functions. Just declare funktions like this:
function Take(this Character*, int Loop){
//script
}
Now you can use Character.Take.
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
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 ;)
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 ;)
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 ::)
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 :)
Man... I could have saved so much time for Cold Meat ::)