AGS v2.7 Final: Yet Another Edition

Started by Pumaman, Sat 13/11/2004 21:02:00

Previous topic - Next topic

Pumaman

There's always one, isn't there  ::)

Fine, you can have your transparent selection background but you'll have to wait for beta 7  :P

Rui 'Trovatore' Pires

Aw, sorry 'bout being so picky! I've been having a looksie at the whole new GUI system. I love it! You're doing an awsome job! ;D
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Pumaman

Hehe actually I did think about making 0 transparent when I added it, but then I thought "that would be stupid, then you wouldn't be able to tell which item was selected".

It was only when you mentioned it that I took a second look and remembered there's the selected text colour property too ... so the rolleyes are all mine I think  ::)

RickJ

Quote
Added simple inheritance support ("extends" keyword).
Can you give a sample usage of reference a descritption in manual.  Thanks.

Quote
All GUI controls now have a "Script name" property, which allows you to give them a VB-style "lstSaveGames" or "btnCancel" type name.
Then, in the script you can do stuff like:
lstSaveGames.AddItem("Jibble");
rather than
ListBoxAdd(3, 6, "Jibble");
all much nicer the new way.
Wouldn't it be something like gMyGui.lstSaveGames.AddItem("Jibble").  If not then how is the particular GUI id resolved?  Also, there is no "Script O-name" display for Gui components in the editor pane.  Is the "lst", "btn", ect prefixes enforced by the editor (as is with gName, oName and cName) or is this just by convention for Gui components? 

Quote
Room objects now have script names, so that you can do:
oDoor.Animate( ... );
and so on, which is much more user friendly than the previous number-based approach.
Cool! Cool! Cool! 
Would it be practical, at some point, to allow mixed case for the object names so that instead of oFrontdoor.Animate(...)  one could have oFrontDoor.Animate(...). 

Character Objects
Don't yet have a Script O-name display in the editor pane as do Object Objects and Gui Objects. 

All I can say is really cool stuff here CJ  8)


Rui 'Trovatore' Pires

---------------------------
Illegal exception
---------------------------
An exception 0xC0000005 occured in ACWIN.EXE at EIP = 0x0044867E ; program pointer is +211, ACI version 2.70.800, gtags (7,2)

AGS cannot continue, this exception was fatal. Please note down the numbers above, remember what you were doing at the time and notify CJ on the Tech forum.



Most versions of Windows allow you to press Ctrl+C now to copy this entire message to the clipboard for easy reporting.
---------------------------
OK   
---------------------------

I seem to get this error whenever I use RestartGame(). This is the message I get when calling it from the GUIs, I get a similar message when calling it from a hotstpot.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Pumaman

QuoteCan you give a sample usage of reference a descritption in manual.  Thanks.

struct Base {
  int a;
}

struct Derived extends Base {
  int b;
}

then you can do:
Derived der;
der.a = 4;
der.b = 5;

The reason I say it's simple inheritance support is that you can't downcast a pointer, ie. you can't do this:

Derived *derived;
Base *base = derived;

so the inheritance is of limited use... I basically added what was necessary for the GUI Control stuff.

QuoteWouldn't it be something like gMyGui.lstSaveGames.AddItem("Jibble").

Well, I thought about that... it would be the "proper" OO way to do it, but fully pathing the control names all the time would be a pain, so in the end I decided just to make the control names have global scope. The only drawback is that you can't have two controls on different GUIs with the same name; but then, allowing that would only lead to confusion anyway.

QuoteIf not then how is the particular GUI id resolved?

The GUI ID is not needed in the script any more -- AGS knows which GUI the control is on, so you can just use the control's name.

QuoteAlso, there is no "Script O-name" display for Gui components in the editor pane.  Is the "lst", "btn", ect prefixes enforced by the editor (as is with gName, oName and cName) or is this just by convention for Gui components?

The prefix is not enforced. Whatever you type in as the script name for the gui control, is the name by which it is accessible in the script.

QuoteWould it be practical, at some point, to allow mixed case for the object names so that instead of oFrontdoor.Animate(...)  one could have oFrontDoor.Animate(...). 

Well, it's a matter of practicality. At the moment, for backwards compatibility, the o-name is just the script name automatically sentence-cased. However, in a future version there could be an option to get rid of the old-style script names, and then you could give an exact o-name however you wanted.

QuoteI seem to get this error whenever I use RestartGame(). This is the message I get when calling it from the GUIs, I get a similar message when calling it from a hotstpot.

Um, oops. Yeah, er, beta 6 will crash if you restore or restart the game ... well spotted, sorry about that. I'll get it fixed.

RickJ

Quote
struct Derived extends Base {
  int b;
}
Does this also work for internal AGS objects (i.e Characters, Objects, GUI, etd) or just ones created in the script?


Pumaman

Well, you could declare a struct inherited from a Character, but because the characters aren't actually declared as your inherited type you wouldn't be able to use it.

RickJ

Quote
Quote
I tried your test game but I didn't get a crash. All I got was it ran through the first room and then got an Array Index Out of Bounds error on global script line 1075.
At what point does it crash for you?
It crashes right at startup.  I may even happen before the video mode is switched etc.  I happens both when I do a Test or when I execute the exe directly.   I didn't have any problems with V2.62.   

I guess I'll go check line 1075 and see what's going on there and let you know if I can get it to work.  Maybe I'll just start doing surgery until the problem goes away.  If you can't repoduce the problem then there probably isn't much you can do on your end.   If you have any other ideas or things you would like me to try just let me know.
If you remember the problem I had converting an existing game a couple of betas back... The problem is that I was using "object" as a parameter name in a number of functions I created.   It seemed an appropiate name to use, at the time, for passing a room object's id number.   It's not surprising that object-o-izing (hehe, sorry couldn't resist the 'o' thingy)  process laid claim to "object" as a reserved word but the resulting error message is a bit confusing in that the line number given doesn't seem to exist or be related.  I suppose "object" contains a pointer or something that go used in trying to acces the object[] array.

I guess this is more of a gotcha than a bug for people upgrading existing projects.

P.S.  I accidently disobeyed you and upgarded everything on that project and now have no way back to my V2.62 version.   Everything seems to now work ok under the new beta.   Will I be forgiven and my project see a bright future or shall I be cursed and my project suffer a thousand calamities?   ??? 

Pumaman

QuoteIf you remember the problem I had converting an existing game a couple of betas back... The problem is that I was using "object" as a parameter name in a number of functions I created.

Hmm, that should generate a compile error... I'll look into it.

QuoteP.S.  I accidently disobeyed you and upgarded everything on that project and now have no way back to my V2.62 version.   Everything seems to now work ok under the new beta.   Will I be forgiven and my project see a bright future or shall I be cursed and my project suffer a thousand calamities?

Oh dear... I can see the cloud of wasps approaching already  :-\

Scorpiorus

Oh my god!!Ã,  :o

Methods, properties, enums, optional arguments, pointers with neatly improved autocomplete list and calltip features! Hurray OO! Hurray CJ! :)

Unbelievably useful things we have here! High thanks, Chris, for improving the scripting language!

Pity I couldn't be online for the past month and thus missed such interesting changes being made. I'm still fiddling with the new features and, if I may, I'd like to ask a couple of questions:

1. Sorry if it was already discussed but is it possible to declare user properties? I've tried some things but was unable to declare those get_* / set_* functions for my property to work.

2. Is it a bad idea to have user-defined managed :) structs (and thereby pointers to them) in scripts? Will it lead to some weird results with save/load?

Oh and btw, is it safe to name vars/functions as something like NAME_name (or whatever it may be) if there is a NAME::name identifier there? I mean are there any internal names declared (like in C with its names with leading underscore character) or should we not bother?

Pumaman

Quote from: RickJ on Tue 14/12/2004 01:26:17
If you remember the problem I had converting an existing game a couple of betas back... The problem is that I was using "object" as a parameter name in a number of functions I created. It seemed an appropiate name to use, at the time, for passing a room object's id number. It's not surprising that object-o-izing (hehe, sorry couldn't resist the 'o' thingy) process laid claim to "object" as a reserved word but the resulting error message is a bit confusing in that the line number given doesn't seem to exist or be related. I suppose "object" contains a pointer or something that go used in trying to acces the object[] array.

Hmm, I tried doing this:

function myfunc(int object) {
}

but I correctly got a compile error saying the "object" was already defined. Can you elaborate on what sort of code you had that lead it to crash?

QuoteUnbelievably useful things we have here! High thanks, Chris, for improving the scripting language!

No problem! It was about time ;)

Quote1. Sorry if it was already discussed but is it possible to declare user properties? I've tried some things but was unable to declare those get_* / set_* functions for my property to work.

User properties in the script are not currently supported. Plugins can however export them (I'll update the plugin documentation at a later date).

Quote2. Is it a bad idea to have user-defined managedÃ,  structs (and thereby pointers to them) in scripts? Will it lead to some weird results with save/load?

That's a possibility for future. It would need some sort of "new" keyword and associated script bytecode, but I may well add it at some point. To be honest, it's not a priority for 2.7.

QuoteOh and btw, is it safe to name vars/functions as something like NAME_name (or whatever it may be) if there is a NAME::name identifier there? I mean are there any internal names declared (like in C with its names with leading underscore character) or should we not bother?

Member vars/funcs are named internally "struct::member", and since that's not a legal name for a global variable I think you'll be alright ;)

Scorpiorus

Thanks for clarifying :)

Having plugin to export properties would be a really nice feature.

Quote from: Pumaman on Tue 14/12/2004 20:38:16Member vars/funcs are named internally "struct::member", and since that's not a legal name for a global variable I think you'll be alright ;)
Hehe, the reason I asked is because in earlier versions it wasn't possible to declare a var like this:

struct NAME {
Ã,  int name;
};

int NAME_name;

And yeah, hehe, one can't have '::' as part of a var name - the above piece of code is compiled with no problems in the beta. :)

RickJ

Quote
but I correctly got a compile error saying the "object" was already defined. Can you elaborate on what sort of code you had that lead it to crash?

The sample game I gave you produces the error.  If you remember, you got the runtime error as well.  If you don't have a copy of the sample it's still up  here: http://www.gaia-spa.com/project/ags/

Pumaman

Quote from: Scorpiorus on Tue 14/12/2004 23:19:53
Having plugin to export properties would be a really nice feature.

Properties are translated into two functions:
type Struct::get_PropertyName(Struct *)
void Struct::set_PropertyName(Struct *, type);

where type is the property's variable type. If you export those (or just the "get" one for a readonly property) from the plugin that'll do the trick.

QuoteHehe, the reason I asked is because in earlier versions it wasn't possible to declare a var like this:

struct NAME {
  int name;
};

int NAME_name;

Indeed, that's one of the things I fixed for the beta :)

QuoteThe sample game I gave you produces the error.  If you remember, you got the runtime error as well.

Hmm, I just got an array index error. Anyway, glad it's all working now.

Scorpiorus

#135
Quote from: Pumaman on Wed 15/12/2004 21:53:05
Properties are translated into two functions:
type Struct::get_PropertyName(Struct *)
void Struct::set_PropertyName(Struct *, type);

where type is the property's variable type. If you export those (or just the "get" one for a readonly property) from the plugin that'll do the trick.
Thanks for the info - I managed to get it to work with the following code:

Plugin code (changes in ags_template.cpp):
struct FRUITS {

   int Apples;Ã,  Ã, // property
   int bananas;Ã,  // ordinary var
};

int get_Apples(const FRUITS * const pFruits) {

   return pFruits->Apples;
}

void set_Apples(FRUITS * const pFruits, int newValue) {

   pFruits->Apples = newValue;
}

...

const char *ourScriptHeader =
"Ã,  struct FRUITS {Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã, \r\n"
"Ã,  Ã,  import attribute int Apples;Ã,  Ã,  Ã,  Ã,  Ã,  \r\n"
"Ã,  Ã,  int reserved; // $AUTOCOMPLETEIGNORE$ \r\n"
"Ã,  Ã,  int bananas;Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  \r\n"
"Ã,  };Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  \r\n";

...

Ã,  engine->RegisterScriptFunction ("FRUITS::get_Apples", get_Apples);
Ã,  engine->RegisterScriptFunction ("FRUITS::set_Apples", set_Apples);

Main global script
FRUITS fruits[3];

function game_start() {
Ã,  // called when the game starts, before the first room is loaded
Ã,  
Ã,  Ã,  int i = 0;
Ã,  Ã,  
Ã,  Ã,  while (i < 3)
Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Display("Apples: %d",Ã,  fruits[ i ].Apples);
Ã,  Ã,  Ã,  Ã,  Display("Bananas: %d", fruits[ i ].bananas);
Ã,  Ã,  Ã,  Ã,  
Ã,  Ã,  Ã,  Ã,  fruits[ i ].Apples++;
Ã,  Ã,  Ã,  Ã,  fruits[ i ].bananas++;
Ã,  Ã,  Ã,  Ã,  
Ã,  Ã,  Ã,  Ã,  Display("Apples: %d",Ã,  fruits[ i ].Apples);
Ã,  Ã,  Ã,  Ã,  Display("Bananas: %d", fruits[ i ].bananas);
Ã,  Ã,  Ã,  
Ã,  Ã,  Ã,  Ã,  i++;Ã,  
Ã,  Ã,  }
}

The first thing I realized that the property import declaration only adds get/set functions but not a variable to store the value, that's actually a clever way. So I added int reserved;. :)

By the way, what about declaring a variable in the plugin code and then export its adress via RegisterScriptFunction. I tried to declare a struct var, export it from the plugin and then import into the script header (just like import GameCharacter character[]). That way we could access the var from both the script and the plugin itself. I seems to work fine. One thing though, for such imported struct var AGS doesn't show autocomplete list with struct's members.

It would be cool to be able to declare a pointer to this var in the script but it didn't work even if I define a struct as managed - Error(...): Pointer cast failure: the object being pointed to is not in the managed object pool.

p.s. sorry for cluttering the thread with somewhat aside issues. :)




EDIT:

After some testing I discovered the following issues:

1. Compiler doesn't allow to declare a pointer to a non-managed type but it's still possible to do that within the function header:
struct MyStruct {
Ã,  Ã,  int a;
};

function Func(MyStruct *Pointer) {

Ã,  Ã,  Pointer.a = 10;
}
On calling that function AGS reports an "object is not in pool" error. Seems not dangerous as the engine catchs that one at run-time. Just to let you know. :)



2. If function only has optional parameters and is called with default values the compiler doesn't allow that:
import function Func(int a = 0, int b = 0);

Funct();
I see that none of the imported internal functions is declared like this, so maybe it's not supposed that a function is declared this way.



3. Optional parameters only work in room scripts:
script header:

import function Func(int a, int b=0);

global script:

function Func(int a, int b) {
Ã,  Ã,  return a+b;
}


Func(1); // doesn't work

room script:

Func(1); // works
I believe that's because the global script has a function implementation code. And it's not possible to have a default value in there (unless the identifier is not specified):
global script:

function Func(int a, int b=0) { // doesn't work
Ã,  Ã,  return a+b;
}

global script:

function Func(int a, int=0) { // allowed but variable identifier is lost

}

SSH

Maybe not the right place for this, but there's no MP3-free version of AGS 2.62 on the main download page...
12

Pumaman

Quote from: Scorpiorus on Thu 16/12/2004 13:16:43
Thanks for the info - I managed to get it to work with the following code:

That looks exactly right, glad you got it working :)

Quote
The first thing I realized that the property import declaration only adds get/set functions but not a variable to store the value, that's actually a clever way. So I added int reserved;. :)

Yes, this is deliberate. The script compiler shouldn't make any assumptions about how the property is actually stored internally -- it might not even be stored as part of that struct necessarily. Your "int reserved" approach is the best way, and it's what I've done with the built-in AGS stuff.

Quote
By the way, what about declaring a variable in the plugin code and then export its adress via RegisterScriptFunction. I tried to declare a struct var, export it from the plugin and then import into the script header (just like import GameCharacter character[]). That way we could access the var from both the script and the plugin itself. I seems to work fine.

Yep, that should work fine, it's what AGS does to export stuff like the characters. This should be mentioned in the docs for RegisterScriptFunction really.

QuoteOne thing though, for such imported struct var AGS doesn't show autocomplete list with struct's members.

It should do -- so long as the struct definition and the import directive are part of the plugin's script header, it should be picked up. If it's not working, can you provide the plugins' script header and I can take a look at why it might not be spotting it.

Quote
It would be cool to be able to declare a pointer to this var in the script but it didn't work even if I define a struct as managed - Error(...): Pointer cast failure: the object being pointed to is not in the managed object pool.

Yes, this will be the case -- I need to add a new RegisterManagedObject function or something to the plugin API.

Basically, managed objects have a reference count maintained, and are automatically freed when the count reaches 0. (this is how things like the OpenFile function don't cause a memory leak).

In order for the reference count to work, AGS has to have the object in its "managed pool"; but currently there's no plugin access to do so.

QuoteMaybe not the right place for this, but there's no MP3-free version of AGS 2.62 on the main download page...

Hmm yeah, oops. Ah well, if anyone needs it, let me know and I'll see what I can do.

Scorpiorus

#138
Quote from: Pumaman on Thu 16/12/2004 22:47:26The script compiler shouldn't make any assumptions about how the property is actually stored internally -- it might not even be stored as part of that struct necessarily.
Yeah, I got it after looking into a new GameObject struct - it mainly consists of properties but all of them should use old object's get/set functions.

QuoteYep, that should work fine, it's what AGS does to export stuff like the characters. This should be mentioned in the docs for RegisterScriptFunction really.
That's really cool - I can see some use for this. :)

QuoteIt should do -- so long as the struct definition and the import directive are part of the plugin's script header, it should be picked up. If it's not working, can you provide the plugins' script header and I can take a look at why it might not be spotting it.
Yep, and the strange thing - it happens to work with no problem. When I had FRUITS fruits[3]; in the plugin header it worked. I'll try replicating and then provide all the info about it.

QuoteBasically, managed objects have a reference count maintained, and are automatically freed when the count reaches 0.
Ah, like in COM specification. So we have it similar to VB and every time the object address is written into a pointer or pointer is reset to nill the ref count is adjusted if necessary?
BTW, I noticed that in the beta a 'ac.log' file is created with all that stuff being logged into it. :)

Quote(this is how things like the OpenFile function don't cause a memory leak).
Ah, so a local pointer to file is reset and file is closed as the function is finished?

By the way, I had edited my previous post just a few minutes before you replied -- some testing results there.

Pumaman

Quote from: Scorpiorus on Fri 17/12/2004 19:15:04
Ah, like in COM specification. So we have it similar to VB and every time the object address is written into a pointer or pointer is reset to nill the ref count is adjusted if necessary?

Exactly. I prefer this method to the .net/java style because this way has determinalistic destruction of objects, which comes in handy for various things. The only potential problem is circular references, which is why pointers are not allowed inside struct definitions.

Quote
BTW, I noticed that in the beta a 'ac.log' file is created with all that stuff being logged into it. :)

Indeed ... this was in case it caused catastrophic crashes all over the place, I'd have some useful information to work from ;)

QuoteAh, so a local pointer to file is reset and file is closed as the function is finished?

Yes, if you forget to Close the file yourself, it will now automatically be closed when the File object goes out of scope.

QuoteCompiler doesn't allow to declare a pointer to a non-managed type but it's still possible to do that within the function header

Well spotted, I'll fix that.

QuoteIf function only has optional parameters and is called with default values the compiler doesn't allow that:

Hmm, that's a strange one, I'll look into it.

QuoteOptional parameters only work in room scripts:

Good point, I'll have a look at how difficult this would be to resolve.

SMF spam blocked by CleanTalk