Hi,
I'm having a similar problem in BGT. I managed to get shooting in my game, but when you fire at the enemy, it gives a runtime error:
A runtime error occurred.
File: C:\Users\EthinP\Documents\troop3\includes\enemy.bgt
On line: 33
In function: void enemy::die()
Description: Too large array size
The stack trace is:
Call stack size: 6
File: C:\Users\EthinP\Documents\troop3\includes\enemy.bgt
Line: 34 (2)
Function: void enemy::die()
File: C:\Users\EthinP\Documents\troop3\includes\enemy.bgt
Line: 23 (3)
Function: void enemy::hit(int)
File: C:\Users\EthinP\Documents\troop3\troop3.bgt
Line: 287 (1)
Function: void gameloop(level@, int)
File: C:\Users\EthinP\Documents\troop3\troop3.bgt
Line: 107 (1)
Function: void difficulty_menu(bool = false, bool = false)
File: C:\Users\EthinP\Documents\troop3\troop3.bgt
Line: 56 (1)
Function: void main_menu()
File: C:\Users\EthinP\Documents\troop3\troop3.bgt
Line: 26 (1)
Function: void main()
(The call stack gave it away. Its troop 3.)
The code of the top entry, which I'm assuming is the issue, is:
enemy@[] enemies;
//basic enemy class. Subclasses can be written later to expand and give different enemies different functions.
//The level class must also be included for the methods in this class to work.
class enemy {
int health, speed=250, ex=0, ey=100, cycle=1;
string soundpath;
double[] enemies;
timer movetimer;
enemy(level @lvl, int h, string s, int sp) {
this.health = h;
this.soundpath=s;
this.speed = sp;
spool.destroy_all();
int maxpos = lvl.maxPosition;
this.ex = random (0, maxpos);
}
enemy() {
//no default constructor allowed.
}
void hit(int d) {
this.health=this.health-d;
if(this.health<=0) {
this.die();
}
else
{
spool.play_1d (this.soundpath+"hit.ogg", x, ex, false, false);
}
}
void die ()
{
spool.play_1d (this.soundpath+"die.ogg", x, ex, false, false);
enemies.resize (enemies.length() - 1);
}
void move()
{
if(this.cycle==2)
{
this.ey=this.ey-5;
this.cycle=1;
}
else
{
this.cycle=2;
}
spool.play_extended_1d(this.soundpath+"move.ogg", x, ex, 0, 0, false, 0, 0, 100, ey+50, false);
}
}
void destroy_all_enemies()
{
enemies.resize(0);
}
Please remember that this is only an include. It does not include the required include files. the main source code does that.
Can anyone help?
"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question." — Charles Babbage.
My Github