OOAGS

Started by Captain Mostly, Mon 26/05/2003 14:33:17

Previous topic - Next topic

Captain Mostly

Is it possible to define Objects (in the sence of C++ objects, containing functions etc) within AGS...

I recognise that AGS script is kind of stripped down C++, but I'm not sure HOW stripped down, so I thought I'd ask.

The project I'm working on will be a LOT easyer if it IS possible, although I'm sure I'll be able to work round it if it isn't... I think...


If it IS possible, then how is it done?
I'm guessing (as I've never ever seen one) that there's no way to include .h files for objects, so the .h code for each object would have to be seperated somehow in the main header, and I don't know how I'd do that... Also, I'm not sure I'd know how to differentiate between objects in the main code section (which seems equivalent to a central .cpp file to me) so I'd need to know that as well...

as I write this it seems less and less likly that anyone will know what I mean, and even LESS likly that it's possible, but it's worth asking eh?

Captain Mostly

and before someone forum quotes rules at me again "OOAGS" IS a descriptive thread heading, as OO is a pretty standard acronym for "Object Oriented", which is the technical area I'm asking about.



anyway, does anyone know if the Character Control System could be used to perhaps simulate an object oriented aproach?

Pumaman

The AGS script is not object oriented, so no you cannot have functions within classes, and so forth.

I actually think that it probably should have been an OO design, but it's too late to change that now.

The Script Header is like a  .h  file that automatically gets included into all scripts.

Captain Mostly

thakyou!

how speedily you answer things!



now I'll have to try and be REAL clever...   :-\

Pumaman

If you tell us what you're trying to do, we might be able to come up with an easy solution for it.

Scorpiorus

QuoteThe project I'm working on will be a LOT easyer if it IS possible, although I'm sure I'll be able to work round it if it isn't... I think...
Yes, AGS doesn't support OOP but C++ does. CJ had made a great feature allowing the support of external DLLs. What you could do (if you really need to use OOP) is to write your system as an external dll and then just import it into ags as a plugin. This way you are free to use any tools that C allows. You can even do not use the script at all but C only; although IMHO it is much more better to combine them by scripting the most of things in AGS itself and writing sub-engines (sub-systems) as an external library and providing the interface functions as well. I had tried and really liked that.
Yes, the dll is not cross-platform so I am not sure you are able to write a linux version of your game. At least for now because Linux has no dlls but... I am sure it has something similar and I hope it will be possible to compile a linux-style binary without problems as well provided the written code is portable enough. :P


Quoteand before someone forum quotes rules at me again "OOAGS" IS a descriptive thread heading, as OO is a pretty standard acronym for "Object Oriented", which is the technical area I'm asking about.
That's ok but I think another reason why threads should be named descriptively is that someone else may look for the thread using the searching function and it just helps them to find one much quickly. :)


Quoteanyway, does anyone know if the Character Control System could be used to perhaps simulate an object oriented aproach?
Do you mean the plugin? If you do, when it depends on what exactly you want to achieve. You want to use OOP so I am guessing it maybe some system of objects processing simultaneously and interacting with each other by means of sending messages. Just a guess... :P

-Cheers

Captain Mostly

my MAIN problem is that I'm making a game based around a noughts and crosses style grid (3x3) and I need to be able to get AGS to check what's in next-door sqares (for example, if I wanted to work out if there was a row of crosses)

I'm sure there's a really clever and simple way of doing this, I've just not worked it out yet...

Scorpiorus

#7
Then you could use a 2D array (N x M). Input parameter is a cell position (x,y). To work out if there was a row of crosses you have to check horizontal, vertical and two diagonal rows to consist of defined amount of crosses. Process calculations from the input position in these 4 x 2 = 8 directions (each row could have two directions to go). Suppose the player has placed a cross at position (x,y). (the grid dimensions: 1..N, 1..M btw)

+--------> X
|
|
|
|
|
Y

Now checking the horizontal row:
if the element in the right square (x+1,y) is a cross then increase counter and goto element (x+2, y) and check if it's a cross again;

else check for opposite direction:
if the element in the left square (x-1,y) is a cross then increase counter and goto element (x-2, y) and check if it's a cross again; etc... x-3, x-4


if counter >= 3 for example then there is a line of crosses.

once you have checked horizontal row the same for vertical and diagonal:

vertical:
=========
if the element in the lower square (x,y+1) is a cross then increase counter and goto element (x, y+2) and check if it's a cross again; etc... y+3, y+4

else check for opposite direction:
if the element in the upper square (x,y-1) is a cross then increase counter and goto element (x, y-2) and check if it's a cross again; etc.. y-1, y-2

if counter >= 3 for example then there is a line of crosses.

diagonal #1:
============

if the element in the lower-right square (x+1,y+1) is a cross then increase counter and goto element (x+2, y+2) and check if it's a cross again; etc... (x+3, y+3), (x+4, y+4)...

else check for opposite direction:
if the element in the upper-left square (x-1,y-1) is a cross then increase counter and goto element (x-2, y-2) and check if it's a cross again; etc...

if counter >= 3 for example then there is a line of crosses.

diagonal #2:
============

if the element in the upper-right square (x+1,y-1) is a cross then increase counter and goto element (x+2, y-2) and check if it's a cross again; etc... (x+3, y-3), (x+4, y-4)...

else check for opposite direction:
if the element in the lower-left square (x-1,y+1) is a cross then increase counter and goto element (x-2, y+2) and check if it's a cross again; etc...

if counter >= 3 for example then there is a line of crosses.


you could make one function processing all 8 directions: GetDirectionNum(x, y, dx, dy);
so it would check this way (x+dx, y+dy), (x+2*dx, y+2*dy), etc... (dx and dy are either 0, 1 or -1). the function could return a counter value.

GetDirectionNum(x, y,  1,  0);
GetDirectionNum(x, y, -1,  0);

GetDirectionNum(x, y,  0,  1);
GetDirectionNum(x, y,  0, -1);

GetDirectionNum(x, y,  1,  1);
GetDirectionNum(x, y, -1, -1);

GetDirectionNum(x, y, -1,  1);
GetDirectionNum(x, y,  1, -1);


Now making a row function which helps combine the opposite directions (so we have a row):

int GetRowNum(x, y, dx, dy) {
return  GetDirectionNum(x, y,   dx,   dy) + GetDirectionNum(x, y,  -dx,  -dy);
}

GetRowNum(x, y, 1,  1);
GetRowNum(x, y, 0,  1);
GetRowNum(x, y, 1,  0);
GetRowNum(x, y, 1, -1);


so something like this :P

PS There is a more general algorithm working with any dimension array which just goes through all possible directions. But for 2d it's enough I think.

-Cheers

Captain Mostly

cool. Thanks for the code trickery!


BUT:
I feel like something of a dope, because I'm not sure I know how I'd explain a grid to AGS...
How do I set up a 2D array in the script (so far I've been planning on using variables i.e. Global Int 1, Global Int 2 etc.)

Will it be possible to attach a variable to a coordinate (so that X1,Y1 referenced Global Int 2) or will I have to do something more complicated... I'm not sure how to assert that a specific position contains a cross...


This is massivly helpful so far thankyou!!!
Just these last little bits and I OUGHT to be able to work the rest out!!!!

Scorpiorus

#9
QuoteI feel like something of a dope, because I'm not sure I know how I'd explain a grid to AGS...
How do I set up a 2D array in the script (so far I've been planning on using variables i.e. Global Int 1, Global Int 2 etc.)

well, you could make a 2d array this way:

//global script

//the array is sezo-based: [0...N),  [0...M)

//array size (N,M)
#define N 3
#define M 3

//array length must always be N*M !!!
#define ARRAY_LENGTH 9

int Array[ARRAY_LENGTH];

//array control functions:
function SetDim(int i, int j, int value) {
 if (i>=0 && i<M && j>=0 && j<N) Array[i*M+j] = value;
 else {Display("Access error: Out of bounds!"); QuiteGame(0);}
}


function GetDim(int i, int j) {
 if (i>=0 && i<M && j>=0 && j<N) return Array[i*M+j];
 else {Display("Access error: Out of bounds!"); QuiteGame(0);}
}

//script header:

import function SetDim(int i, int j, int value);
import function GetDim(int i, int j);



so you have two functions to set/retrieve data from it:

SetDim(1,1, 5); // <====> Array[1][1] = 5;

value = GetDim(2,1); // <====> value = Array[2][1];

QuoteWill it be possible to attach a variable to a coordinate (so that X1,Y1 referenced Global Int 2) or will I have to do something more complicated... I'm not sure how to assert that a specific position contains a cross...
That's the same as the example above as the GlobalInts is actually an array. But I would suggest you to use Array[]'s functions and leave the GlobalInts for something else.
So to store a cross at position (2,2) (lower-right corner):
SetDim(2,2, 1); //where 1 represents a cross for ex.

QuoteThis is massivly helpful so far thankyou!!!
Just these last little bits and I OUGHT to be able to work the rest out!!!!
You are welcome.  In any case if you will need any help just post here. ;)

-Cheers

Scorpiorus

I have re-read the thread and decided to write a test game so here is a template: download

hope it will be useful

-Cheers

Captain Mostly

wow!

Thanks!!!

Captain Mostly

wait a sec... what's an agt file (am I being REALLY stupid here? I fear I may be a little out of my depth!!!)

Gilbert

#13
It's an AGS template file, introduced in V2.5.... errr... I forgot it, using it, you can start a new game with predefined GUIs, settings, etc.

P.S. When will RLBAT2 be done?

Scorpiorus

Quotewait a sec... what's an agt file (am I being REALLY stupid here? I fear I may be a little out of my depth!!!)
opps, sorry, I forgot there is no AGS 2.55 officially released. :P

-Cheers


SMF spam blocked by CleanTalk