@ professor_scissors
Ha!
After tinkering around with your script I think I figured out where the problem lies.
Apparently, danmakufu goes insane when you call CreateEnemyFromScript in the @Initialize part of the parent enemy. I "outsourced" the slave creation from the @Initialize to a task that simply read task TSpawn{
yield;
ascent(i in 0..4) {
SetCommonData("Enemy01Side", id);
CreateEnemyFromScript("Familiar", GetX, GetY, 0, 0, i*90);
}
}
And now the error doesn't seem to appear anymore.
What got my attention was a strange occurance when I played around with the enemies' health. After making the main enemy tough and the slaves weak, I noticed that one of the slaves was much tougher than the others. So I tried this, and it seemed to work.
To be precise, the full code that is working for me right now is this:
script_enemy_main
{ //Slave-having enemy
let imgEnemy=GetCurrentScriptDirectory~"img\Enemy.png";
let imgAngle=0;
let shotAngle=0;
let id = GetArgument;
function wait(n) {
loop(n) { yield; }
}
task TMove {
while(GetX < GetClipMaxX + 51 && GetX > GetClipMinX - 51) {
if(GetSpeed > 0.5) {
SetSpeed(GetSpeed - 0.05);
}
yield;
}
VanishEnemy;
}
task TSpawn{
yield;
ascent(i in 0..4) {
SetCommonData("Enemy01Side", id);
CreateEnemyFromScript("Familiar", GetX, GetY, 0, 0, i);
}
}
@Initialize
{
SetLife(10);
SetDamageRate(100, 100);
LoadGraphic(imgEnemy);
if(id) {
SetCommonData("Enemy01LeftX", GetX);
SetCommonData("Enemy01LeftY", GetY);
SetCommonData("Enemy01LeftDead", false);
SetAngle(30);
SetSpeed(5);
} else {
SetCommonData("Enemy01RightX", GetX);
SetCommonData("Enemy01RightY", GetY);
SetCommonData("Enemy01RightDead", false);
SetAngle(150);
SetSpeed(5);
}
TSpawn;
TMove;
}
@MainLoop
{
SetCollisionA(GetX, GetY, 16);
SetCollisionB(GetX, GetY, 16);
if(id) {
SetCommonData("Enemy01LeftX", GetX);
SetCommonData("Enemy01LeftY", GetY);
} else {
SetCommonData("Enemy01RightX", GetX);
SetCommonData("Enemy01RightY", GetY);
}
yield;
}
@Finalize
{
// if(id) {
// SetCommonData("Enemy01LeftDead", true);
// } else {
// SetCommonData("Enemy01RightDead", true);
// }
CreateItem(ITEM_SCORE, GetX + rand(-10,10), GetY + rand(10,10));
}
@DrawLoop
{//
SetTexture(imgEnemy);
SetGraphicRect(1,1,32,32);
SetColor(255,255,255);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,imgAngle);
DrawGraphic(GetX(),GetY());
SetTexture(imgEnemy);
SetGraphicRect(1,1,32,32);
SetColor(255,255,255);
SetRenderState(ADD);
SetGraphicAngle(0,0,-imgAngle);
DrawGraphic(GetX(),GetY());
imgAngle+=4;
if(imgAngle>360){imgAngle-=360;}
}
}
script_enemy Familiar {
let ImgFam = GetCurrentScriptDirectory ~ "img\Enemy.png";
let imgAngle=0;
let angle = (GetArgument)*90;
let id = GetCommonData("Enemy01Side");
function wait(w) {
loop(w) { yield; }
}
@Initialize {
SetLife(10);
SetDamageRate(100, 100);
TRotate;
TFire;
}
@MainLoop {
SetCollisionA(GetX, GetY, 8);
SetCollisionB(GetX, GetY, 8);
if(id) {
if(GetCommonDataDefault("Enemy01LeftDead", true)||BeParentVanished==true) {
VanishEnemy;
}
} else {
if(GetCommonDataDefault("Enemy01RightDead", true)||BeParentVanished==true) {
VanishEnemy;
}
}
yield;
}
@DrawLoop
{//
SetTexture(ImgFam);
SetGraphicRect(1,1,32,32);
SetColor(255,255,255);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,imgAngle);
DrawGraphic(GetX(),GetY());
SetTexture(ImgFam);
SetGraphicRect(1,1,32,32);
SetColor(255,255,255);
SetRenderState(ADD);
SetGraphicAngle(0,0,-imgAngle);
DrawGraphic(GetX(),GetY());
imgAngle+=4;
if(imgAngle>360){imgAngle=0;}
}
@Finalize
{//
CreateItem(ITEM_SCORE, GetX + rand(-10,10), GetY + rand(10,10));
}
// rotate around the boss
task TRotate {
let eX = 0;
let eY = 0;
loop {
if(id) {
eX = GetCommonDataDefault("Enemy01LeftX", -50);
eY = GetCommonDataDefault("Enemy01LeftY", -50);
} else {
eX = GetCommonDataDefault("Enemy01RightX", -50);
eY = GetCommonDataDefault("Enemy01RightY", -50);
}
SetX(eX + cos(angle) * 50);
SetY(eY + sin(angle) * 50);
yield;
angle += 1.5;
}
}
task TFire {
loop {
CreateShot01(GetX, GetY, 1.5, angle+180, RED01, 10);
CreateShot01(GetX, GetY, 2, angle+180, ORANGE01, 10);
wait(36);
}
}
}
It contains a number of other small differences, some of which may have had a positive effect on the performance of the script, so when you still get errors, copypaste the entire script. I didn't implement the damaging of the main enemy through the slaves yet, though.
Among other things, you had SetGraphicRect and other drawing related functions inside the @Initialize parts of the scripts. Generally, you call these in the @DrawLoop once for each individual call of DrawGraphic. Also, you still had SetScore(0); in your slave scripts, which as I said doesn't do anything except maybe cause additinal problems.
Also, you should load the data for the enemies (graphics and sounds) at the beginning of the stage you want to use them in. Otherwise you'll load the stuff into memory mutliple times and cause slight slow down when the enemies appear.