Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: monkey0506 on Sun 30/01/2011 01:09:09

Title: BUG: Compile error using static variable as index to dynamic array. (AGS 3.2.1)
Post by: monkey0506 on Sun 30/01/2011 01:09:09
I haven't tested it in AGS 3.2 yet, only the 3.2.1 Beta, but if I use a static variable (such as Room.Height, System.ViewportWidth, etc.) in the index of a dynamic array (by itself or as part of an expression) then I get a compile-time error. If there is an expression used (i.e., an arithmetic applied to the value) then I get "parse error in expression near [array name]", otherwise I get "parse error after '['".

It's reasonably simple to work around, I just store the static variable's value into a temporary variable and it compiles properly.
Title: Re: BUG: Compile error using static variable as index to dynamic array. (AGS 3.2.1)
Post by: Pumaman on Sun 30/01/2011 19:44:22
this is a general problem with the compiler using static variables inside a non-static, you get the same problem with:

int hour = DateTime.Now.Hour;

It does need to be fixed.
Title: Re: BUG: Compile error using static variable as index to dynamic array. (AGS 3.2.1)
Post by: monkey0506 on Sun 30/01/2011 21:06:49
Yeah, I was aware of the issues with accessing a non-static member of a static member of a class. I wasn't sure if it was actually related since dynamic arrays aren't (at least on the user-side) tied to structs at all.

Anyway, since this is compile-side, is there a technical reason why the engine would reject it? Meaning, with the editor being open-sourced, would it be possible for this issue to be addressed by anyone right now, or would it still cause runtime issues?
Title: Re: BUG: Compile error using static variable as index to dynamic array. (AGS 3.2.1)
Post by: Pumaman on Fri 04/02/2011 19:35:16
It's an issue with the way the compiler parses expressions containing static variables.

It's purely a compiler error, the engine would accept it fine. However the compiler is part of the Native DLL which is not yet open-sourced.
Title: Re: BUG: Compile error using static variable as index to dynamic array. (AGS 3.2.1)
Post by: monkey0506 on Fri 04/02/2011 23:12:39
Ah, yes. I later asked myself whether it might be there..

Very well then. :) Thanks for the info nonetheless.