Read-only archive of the Armageddon Games Forums Archive (2000–2026) · About this archive

this-> bug and workaround

4 replies · 1,233 views · Started 06 January 2007

Lets say you have two FFCs and want them to move around with individual movement scripts. If you try to stick movement scripts on them using the this-> function, what you'll discover is that the codes collapse into one and all of the this-> data refers to one FFC. One of your FFCs wont move, the other will do nothing.

For instance, this code:


// =============================================================
// vertical_dasher - This FFC will use four FFCs on the screen as
// vertical dashers. The dasher will move up and down the length
// of the screen, until it comes into line with the player. It will
// then lunge across the screen. At the other side, it's combo
// will increase (use this as a "turning around" graphic) and it will
// repeat it's behavior going the other way. Designed to be a 2x2 boss.
// Put this FFC on an invisible FFC that the others will follow.
// D0-D3 - Numbers of the FFCs used as the dasher.
// D4 - Speed of the dasher while moving up and down.
// D5 - Speed of the dasher while dashing.
// =============================================================

ffc script vertical_dasher{

void main (int first_ffc, int second_ffc, int third_ffc, int fourth_ffc, int rest_speed; int dash_speed){

int state = 0; // 0 = Moving up the right side of the room
// 1 = Moving down the right side of the room
// 2 = Dashing left
// 3 = Moving up the left side of the room
// 4 = Moving down the left side of the room
// 5 = Dashing right

while(true){
if (state == 0){
if ((Link->Y < this->Y+16) && (Link->Y > this->Y-1)) { state = 2; }
else{
if (this->Y < 32){

this->Vy = 0;
state = 1;

}
else
{
this->Vy = -rest_speed;
}
}
} // end of state 0

if (state == 1){
if ((Link->Y < this->Y+16) && (Link->Y > this->Y-1)) { state = 2; }
else{
if (this->Y > 128){

this->Vy = 0;
state = 0;

}
else
{
this->Vy = rest_speed;
}
}
} // end of state 1

if (state == 2){
if (this->X < 32){ state = 3; }
else{
this->Vy = 0;
this->Vx = -dash_speed;
}
} // end of state 2

if (state == 3){
if ((Link->Y < this->Y+16) && (Link->Y > this->Y-1)) { state = 5; }
else{
if (this->Y > 128){

this->Vy = 0;
state = 4;

}
else
{
this->Vy = rest_speed;
}
}
} // end of state 3

if (state == 4){
if ((Link->Y < this->Y+16) && (Link->Y > this->Y-1)) { state = 5; }
else{
if (this->Y > 128){

this->Vy = 0;
state = 3;

}
else
{
this->Vy = rest_speed;
}
}
} // end of state 4

if (state == 5){
if (this->X > 224){ state = 0; }
else{
this->Vy = 0;
this->Vx = dash_speed;
}
} // end of state 5

Waitframe();

} // end of while loop
} // end of void main
} // end of ffc script

Will, if you put it on FFC4, execute on FFC0, for some reason. Youll see FFC0 moving around.

BUT! There is a workaround. Don't use this->. Instead, explicitly pass the script the number of the FFC and load it. This code will move the proper ffc.


// =============================================================
// vertical_dasher - This FFC will use four FFCs on the screen as
// vertical dashers. The dasher will move up and down the length
// of the screen, until it comes into line with the player. It will
// then lunge across the screen. At the other side, it's combo
// will increase (use this as a "turning around" graphic) and it will
// repeat it's behavior going the other way. Designed to be a 2x2 boss.
// Put this FFC on an invisible FFC that the others will follow.
// D0-D3 - Numbers of the FFCs used as the dasher.
// D4 - Speed of the dasher while moving up and down.
// D5 - Speed of the dasher while dashing.
// D6 - The number of this FFC (Workaround for problems with "this"
// pointer in ZC beta 2.15
// =============================================================

ffc script vertical_dasher{

void run (int first_ffc, int second_ffc, int third_ffc, int fourth_ffc, int rest_speed, int dash_speed, int this_ffc_number){

int state = 0; // 0 = Moving up the right side of the room
// 1 = Moving down the right side of the room
// 2 = Dashing left
// 3 = Moving up the left side of the room
// 4 = Moving down the left side of the room
// 5 = Dashing right

ffc first_piece = Screen->LoadFFC(first_ffc);
ffc second_piece = Screen->LoadFFC(second_ffc);
ffc third_piece = Screen->LoadFFC(third_ffc);
ffc fourth_piece = Screen->LoadFFC(fourth_ffc);

ffc this_ffc = Screen->LoadFFC(this_ffc_number);

while(true){
if (state == 0){
if ((Link->Y < this_ffc->Y+16) && (Link->Y > this_ffc->Y-1)) { state = 2; }
else{
if (this_ffc->Y < 32){

this_ffc->Vy = 0;
state = 1;

}
else
{
this_ffc->Vy = -rest_speed;
}
}
} // end of state 0

if (state == 1){
if ((Link->Y < this_ffc->Y+16) && (Link->Y > this_ffc->Y-1)) { state = 2; }
else{
if (this_ffc->Y > 128){

this_ffc->Vy = 0;
state = 0;

}
else
{
this_ffc->Vy = rest_speed;
}
}
} // end of state 1

if (state == 2){
if (this_ffc->X < 32){
state = 3;
first_piece->Data++;
second_piece->Data++;
third_piece->Data++;
fourth_piece->Data++;
}
else{
this_ffc->Vy = 0;
this_ffc->Vx = -dash_speed;
}
} // end of state 2

if (state == 3){
if ((Link->Y < this_ffc->Y+16) && (Link->Y > this_ffc->Y-1)) { state = 5; }
else{
if (this_ffc->Y > 128){

this_ffc->Vy = 0;
state = 4;

}
else
{
this_ffc->Vy = rest_speed;
}
}
} // end of state 3

if (state == 4){
if ((Link->Y < this_ffc->Y+16) && (Link->Y > this_ffc->Y-1)) { state = 5; }
else{
if (this_ffc->Y > 128){

this_ffc->Vy = 0;
state = 3;

}
else
{
this_ffc->Vy = rest_speed;
}
}
} // end of state 4

if (state == 5){
if (this_ffc->X > 224){
state = 0;
first_piece->Data--;
second_piece->Data--;
third_piece->Data--;
fourth_piece->Data--;
}
else{
this_ffc->Vy = 0;
this_ffc->Vx = dash_speed;
}
} // end of state 5

Waitframe();

} // end of while loop
} // end of void main
} // end of ffc script

NOTE: There may be other errors in the older version of the code, as the old one is from a backup. It's the this-> changes that matter.

Not sure. It was a problem in an earlier beta, I never heard of a fix, so I've just always continued to use the workaround. I'll check to see if it's been fixed sometime this weekend.

It is still a bug.

Under build 357, I tried my wallflower script using this-> instead of passing in the ffc number and using LoadFFC(). The behavior is still as C-Dawg originally described. If I make two wall following traps and apply the script to both of them, only the first trap will move. If I remove the script from ffc 1, and have ffc 2 use the script, ffc 1 will move.

Also, if I put the trap ffcs on ffc 2 and 3, neither one moves at all. Basically, this-> always points to ffc #1.

Here is an example quest: http://filer.case.edu/dpf4/this.qst