Couple of quick scripting questions (from a Java programmer)

Started by Jared, Fri 17/10/2008 00:49:47

Previous topic - Next topic

Jared

I've been programming in Java for 2 years at TAFE and have got the hang of the language pretty well, along with the Object-Oriented principles. (Not gotten the hang of handing in assignments in time but that's neither here nor there..) I've noticed that the AGS scripting language is quite similar, but then I think I read it was based on C so that makes sense.

Anyway, firstly I've been taught that encapsulation is the key to good programming, and that 100+ line code so should be avoided outside of driver classes, so when I read that "All character interaction must be handled in the Global Script" a warning light goes off in my head. For some context I'm making a LECScumm gui game at the moment so my Global Script is already 400+ lines just with click handling. Here's something I know would work in Java and that's creating a Characters script where all the code goes, so that the GlobalScript bits would look like this:

cGinny_mode8(){
    cGinny_click();
}

And the code would then be really easy to use. Any reason why that wouldn't work?

Also, I was wondering about the scope of variables. I'm assuming at the moment that an int is only accessible within it's native class (as in Java), but does the AGS language support Getters to make this job easier? Do they look any different from

int getDoorLocked(){
    return doorLocked;
}

Sorry if these questions are stupid, but I've found that looking at the Scripting tutorials that they're all geared for newbies to scripting. If there was an overview of the language's traits made for experienced programmers I didn't see it, and it could be an idea for any updates. Thanks in advance for your help.

RickJ

You may find some of the documentation here helpful, especially the Module Programming Guidelines and  Programming Conventions documents.

The issue of cleaning up the global script by separating out character, gui, and other interactions has been recently discussed in this thread.   The conclusion seemed to be that a good first step to improve the situation is to allow the interactions to be moved to a module which, to the best of my knowledge, is not currently implemented.   Since the current development version is in the "Release Canidate Stage" I wouldn't expect this to happen until the next version.

As far as your suggestion is concerned you can do something similar now by using modules to contain the interaction code.  And then the only thing that needs to be in the global script is the interaction handler and a call to the code in your module. 

In the case of GUI events it's even possible to use the same handler for multiple events.  The GUI handlers are passed a pointer to the control that was clicked and a mouse button ID, so it's possible to pass the same info on to a function in a module which determines what was clicked and what to do about it.   I'm not certain if something similar can be done for characters or not.

Variable scope is fairly uncomplicated.   Variables defined within the scope of a function are dynamic and are valid only for the duration of the function's execution.   Variables defined outside the bounds of a function are static and can be shared between any functions defined within the same script file. 
Variables can be made global using the export and import keywords.  To create a global variable you would make it's declaration in the global script along with an export statement.  You would then put an import statement in the script header which would make it available to any room script.

Hope this helps  :D

Jared

Ah, thanks a heap! Those DemoQuest docs are much more like what I'm used to.

Quote from: RickJAs far as your suggestion is concerned you can do something similar now by using modules to contain the interaction code.  And then the only thing that needs to be in the global script is the interaction handler and a call to the code in your module. 

Yeah, that was the idea. Guess I'll have to read up on how the AGS modules work. But now I'm on my way. Thanks again.

SMF spam blocked by CleanTalk