Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Creator on Thu 20/08/2009 18:55:55

Title: Enabling gravity on characters (SOLVED)
Post by: Creator on Thu 20/08/2009 18:55:55
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?
Title: Re: Enabling gravity on characters.
Post by: Matti on Thu 20/08/2009 19:25:59

function Gravity(int ground, int pixelFall, Character*char)
{  
 if (gravOn == true) {
   if (char.y < ground) {
     char.y += pixelFall;
   }
 }
}
Title: Re: Enabling gravity on characters.
Post by: Mazoliin on Thu 20/08/2009 19:58:48
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);
Title: Re: Enabling gravity on characters (SOLVED)
Post by: Creator on Thu 20/08/2009 20:37:44
Thank you both for that.
Using Mazoliin's method. Seems more logical to make it a character function.