how to do "blah.blah" functions

Started by Theme, Wed 19/10/2005 20:32:01

Previous topic - Next topic

Theme

How can I do something like
Myclass.myfunction(x,y) in ags?
???

o/

magintz

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.
When I was a little kid we had a sand box. It was a quicksand box. I was an only child... eventually.

Theme

Not like that
I want to do like

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

}


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

o/

Scummbuddy

#3
Im confused. There are already walk functions embedded in ags.
-------------------------
[Walk code was originally here, taken directly from the manual]
- Oh great, I'm stuck in colonial times, tentacles are taking over the world, and now the toilets backing up.
- No, I mean it's really STUCK. Like adventure-game stuck.
-Hoagie from DOTT

Theme

#4
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/

Scummbuddy

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.
- Oh great, I'm stuck in colonial times, tentacles are taking over the world, and now the toilets backing up.
- No, I mean it's really STUCK. Like adventure-game stuck.
-Hoagie from DOTT

strazer

Code: ags

// script header

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


Code: ags

// main script

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

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


Code: ags

  // some script

  theblah.dostuff(2);


or

Code: ags

// script header

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



Code: ags

// main script

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


Code: ags

  // some script

  Blah.dostuff(2);

Theme

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/

strazer

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();

Theme

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

Code: ags
// 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/

strazer

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?

Theme

woo thanks strazer
it was silly stuff I did  ::)

thanks for your patience  ;)
luv ya man!

o/

strazer


SMF spam blocked by CleanTalk