Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: GarageGothic on Sun 18/05/2008 03:56:48

Title: Problems with dynamic array "new" command (SOLVED)
Post by: GarageGothic on Sun 18/05/2008 03:56:48
I've been trying to set up a dynamic array of bools (tried replacing with "int", but I get the same error). However, the compile fails with the message:

QuoteLightMap.asc(317): Error (line 317): Parse error in expr near 'new'

The line in question is:

origscalesetting = new bool[0];

At the top of the script module I have declared:

bool origscalesetting[];

If I comment line 317 out (I thought perhaps the zero-size array was a problem), it just get stuck at the next "new bool" line, which is:

origscalesetting = new bool[Game.CharacterCount];

That's just a modified version of the example from the manual, so it should work. What am I doing wrong?
Title: Re: Problems with dynamic array "new" command
Post by: monkey0506 on Sun 18/05/2008 04:07:07
I'm pretty sure you can't have a zero-sized array, but Game.CharacterCount should work as long as you have at least one Character....is it possible to have zero characters?

In any case, where exactly are you trying to create the array from?
Title: Re: Problems with dynamic array "new" command
Post by: GarageGothic on Sun 18/05/2008 04:23:39
I get the same error even with:

origscalesetting = new bool[10];

I'm creating it inside a function in a module where "bool origscalesetting[];" is defined at the top. It's the first module in the script lists, so I doubt it's because there's a global variable named "new" somewhere (if that's even possible?). The function itself is imported in a struct in the module header, but in this case it's called from within the module's own EnterRoomBeforeFadein event.

Edit: To track down the issue I commented out both functions and instead put it in game_start

function game_start() {
  origscalesetting = new bool[10];
  origlightsetting = new bool[10];
  }


Top op the script reads:

bool origscalesetting[];
bool origlightsetting[];


Same error message for the new line, so the details for the other functions don't really matter.

Edit 2: Hell, even copy-pasting the example from the manual gives this error. It seems that it doesn't like the word "new", but I can't see that I have any gui's, characters or global variables named new.
Title: Re: Problems with dynamic array "new" command
Post by: skuttleman on Sun 18/05/2008 04:41:31
try this:

bool origscalesetting[10];
bool origlightsetting[10];
Title: Re: Problems with dynamic array "new" command
Post by: GarageGothic on Sun 18/05/2008 04:49:24
You mean in game_start()? Then I just get:

QuoteLightMap.asc(382): Error (line 382): Variable 'origscalesetting' is already defined

which makes sense since it's defined at the top of the script. And if I put it in the definition, I get the same exact same message, probably because the size of the array is now static and therefore defined.

Edit: Strange, when I create a new game from the default template, I can use the example from the manual without any compile errors.
Title: Re: Problems with dynamic array "new" command
Post by: skuttleman on Sun 18/05/2008 05:11:27
don't define it in game start or anywhere else, except the very top of your script.
Title: Re: Problems with dynamic array "new" command
Post by: GarageGothic on Sun 18/05/2008 05:19:26
As I said:

Quoteif I put it in the definition, I get the same exact same message, probably because the size of the array is now static and therefore defined.

(I meant that I get the same error later in the script (when using the "new bool" command) because the size of the array was set when defining it using your code)

Anyhow, it does seem to be a problem specific to my game. The example code that compiled fine in my default game now gives an error (same "Parse error in expr near 'new'") at the "new bool" part when run from either it's own module or from the global script. I'm pretty sure this code doesn't have any mistakes:

int characterHealth[];

function game_start() {
  characterHealth = new int[Game.CharacterCount];
  }
Title: Re: Problems with dynamic array "new" command
Post by: monkey0506 on Sun 18/05/2008 05:28:29
There's nothing actually wrong with the code as you've said. I would say try starting a new game project in a different folder and see if you get the same errors. If you do this probably means your AGS installation is corrupt. Perhaps if you're trying dynamic arrays there is some AGS component that wasn't properly installed when you installed AGS? If you're installing from the installer, it's best to just install to a new folder because in my experience the installers don't always overwrite existing files (at least not properly or completely). Otherwise you'd need to be sure all files are extracted and overwritten.

It's unlikely that your installation is corrupt, though sometimes I have seen AGS hiccup and refuse to compile valid code. Sometimes it just takes a reboot of the computer.

And if all else fails, package it up and upload for CJ to check as at this point it's probably a bug somewhere.
Title: Re: Problems with dynamic array "new" command
Post by: GarageGothic on Sun 18/05/2008 05:34:57
I did a full reinstall of AGS (the latest beta) in a clean folder and also cleared the compiled and _debug folders of my game. A new game created using the same version does run the code, my game does not. I worry a bit that my game code got corrupted somewhere while moving through all the betas.

Have you tried using dynamic arrays in games that started development on older AGS versions?

I'm gonna try a reboot now at see if that changes anything, somehow I have my doubts  :-\
Thanks for the help!

Edit (after reboot): Nah, it didn't :)
Title: Re: Problems with dynamic array "new" command
Post by: Pumaman on Sun 18/05/2008 11:55:35
You've probably got something called "new" somewhere in the game, which is causing AGS to misinterpret the command. Double-check your view and character names and make sure none of them is called "new".

If all else fails and the game is a reasonable size, you could upload it for me to trace the problem.
Title: Re: Problems with dynamic array "new" command
Post by: GarageGothic on Sun 18/05/2008 13:24:32
Yes, that was what I thought too, and it's one of the first things I tried. But I haven't been able to located anything named just "new". Is there any limit to where this second "new" definition can be? Would I get the error if it was a variable defined in a script further down in the scripts list? I checked all the headers and it's not defined or imported anywhere there. Could it be in a room (object/hotspot/variable)? I didn't think AGS managed those unless the room file was open.

I should mention that "Enforce new-style strings" and "Enforce object-based scripting" are set to false to support some of my older code.

Edit: By the way, I'm a bit concerned about how the new editor allows script-o-names not preceded by a letter specifying it's type (e.g. oKey, cEgo). Isn't this likely to spawn lots of difficult-to-trace conflicts for beginners?

Edit 2: I PM'ed you a link to my game's source code. It would be great if you could take a look at it. Thanks!
Title: Re: Problems with dynamic array "new" command
Post by: Pumaman on Sun 18/05/2008 15:41:41
Thanks for uploading it.

Turns out it is a bug in the compiler, whereby "new" doesn't work if you have Left-to-Right Operator Precedence turned off in the general settings.

I'll get it fixed; in the meantime the workaround would be to switch that option on (assuming you're not relying on it being off for some script arithmetic).
Title: Re: Problems with dynamic array "new" command (SOLVED)
Post by: GarageGothic on Sun 18/05/2008 16:30:09
Great, so it's not just me then :)

I'll turn on left-to-right operator precedence for now. I think I've been paranoid enough in my scripting to have added parentheses everywhere needed.

Thanks for looking into it, CJ!