Script link failure for indexed attribute

Started by edmundito, Yesterday at 15:09:48

Previous topic - Next topic

edmundito

Hello, I'm trying to figure out a problem I'm having with indexed attributes which is a feature I haven't used much in the past.

Here's a summary: I'm working on a pattern to get an indexed value of a managed struct pointer from another managed struct (source link below), which is more or less like this:

Code: ags
managed struct Child {
  int Index;

  import readonly attribute String Name;
  import String get_Name();
}

managed struct Parent {
  import readonly attribute Child* children[];
  import Child* geti_Children(int index);
}


String _names[];
Child* _children[];

String Child::get_Name() {
  return _names[this.Index];
}

Child* Parent::geti_Children(int index) {
  return _children[i];
}


void game_start() {
  _names = new String[8];
  _children = new Child[8];
}


But if I write `parent.Children[0]` in the script and build the game (3.6.2), I get an error:
Code: ags
Error (line unknown): in script 'LayeredCharacter.asc' around line 147: cannot resolve import (bytecode pos 1967, key -1).

The line in question is here:
https://github.com/clickpulp/ags-modules/blob/7c4f28793e072c86c672a1e3b85129e67b6541d6/game/LayeredCharacter.asc#L147

Is there something I'm missing, or is there something not supported in AGS 3.x, or is this a bug?

eri0o

#1
I don't have AGS to test right now but I think this is the ags3 issue that you can't use attributes in the same script where you declare them. I just remember that it gave me a mystical error message.

This is fixed in ags4 with the new compiler.

If it's this, you would need to call geti_AttributeName(I).

Crimson Wizard

#2
Yes, the old compiler cannot handle this case for some reason, which I forgot.
I think I tried to investigate once, but it's code is confusing me, so I failed at the time.

You have to call a real function instead:

Code: ags
parent.Children[0]
---->
Code: ags
parent.geti_Children(0)

You can still use the proper syntax when using structs and attributes declared in other script headers.

SMF spam blocked by CleanTalk