Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Crimson Wizard on Thu 08/07/2010 18:34:33

Title: [3.2 RC5] Compiler failure at calling static func inside [ ]
Post by: Crimson Wizard on Thu 08/07/2010 18:34:33
Example code:


struct MyStruct
{
  import static int func();
};

function SomeOtherFunc()
{
   int arr[100];
   int var = arr[MyStruct.func()];    // <--- line X
}


Compiler stops with error: " Error (line X): parse error after '[' ".


Possible workaround:

   int dummy = MyStruct.func();
   int var = arr[dummy];

Title: Re: [3.2 RC5] Compiler failure at calling static func inside [ ]
Post by: Khris on Thu 08/07/2010 18:51:18
I didn't test this and the error seems unrelated, but doesn't an array declaration require a constant?
What happens if you try this using a dynamic array?
Title: Re: [3.2 RC5] Compiler failure at calling static func inside [ ]
Post by: Crimson Wizard on Thu 08/07/2010 18:52:07
Quote from: Khris on Thu 08/07/2010 18:51:18
I didn't test this and the error seems unrelated, but doesn't an array declaration require a constant?
What happens if you try this using a dynamic array?
It isn't array declaration. It is getting array's element by index.

There's no error if a non-static struct member is used.
I guess it is parsing mistake.
Title: Re: [3.2 RC5] Compiler failure at calling static func inside [ ]
Post by: Monsieur OUXX on Fri 09/07/2010 11:03:28
Yeah, I've noticed that the compiler sometimes doesn't really like complex expressions between the square brackets of an array.
The few times it happend, as you already mentionned, I used the workaround to use a temporary variable :

temporary variable : = complex expression
array[temporary variable] : =   ...
Title: Re: [3.2 RC5] Compiler failure at calling static func inside [ ]
Post by: Khris on Fri 09/07/2010 12:05:34
Yeah, sorry, I have to stop posting here while being too tired =)
Title: Re: [3.2 RC5] Compiler failure at calling static func inside [ ]
Post by: Crimson Wizard on Fri 09/07/2010 17:33:24
Quote from: Monsieur OUXX on Fri 09/07/2010 11:03:28
temporary variable : = complex expression
array[temporary variable] : =   ...

Pascal coder detected  ;D
Title: Re: [3.2 RC5] Compiler failure at calling static func inside [ ]
Post by: Pumaman on Mon 12/07/2010 21:26:27
Yes, there are a couple of limitations on the way the compiler handles static functions & properties. It's the same reason that this doesn't work:

int hour = DateTime.Now.Hour;

I will try to get around to fixing it at some point.