I've made a function which enables gravity depending on a boolean (which is a global variable). This is the code:
//Boolean is called gravOn
function Gravity(int ground, int pixelFall) //ground is where the floor meets the wall. pixelFall is how many pixels the character will drop
{
if (gravOn == true) {
if (player.y < ground) {
player.y += pixelFall;
}
}
}
What I want to know is how to set it for just the one character and setting which character in the function parameters.
EG.
Gravity(player, 313, 3);
How would I set it up so I can choose a character based on their script-o name?
function Gravity(int ground, int pixelFall, Character*char)
{
if (gravOn == true) {
if (char.y < ground) {
char.y += pixelFall;
}
}
}
Or use extender functions (http://www.adventuregamestudio.co.uk/manual/ExtenderFunctions.htm).
function Gravity(this Character*, int ground, int pixelFall)
{
if (gravOn == true) {
if (this.y < ground) {
this.y += pixelFall;
}
}
}
Then you can write
player.Gravity(313, 3);
cEgo.Gravity(313, 3);
Thank you both for that.
Using Mazoliin's method. Seems more logical to make it a character function.