exploding barrel trouble
Ive made a script for an exploding barrel. This is as in you lite it and it explodes. I've come across some trouble regarding coordinates of the spark though. The first coordinate works. That's the one where the sprite is made btw, but after that, it jumps far to the left. I think I've done my coordinates right, so I can't find the problem. Here's the part of my script that's causing trouble:
Edit: By far left, I do not mean off screen.
//Excerpt from script
int &fsave_x = sp_x(¤t_sprite, -1);
int &fsave_y = sp_y(¤t_sprite, -1);
//frame 1 -------------------------------------------------------------------------------------------------]
&fsave_x -= 13 ;
&fsave_y -= 30;
//create the spark
int &spark = create_sprite(&fsave_x, &fsave_y, 6, 166, 1);
sp_seq(&spark, 166);
sp_que(&spark, 10001);
//reset the variable
&fsave_x += 13 ;
&fsave_y += 30;
wait(500);
//frame 2 -------------------------------------------------------------------------------------------------]
sp_pframe(¤t_sprite, 2);
&fsave_x -= 13;
&fsave_y -= 35;
//move spark
sp_x(&spark, &fsave_x);
sp_x(&spark, &fsave_y);
//reset the variable
&fsave_x += 13;
&fsave_y += 35;
wait(500);
//frame 3 -------------------------------------------------------------------------------------------------]
sp_pframe(¤t_sprite, 3);
&fsave_x -= 10;
&fsave_y -= 35;
//move spark
sp_x(&spark, &fsave_x);
sp_x(&spark, &fsave_y);
//reset the variable
&fsave_x += 10;
&fsave_y += 35;
wait(500);
//frame 4 -------------------------------------------------------------------------------------------------]
sp_pframe(¤t_sprite, 4);
&fsave_x -= 6;
&fsave_y -= 32;
//move spark
sp_x(&spark, &fsave_x);
sp_x(&spark, &fsave_y);
//reset the variable
&fsave_x += 6;
&fsave_y += 32;
wait(500);
//frame 5 -------------------------------------------------------------------------------------------------]
sp_pframe(¤t_sprite, 5);
&fsave_x -= 3;
&fsave_y -= 33;
//move spark
sp_x(&spark, &fsave_x);
sp_x(&spark, &fsave_y);
wait(500);
//blow up time !!
goto blowup;
Edit: By far left, I do not mean off screen.
//Excerpt from script
int &fsave_x = sp_x(¤t_sprite, -1);
int &fsave_y = sp_y(¤t_sprite, -1);
//frame 1 -------------------------------------------------------------------------------------------------]
&fsave_x -= 13 ;
&fsave_y -= 30;
//create the spark
int &spark = create_sprite(&fsave_x, &fsave_y, 6, 166, 1);
sp_seq(&spark, 166);
sp_que(&spark, 10001);
//reset the variable
&fsave_x += 13 ;
&fsave_y += 30;
wait(500);
//frame 2 -------------------------------------------------------------------------------------------------]
sp_pframe(¤t_sprite, 2);
&fsave_x -= 13;
&fsave_y -= 35;
//move spark
sp_x(&spark, &fsave_x);
sp_x(&spark, &fsave_y);
//reset the variable
&fsave_x += 13;
&fsave_y += 35;
wait(500);
//frame 3 -------------------------------------------------------------------------------------------------]
sp_pframe(¤t_sprite, 3);
&fsave_x -= 10;
&fsave_y -= 35;
//move spark
sp_x(&spark, &fsave_x);
sp_x(&spark, &fsave_y);
//reset the variable
&fsave_x += 10;
&fsave_y += 35;
wait(500);
//frame 4 -------------------------------------------------------------------------------------------------]
sp_pframe(¤t_sprite, 4);
&fsave_x -= 6;
&fsave_y -= 32;
//move spark
sp_x(&spark, &fsave_x);
sp_x(&spark, &fsave_y);
//reset the variable
&fsave_x += 6;
&fsave_y += 32;
wait(500);
//frame 5 -------------------------------------------------------------------------------------------------]
sp_pframe(¤t_sprite, 5);
&fsave_x -= 3;
&fsave_y -= 33;
//move spark
sp_x(&spark, &fsave_x);
sp_x(&spark, &fsave_y);
wait(500);
//blow up time !!
goto blowup;
One more problem. I want it to be set off when it is attacked by a fireball or hellfire, so I tried this, but it doesn't work. I tested the numbers of Dink's punch and that worked, but the fireballs do not for some odd reason...
Note: Fireball sequences are 502, 504, 506, 504; Hellfire sequences are 512, 514, 516, 518. Btw &crap is defined in the main procedure correctly.
void hit( void )
{
&crap = sp_seq(&missle_source, -1);
if (&crap > 500)
{
if (&crap < 520)
goto blowup;
}
}
Update: It works when you're right against it. Other than that, it doesn't work.
Note: Fireball sequences are 502, 504, 506, 504; Hellfire sequences are 512, 514, 516, 518. Btw &crap is defined in the main procedure correctly.
void hit( void )
{
&crap = sp_seq(&missle_source, -1);
if (&crap > 500)
{
if (&crap < 520)
goto blowup;
}
}
Update: It works when you're right against it. Other than that, it doesn't work.
Reformat and then throw your PC through your window, should fix it. If not give me a message back.
I don't think that'll be necessary... Sounds like it'd cause more problems than it'd solve... Anyways, I fixed the spark problem. It was something wrong with the sp_x, sp_y things, I guess. I created new sparks and disabled the old ones and all that fun so it works now (I created a new spark for each frame)
I guess the fireball thing won't happen as all the retarded problems seem to find their way toward me.

I guess the fireball thing won't happen as all the retarded problems seem to find their way toward me.
Okay, I think I've come up with a solution, but I'm not sure how to go about it or if it's even possible. Is there a way to run an if statement based on the projectile's particular script. For example the script should identify if the projectile has a script, and then do the if statement if the script attatched is dam-sfb or dam-fire.
If this isn't possible, I know I could modify the damage scripts to identify if it is hitting a barrel, then forcing the barrel to run it's exploding procedure, but I'd like to keep everything in this script.
If this isn't possible, I know I could modify the damage scripts to identify if it is hitting a barrel, then forcing the barrel to run it's exploding procedure, but I'd like to keep everything in this script.
You could check to see if there is a script attached with
&myscript = is_script_attached(&missile_source);
&okthen = 0;
run_script_by_number(&myscript,"CHECK");
use the check procedure in the fireball script, and write
void check(void)
{
&okthen = 1;
}
&okthen is a global variable. You can check then if it's 1 or 0. I know you didn't want to involve the fireball script, but that's the only way I could think of, if you want to check for scripts.
&myscript = is_script_attached(&missile_source);
&okthen = 0;
run_script_by_number(&myscript,"CHECK");
use the check procedure in the fireball script, and write
void check(void)
{
&okthen = 1;
}
&okthen is a global variable. You can check then if it's 1 or 0. I know you didn't want to involve the fireball script, but that's the only way I could think of, if you want to check for scripts.
That is a bad idea. I think that if run_script_by_number doesn't find the procedure it wants, it will just run a procedure that does exist, like push() or die() or something. Maybe 1.08 fixed this?
EDIT: redink1 quoted in the DinkC reference (in regards to run_script_by_number): "I did notice one thing, though... if the engine can't find the specified procedure in the script, then it runs the die() procedure."
EDIT: redink1 quoted in the DinkC reference (in regards to run_script_by_number): "I did notice one thing, though... if the engine can't find the specified procedure in the script, then it runs the die() procedure."
Try this script for the barrel:
void hit( void )
{
int &holder = sp_seq(&missile_source, -1);
say(&holder, ¤t_sprite);
//And just to check...
int &holder = sp_pseq(&missile_source, -1);
say(&holder, 1);
}
This should tell you a little more about what's going on.
void hit( void )
{
int &holder = sp_seq(&missile_source, -1);
say(&holder, ¤t_sprite);
//And just to check...
int &holder = sp_pseq(&missile_source, -1);
say(&holder, 1);
}
This should tell you a little more about what's going on.
Okay. I tried this and got -1 for both.
This is quite queer... I made it so that it will react to sequence 161 (the atomic bomb sequence) and that worked fine.

I had thought that the problem might be that the fireball changes sequences (goes to sequence 70) when it hits the thing. This is very, very odd. It looks as if &missle_source (lol, missle) "reverts" to -1. The whole system of variables having certain values in certain contexts is rather prone to bugs, especially if you try to do anything complicated.
Anyways, to improve upon cypry's idea, if the barrel sequence is XXX, you could add the following to the damage procedure of the fireball:
&target_pseq = sp_pseq(&missile_target, -1);
if (&target_pseq == XXX)
{
&target_pseq = sp_script(&missile_target, -1);
//You should probably use a custom variable for the following:
&target_gold = sp_gold(&missile_target, -1);
//^ if target's gold is 1, we will blow it up.
if (&target_gold == 1)
{
run_script_by_number(&target_pseq, "kaboom");
}
}
Then, in the barrel script, you would have a kaboom procedure to blow it up and add sp_gold(¤t_sprite, 1) in the main procedure. There's probably a simpler way to do this, but I think this is the redink way.
There is a similar bug with the fireplace in VDC, but way more bizzare. This idea did not (entirely) fix it.
Anyways, to improve upon cypry's idea, if the barrel sequence is XXX, you could add the following to the damage procedure of the fireball:
&target_pseq = sp_pseq(&missile_target, -1);
if (&target_pseq == XXX)
{
&target_pseq = sp_script(&missile_target, -1);
//You should probably use a custom variable for the following:
&target_gold = sp_gold(&missile_target, -1);
//^ if target's gold is 1, we will blow it up.
if (&target_gold == 1)
{
run_script_by_number(&target_pseq, "kaboom");
}
}
Then, in the barrel script, you would have a kaboom procedure to blow it up and add sp_gold(¤t_sprite, 1) in the main procedure. There's probably a simpler way to do this, but I think this is the redink way.
There is a similar bug with the fireplace in VDC, but way more bizzare. This idea did not (entirely) fix it.
I guess I shall give in and do this. The exploding of the barrel already has it's own procedure, so it will be cake
I am familiar with doing this type of thing, but thanks anyways. I was just stubborn and didn't want to have to put yet another script in the story folder


From dinkc.chm:
compare_sprite_script
Category: Script, Sprite
Version: 1.00+
Prototype: int compare_sprite_script(int active_sprite, string script[9]);
compare_sprite_script returns '1' if active_sprite is attached to a script named script.
I guess that in that last line active_sprite and script should be switched, since scripts are attached to sprites, not sprites to scripts.
compare_sprite_script
Category: Script, Sprite
Version: 1.00+
Prototype: int compare_sprite_script(int active_sprite, string script[9]);
compare_sprite_script returns '1' if active_sprite is attached to a script named script.
I guess that in that last line active_sprite and script should be switched, since scripts are attached to sprites, not sprites to scripts.