Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: abstauber on Wed 01/08/2018 12:18:56

Title: Static extenders confusion
Post by: abstauber on Wed 01/08/2018 12:18:56
After learning about attributes, I am currently implementing them to my modules. Now I have also learned that static extenders are possible since 3.4.

I have a static struct like this, along with its extenders:

struct CustomDialogGui {
  import static void init();
  import static attribute int DialogGuiOptions[];
};
import void prepare(static CustomDialogGui, DialogOptionsRenderingInfo *info);
import void addOption(static CustomDialogGui, int position, int optionNumber, String optionText);
import void getOptionDetails(static CustomDialogGui, DialogOptionsRenderingInfo *info);
import void getRowCount(static CustomDialogGui, int width);


An extender function head looks like this in the .asc file, as it was explained here http://www.adventuregamestudio.co.uk/manual/ags38.htm

void prepare(static CustomDialogGui, DialogOptionsRenderingInfo *info)

Now here's the thing I don't understand.

The attribute extender has to be like declared like a non-static extender. And it even works (wtf)

bool seti_DialogGuiOptions(this CustomDialogGui*, eDialogGuiOptions index,  int value)


So yes, it all works but I don't get why attribute extenders have to be non-static on static structs.
Title: Re: Static extenders confusion
Post by: Crimson Wizard on Wed 01/08/2018 12:26:00
This should work in AGS 3.4.1:
Code (ags) Select

int get_PropertyName(static ClassName)
{
  return
}

void set_PropertyName(static ClassName, int value)
{
}
Title: Re: Static extenders confusion
Post by: abstauber on Wed 01/08/2018 12:31:05
Sure, but why the exception for the attribute extenders. I just found out that either of these work.

bool seti_DialogGuiOptions(static CustomDialogGui, eDialogGuiOptions index,  int value) {
}

// works too on a static struct, but it should not
bool seti_DialogGuiOptions(this CustomDialogGui*, eDialogGuiOptions index,  int value){
}
Title: Re: Static extenders confusion
Post by: Crimson Wizard on Wed 01/08/2018 12:45:08
That is just an oversight in the ags script implementation.

I do not think it's a good idea to rely on the pointer value inside a static extender, I cannot even tell what it will be, may be just null as well.

EDIT: Don't remember for certain, but it was probably only way to create static attributes before "static" extenders were allowed. If that's correct, then this was left for backwards compatibility.
Title: Re: Static extenders confusion
Post by: abstauber on Wed 01/08/2018 13:42:34
Ah alright, thanks for the clarification! Btw. in your doubleclick module you're using the non-static extender on a static struct - so at one time you might want to fix it.

bool geti_Event(this DoubleClick*, MouseButton mb)
Title: Re: Static extenders confusion
Post by: Crimson Wizard on Fri 03/08/2018 17:24:53
Quote from: abstauber on Wed 01/08/2018 13:42:34
Btw. in your doubleclick module you're using the non-static extender on a static struct - so at one time you might want to fix it.

bool geti_Event(this DoubleClick*, MouseButton mb)


This is done for compatibility with old versions of AGS which did not have static extender support.