Author Topic: Static extenders confusion  (Read 509 times)

abstauber

  • Cavefish
  • Posts: 2,048
  • still mowing the lawn
    • abstauber worked on a game that won an AGS Award!
    •  
    • abstauber worked on a game that was nominated for an AGS Award!
Static extenders confusion
« on: 01 Aug 2018, 12:18 »
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:
Code: Adventure Game Studio
  1. struct CustomDialogGui {
  2.   import static void init();
  3.   import static attribute int DialogGuiOptions[];
  4. };
  5. import void prepare(static CustomDialogGui, DialogOptionsRenderingInfo *info);
  6. import void addOption(static CustomDialogGui, int position, int optionNumber, String optionText);
  7. import void getOptionDetails(static CustomDialogGui, DialogOptionsRenderingInfo *info);
  8. import void getRowCount(static CustomDialogGui, int width);
  9.  

An extender function head looks like this in the .asc file, as it was explained here http://www.adventuregamestudio.co.uk/manual/ags38.htm
Code: Adventure Game Studio
  1. void prepare(static CustomDialogGui, DialogOptionsRenderingInfo *info)
  2.  
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)
Code: Adventure Game Studio
  1. bool seti_DialogGuiOptions(this CustomDialogGui*, eDialogGuiOptions index,  int value)
  2.  

So yes, it all works but I don't get why attribute extenders have to be non-static on static structs.
« Last Edit: 01 Aug 2018, 12:27 by abstauber »

Crimson Wizard

  • Posts: 8,794
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    • Lifetime Achievement Award Winner
    • Crimson Wizard worked on a game that won an AGS Award!
    •  
    • Crimson Wizard worked on a game that was nominated for an AGS Award!
Re: Static extenders confusion
« Reply #1 on: 01 Aug 2018, 12:26 »
This should work in AGS 3.4.1:
Code: Adventure Game Studio
  1. int get_PropertyName(static ClassName)
  2. {
  3.   return
  4. }
  5.  
  6. void set_PropertyName(static ClassName, int value)
  7. {
  8. }
  9.  

abstauber

  • Cavefish
  • Posts: 2,048
  • still mowing the lawn
    • abstauber worked on a game that won an AGS Award!
    •  
    • abstauber worked on a game that was nominated for an AGS Award!
Re: Static extenders confusion
« Reply #2 on: 01 Aug 2018, 12:31 »
Sure, but why the exception for the attribute extenders. I just found out that either of these work.
Code: Adventure Game Studio
  1. bool seti_DialogGuiOptions(static CustomDialogGui, eDialogGuiOptions index,  int value) {
  2. }
  3.  
  4. // works too on a static struct, but it should not
  5. bool seti_DialogGuiOptions(this CustomDialogGui*, eDialogGuiOptions index,  int value){
  6. }
  7.  

Crimson Wizard

  • Posts: 8,794
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    • Lifetime Achievement Award Winner
    • Crimson Wizard worked on a game that won an AGS Award!
    •  
    • Crimson Wizard worked on a game that was nominated for an AGS Award!
Re: Static extenders confusion
« Reply #3 on: 01 Aug 2018, 12:45 »
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.
« Last Edit: 01 Aug 2018, 12:53 by Crimson Wizard »

abstauber

  • Cavefish
  • Posts: 2,048
  • still mowing the lawn
    • abstauber worked on a game that won an AGS Award!
    •  
    • abstauber worked on a game that was nominated for an AGS Award!
Re: Static extenders confusion
« Reply #4 on: 01 Aug 2018, 13:42 »
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.
Code: Adventure Game Studio
  1. bool geti_Event(this DoubleClick*, MouseButton mb)
  2.  

Crimson Wizard

  • Posts: 8,794
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    • Lifetime Achievement Award Winner
    • Crimson Wizard worked on a game that won an AGS Award!
    •  
    • Crimson Wizard worked on a game that was nominated for an AGS Award!
Re: Static extenders confusion
« Reply #5 on: 03 Aug 2018, 17:24 »
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.
Code: Adventure Game Studio
  1. bool geti_Event(this DoubleClick*, MouseButton mb)
  2.  

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