RunAGSCommand command suggestion

Started by Spyros, Wed 12/11/2003 20:21:00

Previous topic - Next topic

Spyros

Would it be possible?
Something like
RunAGSCommand ( AnimateCharacter(2,2,0,0) );
that would execute the AnimateCharacter(2,2,0,0) command.

Pumaman

Why would you use that rather than just doing

AnimateCharacter(2,2,0,0) ;

?

Spyros

Cos I want to run a command that will be sent by a textbox GUI (I type a command and it 's executed). Remember the Debuging panel ?

RickJ

I would also find this useful.  Things like my animatin engine and Scorp's character control system (a script version of it) would greatly benefit.  


Rui 'Trovatore' Pires

I think it'd be perfect - it might even allow someone to make an AGS tutorial where the player can actually create something, or a very simple game maker, with little coding. I support it.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Pumaman

Ah sorry, I see what you mean.

There is currently no script parser in the engine, which is why that debugging feature was never added. I suppose a basic parser could be added to allow you to run simple one-line commands (no "if" statements or anything), since parsing a single command is a fairly easy job.

Scorpiorus

#6
It would be very handy. But what I really want is to be able to call any user defined function as well. :P Is it possible (not too much work)?

Example:

function my_func(int a, int b, int c, int gi) {

if (a<1) {
a = b + c;
a+=5;
} else a = 1;

SetGlobalInt(gi, a);
}

then...

ParseAndRun("my_func(a, b, c, gi);");

Some time ago RickJ and me were discussing a some sort of a simulation of multithread script system (like animation engine or ccs plugin).

RickJ: Do you remember those aeAdd(), aeDivide() that were introduced in the AI specification file. Such a function would solve the problem of calculating character's behavior. :P

~Cheers


After

#7
Hm. Well as long as others are asking, I also thought an eval(string command) (as JScript would put it) would be nice.

Of course it is possible to build your own inside AGS (up to a point), but it would be something of a coding abomination based on "if(){}else if(){}else if(){}else ... " and a whole heap of string manipulation (or a custom input language/method).
That would probably be good enough for less than 20 functions.

I was thinking about function pointers too at one point, but I'm not sure they'd be worth it.

Pumaman

Quote from: Scorpiorus on Thu 13/11/2003 00:17:09
It would be very handy. But what I really want is to be able to call any user defined function as well. :P Is it possible (not too much work)?


Well, bearing in mind the non-reentrant nature of the script system, it could be done - but only from a special debug hotkey in the engine, probably not from a script command itself.

I'll give it some thought.

Scorpiorus

Ah, it's a pity. I was hopping we can link an AGS user script function with the command defined in the instructions list:

I use an 'ae' prefix (animation engine) to distinguish the functions that form the instruction list.

struct TInstructionList {
...
int command;            //command name
int p1,p2,p3; //integer type parameters for the command
char string_param[200]; //one string type parameter for the command
...

};

TInstructionList instructions[MAX_INSTR];


int bp=0; //instruction pointer at a build time

function aeCall(string name) {

 instructions[bp].command = CALL;  //set the instruction command
 instructions[bp].string_param = name; //StrCopy
 
 bp++;

}


function on_game_start() {

//set up a new instruction list:

AE_CreateInstructionList(NAME);

aeMoveCharacter(...)
aeAnimateCharacter(...);
...
aeCall("myfunc(3,5,6);");

AE_End();

}


int ip=0; //instruction pointer

repeatedly execute:


if (instructions[ip].command == CALL) ParseAndRun(instructions[ip].string_param);
if (instructions[ip].command == ANIM) AnimateCharacter(instructions[ip].p1, .....);
if ...

ip++;





Writing a post I've found a kind of workaround: :)

#define LINK if (StrComp(str,
#define TO )==0)

#define PARAM1 p1
#define PARAM2 p1, p2
#define PARAM3 p1, p2, p3

// now registering the functions in the special function:

function RegisteredFunc(string str, int p1, int p2, int p3) {

LINK "myfunc1" TO my_func1(PARAM1);
LINK "myfunc2" TO my_func2(PARAM2);
LINK "myfunc3" TO my_func3(PARAM3);

}

repeatedly execute:


if (instructions[ip].command == CALL) RegisteredFunc(instructions[ip].string_param, p1,p2,p3)

ip++;



Btw, how hard would it be to implement the ability to pass some parameters for the macroses?

#define RegisterFunction(name) if (StrComp(name, str)==0)

in the script:

RegisterFunction("myfunc") myfunc(); :P


~Cheers

Pumaman

Macros with parameters is a possibility, but I don't know that there has been a level of interest to merit the work it would take to implement just yet :)

Paper Carnival

ah, u mean something like ExecuteString(string);... Yup, that would be very helpful

SMF spam blocked by CleanTalk