Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Theme on Wed 19/10/2005 20:32:01

Title: how to do "blah.blah" functions
Post by: Theme on Wed 19/10/2005 20:32:01
How can I do something like
Myclass.myfunction(x,y) in ags?
???

o/
Title: Re: hot to do .functions
Post by: magintz on Wed 19/10/2005 20:38:48
to create a function in teh global scripts just type the following

function myfunction (parameters)
{
// what you want the function to do
}

If you go into the AGS help and search for functions it will explain everything.
Title: Re: hot to do .functions
Post by: Theme on Wed 19/10/2005 20:49:17
Not like that
I want to do like

int Walkto
{
 
  int goto(x,y)
  {
   ...
  }

}


so I can use Walkto.goto(x,y)

o/
Title: Re: hot to do .functions
Post by: Scummbuddy on Wed 19/10/2005 21:09:06
Im confused. There are already walk functions embedded in ags.
-------------------------
[Walk code was originally here, taken directly from the manual]
Title: Re: hot to do .functions
Post by: Theme on Wed 19/10/2005 21:13:21
that was just a exemple  :-\

I have another question.
How do I import variable to modules?
I tryed to import but it gives me a unresolved import error

o/
Title: Re: hot to do .functions
Post by: Scummbuddy on Wed 19/10/2005 21:23:58
well thanks for clarifying more on your question. (sarcasim)

now, im guessing you want to be able to create your own object-oriented script... which I don't believe you can do. Only CJ can create the keywords, but you can use arrays almost like your own object oriented code.
-----------
Arrays
data_type name [ size ];
Arrays allow you to easily create several variables of the same type. For example, suppose you wanted to store a health variable for all the different characters in the game. One way would be to declare several different variables like this:

int egoHealth;
int badGuyHealth;
int swordsmanHealth;

but that quickly gets messy and difficult to keep up to date, since you need to use different script code to update each one. So instead, you can do this:
int health[50];

This example declares 50 int variables, all called health.
You access each seperate variable via its index (the number in the brackets). Indexes start from 0, so in this case the health array can be accessed by indexes 0 to 49. If you attempt to access an invalid index, your game will exit with an error.
Here's an example of using the array:

  health[3] = 50;
  health[4] = 100;
  health[player.ID] = 10;

this sets Health 3 to 50, Health 4 to 100, and the Health index that corresponds to the player character's ID number to 10.
Title: Re: hot to do .functions
Post by: strazer on Wed 19/10/2005 21:25:40

// script header

struct Blah {
  import function dostuff(int parameter); // import member function
};



// main script

function Blah::dostuff(int parameter) { // define member function
  //...the code
}

Blah theblah; // create instance of struct defined in script header



  // some script

  theblah.dostuff(2);


or


// script header

struct Blah {
  import static function dostuff(int parameter); // import STATIC member function
};




// main script

static function Blah::dostuff(int parameter) { // define STATIC member function
  //...the code
}



  // some script

  Blah.dostuff(2);
Title: Re: how to do "blah.blah" functions
Post by: Theme on Wed 19/10/2005 22:00:00
yay thanks
but Its not working here  :'(

// main global script file
function WalkToInteraction::Go (int x, int y)
{
   player.Walk(x, y, eNoBlock, eWalkableAreas);
   going = 1;
}

function WalkToInteraction::Stoped()
{
}


// Main header script
struct WalkToInteraction { 
      import function Go(int x, int y);
      import function Stoped(); 
  };



When I try to run I get the fowlling error:
Error: Unable to create local script: Run time error:  unresolved import 'walktointeraction'


o/
Title: Re: how to do "blah.blah" functions
Post by: strazer on Wed 19/10/2005 22:27:32
What's the code where you call the functions?

Remember, if you want to be able to do
  WalkToInteraction.Stoped();
you have to use STATIC members functions, from the second example.

The way you have it now, you have to create an instance of the struct first that you can call the functions on:

  WalkToInteraction thething;
  //...
  thething.Stoped();
Title: Re: how to do "blah.blah" functions
Post by: Theme on Wed 19/10/2005 22:36:02
I did it like this in a module but still getting the unresolved import error
and try to run the game without using the functions

// Main script for module 'WalkToInteraction'

static function WalkToInteraction::Go (int x, int y)
{
     
  player.Walk(x, y, eNoBlock, eWalkableAreas); 


}

static function WalkToInteraction::Stoped()
{



}


// Script header for module 'WalkToInteraction'

struct WalkToInteraction {
 
import static function Go(int x, int y);
import static function Stoped();
 
  };




o/
Title: Re: how to do "blah.blah" functions
Post by: strazer on Wed 19/10/2005 22:40:44
Compiles fine here...
You have put the script header code in the seperate header script and not appended it to the end of the main script, right?
Title: Re: how to do "blah.blah" functions
Post by: Theme on Wed 19/10/2005 23:00:13
woo thanks strazer
it was silly stuff I did  ::)

thanks for your patience  ;)
luv ya man!

o/
Title: Re: how to do "blah.blah" functions
Post by: strazer on Wed 19/10/2005 23:21:41
Glad I could help. :)