Custom functions?

happyturk Heya. I thought the last would be a one-time post, because I don't want to bother all've ya, but I have a quick question for those of you out there that are code-savvy.

Is there a way, in AGI logics, to define a function somewhere and then simply call the function when you need it, rather than typing in a long string of commands over and over?

Like defining functions in C, if anyone's familiar.

Or like a macro.

It's just that there's one very long string of commands I'm finding I have to put into every room's if(f5) section just to make sure the correct view is attached to o0, depending on what 'character' is currently selected. And it'd be really nice to define it elsewhere and only have to call the one function in each room.

Any help would be appreciated, as would a simple 'no, that's impossible', if that's the case... so I'll stop wasting my time. ;)

Joel If it's possible (I'm not sure it is), it won't be as simple as a language that has functions built in. You could create a file that you include in every logic file (kind of like defines.txt) that has a labeled section that provides the implementation of the "function". However, I'm not sure how you'd resume execution where you left off if you did something like that. That would probably be the greatest difficulty. If you can do that, you could probably define something that gives you the behavior you want.

If it's simply a matter of a lot of duplicate code, it might be easier just to put that code into a text file and include the text file where you want that code executed. If you have a file code.txt that has the contents:

load.pic(room_no);
draw.pic(room_no);
discard.pic(room_no);

You could then create a new logic and use the following code to load its picture resource:

if (new_room)
{
#include "code.txt"
}

That should theoretically work. I've never actually tried it, so I don't know for sure.
AGI1122 You need to set up a separate logic for the function you want to happen. Program all the stuff in the separate logic then goto the logics that this needs to be used in. Then in the new room flag put load.logics(number); Then where you want the code to be used type this call(number);
Joel Yeah, I wasn't thinking about that. If there's going to be a lot of code that you want to reproduce or you don't think you'll need all 255 logics for your game, then creating another logic should work just fine.

If you that's not the case, it would probably be worthwhile to use the #include method. AGISCI, I think that thing with not allowing space at the beginning of the line with stuff like #define is by design and is not a bug. I guess that's one problem with this method...it'll produce some ugly code and will probably increase the sizes of every logic that uses it.
Nailhead

#define "code.txt" works
AGI1122 I think the ability to add spaces should be included because there might still be some people that don't know that you can't add spaces in it and it might cause them some trouble.
Joel As far as I can tell, if it's not a bug in the compiler, it seems to be just an arbitrary decision (it may have been based on the behavior of earlier compilers, but if so I can't imagine why they would behave that way).

It doesn't seem to affect anything in Visual C++ if there's space at the beginning of the line, so I don't think it's based on the behavior of C++. If you think it will be fairly simple to fix it, I'd say go ahead.
Joel Actually, scratch that. According to my C++ book, it IS a requirement of C++ that compiler directives like #define start in column 1. I guess Visual C++ just lifted that requirement.

I'd say it's up to you then. It doesn't really matter to me.
AGI1122 The AGI Studio program was not written in Visual C++ it is written in pascal. I don't really know anything about pascal since I don't have it.

Woo hoo 100 posts amazing arn't I!!!
Joel I know AGI Studio wasn't written in Visual C++, but the syntax for the logic is based on the syntax for C, and C apparently requires preprocessor directives to start at column 1.

happyturk As I finally get my cable modem working again. o_o

Thanks for all the responses; that should be really helpful and save my poor fingers some strain.  ^__^
AGI1122 Hope this helps and if you need anything else just ask.
df what I did was have some custom stuff. this is a rundown of basically what I had.

you need a bunch of free variables.

1 variable as function variable
1 var as return value
say 5 as function parameters.

have 1 logic as your 'util' logic.

(pretty rough psuedo code)

eg:
logic.254
and variables 100-106

in logic.254

if v100 = 0
{
/* function 1 */
}
if v100 = 1
{
/* function 2 */
}
etc

====

then in your other logics
v100 = 0 /* call function 0 */
call logic.254

that way you can have a bunch of common routines
callable from anywhere in your code! nice and reusable
and saves from having a logic.0 thats HUUUUUUUUUUUUUUUUGE

brian corr hye evry1 its been awhile but im back

i think your best bet is to use logic 90, it's called in evry cycle...

set up your custom thing like this:
(in logic 90)

if(f30){

(your custom stuff)

reset(f30);
}


then whenever you want to call that just type
set(f30);

and it will run that.

voila