A little help with an internal error?

Started by beomoud, Sat 31/01/2009 19:42:49

Previous topic - Next topic

beomoud

I get an error in my script and i frankly can't find anything wrong with it, the message i get is:

An internal error has occurred.....
(ACI version 3.10.10.50)

Error: Unable to create local script: Runtime error: unresolved import 'NPC::set_stroll^13'

I am working on AGS 3.1

Does anyone have any idea what that might be? In the referred function i am using optional parameters....what could it be?
Also the import declaration of this function belongs to a struct.... any thoughts?

this is in the script:

function NPC::set_stroll(short ch_numb, short timer_numb, int timer_min, int timer_max, short max_mov, int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4){
......
}

and this is in the header

import function set_stroll(short ch_numb, short timer_numb, int timer_min, int timer_max, short max_mov, int x1 = 0, int y1 = 0, int x2 = 0, int y2 = 0, int x3 = 0, int y3 = 0, int x4 = 0, int y4 = 0);

I use this function in a room script but when i delete it from there it compiles just fine....

room script:

person[2].set_stroll(2, 3, 400, 800, 3, 200, 180, 1175, 210, 685, 250);

Khris

This might happen because the function has eleven parameters.

beomoud

#2
I tried to Split it into two functions and it worked. Why would that even happen, is there a limit to the parameters?

Gilbert

As far as I remember there was a limit of at most 10 parameters per function, don't know whether this had been changed though.

Pumaman

Sorry for the delay with this... I've finally had time to investigate it and there is indeed a bug here.

The AGS script engine limits functions to 14 parameters, however there is a bug which means that if you have a struct member function it will give this error message at run-time if it has more than 9 parameters.

I will get it fixed so that all functions including struct member functions can have the 14 parameters.

Joe

Hmmm I'm having the same trouble... will this be corrected in the next AGS version?

CJ: are you thinking to make the parameters limit bigger?
Copinstar © Oficial Site

Gilbert

:P
Quote* Fixed struct member functions with more than 9 parameters giving run-time error
http://www.adventuregamestudio.co.uk/yabb/index.php?topic=37668.0

Joe

Oh damn. I mean, sorry. Thanks for telling.

Anyway I'd also like to know if the parameters number is gonna be increased.

Thanks
Copinstar © Oficial Site

Pumaman

Do you need more than 14 parameters in a single function call?

Joe

Well in my last script i had a function with 13 parameters... but maybe in a future I'd like to add more parameters.

In my game I have different kinds of enemies, and the function was just to make the game begin creating the number of enemies of each kind specified with the parameters:

function Begin(int enem1Quantity, enem2Quantity............);

So if I had more than 14 kind of enemis I'd have to divide it in 2 functions... and It's not very nice. Anyway It's not necessary for me by now....
Copinstar © Oficial Site

lostbuthappy

#10
I know, I'm new, but I can't shut up on this one :)
I'm programming software for more than ten years (blah blah blah) and it rarely occured that I had to pass more than four arguments to a function. If you need much more this often indicates that your function is not specialized enough to be easy to maintain and understand (especially a few months later). Also this many arguments are easily mixed up and therefore a common source for errors which are either found before the game's being shipped or manage to hide in a dark place before the light is switched on and are then referred to as bugs.
If splitting the function into more specialized ones is not an option, can't you just use an array instead?:
Code: ags

enum EnemyTypes
{
  etGiantWarhog = 0,
  // ...
  etStripedBiologistTaunter = 12
};

int enemyQuantities[13];
  enemyQuantities[etGiantWarhog] = 24;
  // ...
  enemyQuantities[etStripedBiologistTaunter] = 3;

doStuff(enemyQuantities);

(If you can't pass arrays in ags please ignore this post entirely :~)
Disclamer: When I say I'm an artist I usually just mean that I can selectively apply filters to an image until it looks like a blurry version of Uranus.

Khris

You can't, unfortunately.

But you can do this:

Code: ags
  param.first_param = 15;
  param.second_param = "Woot!";
  param.third_param = "3.0";
  param.fourth_param = "Poobungies.";
  ...
  param.seventeenth_param = "Of course!";
  doStuff();


Where param is an instance of a struct holding the parameters. The thing is: you don't need to pass "param" to the function because you'll only ever use "param".

If you really need to pass a certain instance to a function, declare an array of instances, then pass the index number to the function.

To pass more than ten ints which are in the range of 0-999, I'd use a string and simply stitch them together (using leading zeros).

So it's entirely possible to work around the limitation.

Wonkyth

Hmm, seems a bit over-fiddly to me...
It would certainly make thing easier for me if you could pass arrays.
"But with a ninja on your face, you live longer!"

Joe

Quote from: lostbuthappy on Thu 07/05/2009 03:39:06
If you need much more this often indicates that your function is not specialized enough to be easy to maintain and understand (especially a few months later). Also this many arguments are easily mixed up and therefore a common source for errors which are either found before the game's being shipped or manage to hide in a dark place before the light is switched on and are then referred to as bugs.

Well I really don't need it too much but I can sure you my code was really understandable. Cause I had defined an array ef enemies called 'Enemy enemies[MAX_ENEMIES]' and I had one function to 'create' each one and I say 'create' because  it's not really to create it, it's just to define their initial values like: graphic, x,y, sound....
And the function that needed the 13 parameters was to create all of them in a loop:

Code: ags

#define KIND1 1
#define KIND2 2
#define KIND3 3

static void Enmies::Begin(int e1Quant, e2Quant, int e3Quant){
  //Call this function only at any room_load script
  int k=0;
  EnemQuant= e1Quant + e2Quant + e3Quant;
  
  while(k<EnemQuant){
    if(k<e1Quant+e2Quant+e3Quant)enemies[k].Create(KIND3);
    if(k<e1Quant+e2Quant)enemies[k].Create(KIND2);
    if(k<e1Quant)enemies[k].Create(KIND1);
    k++;
  }
 
}
Copinstar © Oficial Site

lostbuthappy

Quote from: KhrisMUC on Thu 07/05/2009 06:40:57
You can't, unfortunately.
Meh.
Well, thanks for pointing that out, Khris! Using a struct will certainly do the job, although you can't just iterate over it (which I'd totally miss since I'm quite lazy :)). Ain't it possible to pass a pointer to an array (I couldn't find anything about that in the manual)?

@Joe Carl: What I wrote was just a general advice. Of course I didn't accuse anybody's particular code to be unreadable, I don't even know it. And as you can see I'm quite new to the forums and ags in general and don't know all it's capabilities and limitations, yet. So if you're happy with your code, so am I :)
Disclamer: When I say I'm an artist I usually just mean that I can selectively apply filters to an image until it looks like a blurry version of Uranus.

Joe

Thanks. And Khris thankyou too, I'll do that if I need more than 14 params. :)
Copinstar © Oficial Site

Pumaman

I can appreciate that until AGS supports passing custom structs as function parameters, you might need to pass a lot of parameters as a workaround. I'll look into it but it's not going to be a high priority.

lostbuthappy

Dear Santa Claus (or christmasman, as he's known in Germany :)),
I've been a good boy this year (and if you think otherwise I'll see you in court), so please grant me these wishes:
1: Let me pass arrays an structs to a function in ags
2: Give me a whirpool with bubbles!
3: When I alt-tab out of an ags application please stop haunting me with techno-beats.

You'll find cookies and milk near the alligator pit. Thanks in advance,
lostbuthappy
Disclamer: When I say I'm an artist I usually just mean that I can selectively apply filters to an image until it looks like a blurry version of Uranus.

SMF spam blocked by CleanTalk