scripting trouble, why always me
Here's a script for my game. It looks perfectly fine to me, but it doesn't work properly and I am completely perplexed. It pushes perfectly and changes the variable the way it's supposed to, but the script for the created sprite doesnt change like it's supposed to. So the main sprite moves, but the created sprite still run. I've tried killing it and everything, but it won't work. It DOES work if you change screens and come back, but that's the same procedure...
I just realized the first three created sprites don't do what they're supposed to even on screenchange.
Forgive me if this is some dumb error overlooked by me, but I keep testing and testing and it gets really annoying because there is a lot going on concerning the screen the scripts take place on.
void main( void )
{
int &junk;
int &place;
int &rock = sp_x(¤t_sprite, -1);
sp_hard(¤t_sprite, 0);
draw_hard_sprite(¤t_sprite);
if (&rock == 465)
{
&rock = 1;
int &hole = create_sprite(507, 278, 0, 158, 2);
}
if (&rock == 244)
{
&rock = 2;
int &hole = create_sprite(244, 286, 0, 158, 2);
}
if (&rock == 279)
{
&rock = 3;
int &hole = create_sprite(243, 131, 0, 158, 2);
}
if (&rock == 466)
{
&rock = 4;
int &hole = create_sprite(513, 120, 0, 158, 2);
}
sp_script(&hole, "s5-trap2");
sp_que(&hole, -10);
sp_nohit(&hole, 1);
goto check;
}
void push ( void )
{
freeze(1);
sp_speed(¤t_sprite, 1);
&place = &rock_placement;
if (&rock == 1)
{
if (&place >= 1000)
&place -= 1000;
if (&place >= 100)
&place -= 100;
if (&place >= 10)
&place -= 10;
if (&place < 1)
{
if (sp_dir(1, -1) == 6)
{
move_stop(¤t_sprite, 6, 507, 1);
&rock_placement += 1;
}
}
}
if (&rock == 2)
{
if (&place >= 1000)
&place -= 1000;
if (&place >= 100)
&place -= 100;
if (&place < 10)
{
if (sp_dir(1, -1) == 2)
{
move_stop(¤t_sprite, 2, 286, 1);
&rock_placement += 10;
}
}
}
if (&rock == 3)
{
if (&place >= 1000)
&place -= 1000;
if (&place < 100)
{
if (sp_dir(1, -1) == 4)
{
move_stop(¤t_sprite, 4, 243, 1);
&rock_placement += 100;
}
}
}
if (&rock == 4)
{
if (&place < 1000)
{
if (sp_dir(1, -1) == 6)
{
move_stop(¤t_sprite, 6, 513, 1);
&rock_placement += 1000;
}
}
}
unfreeze(1);
draw_hard_map();
goto check;
}
void check( void )
{
check:
&place = &rock_placement;
if (&place >= 1000)
{
if (&rock == 4)
{
sp_x(¤t_sprite, 513);
&junk = is_script_attached(&hole);
sp_script(&hole, "");
}
}
&place -= 1000;
if (&place >= 100)
{
if (&rock == 3)
{
sp_x(¤t_sprite, 243);
sp_script(&hole, "");
}
}
&place -= 100;
if (&place >= 10)
{
if (&rock == 2)
{
sp_y(¤t_sprite, 286);
sp_script(&hole, "");
}
}
&place -= 10;
if (&place >= 1)
{
if (&rock == 1)
{
sp_x(¤t_sprite, 507);
sp_script(&hole, "");
}
}
draw_hard_map();
}
I just realized the first three created sprites don't do what they're supposed to even on screenchange.
Forgive me if this is some dumb error overlooked by me, but I keep testing and testing and it gets really annoying because there is a lot going on concerning the screen the scripts take place on.
void main( void )
{
int &junk;
int &place;
int &rock = sp_x(¤t_sprite, -1);
sp_hard(¤t_sprite, 0);
draw_hard_sprite(¤t_sprite);
if (&rock == 465)
{
&rock = 1;
int &hole = create_sprite(507, 278, 0, 158, 2);
}
if (&rock == 244)
{
&rock = 2;
int &hole = create_sprite(244, 286, 0, 158, 2);
}
if (&rock == 279)
{
&rock = 3;
int &hole = create_sprite(243, 131, 0, 158, 2);
}
if (&rock == 466)
{
&rock = 4;
int &hole = create_sprite(513, 120, 0, 158, 2);
}
sp_script(&hole, "s5-trap2");
sp_que(&hole, -10);
sp_nohit(&hole, 1);
goto check;
}
void push ( void )
{
freeze(1);
sp_speed(¤t_sprite, 1);
&place = &rock_placement;
if (&rock == 1)
{
if (&place >= 1000)
&place -= 1000;
if (&place >= 100)
&place -= 100;
if (&place >= 10)
&place -= 10;
if (&place < 1)
{
if (sp_dir(1, -1) == 6)
{
move_stop(¤t_sprite, 6, 507, 1);
&rock_placement += 1;
}
}
}
if (&rock == 2)
{
if (&place >= 1000)
&place -= 1000;
if (&place >= 100)
&place -= 100;
if (&place < 10)
{
if (sp_dir(1, -1) == 2)
{
move_stop(¤t_sprite, 2, 286, 1);
&rock_placement += 10;
}
}
}
if (&rock == 3)
{
if (&place >= 1000)
&place -= 1000;
if (&place < 100)
{
if (sp_dir(1, -1) == 4)
{
move_stop(¤t_sprite, 4, 243, 1);
&rock_placement += 100;
}
}
}
if (&rock == 4)
{
if (&place < 1000)
{
if (sp_dir(1, -1) == 6)
{
move_stop(¤t_sprite, 6, 513, 1);
&rock_placement += 1000;
}
}
}
unfreeze(1);
draw_hard_map();
goto check;
}
void check( void )
{
check:
&place = &rock_placement;
if (&place >= 1000)
{
if (&rock == 4)
{
sp_x(¤t_sprite, 513);
&junk = is_script_attached(&hole);
sp_script(&hole, "");
}
}
&place -= 1000;
if (&place >= 100)
{
if (&rock == 3)
{
sp_x(¤t_sprite, 243);
sp_script(&hole, "");
}
}
&place -= 100;
if (&place >= 10)
{
if (&rock == 2)
{
sp_y(¤t_sprite, 286);
sp_script(&hole, "");
}
}
&place -= 10;
if (&place >= 1)
{
if (&rock == 1)
{
sp_x(¤t_sprite, 507);
sp_script(&hole, "");
}
}
draw_hard_map();
}
Okay, I have little idea what you're talking about in the beginning of your post. It looks like you're dong something with various rocks being pushed, but other than that, I'm having a hard time understanding what this script is supposed to do, or what exactly is wrong. Change is a very inexact word.
Despite that, you mentioned something about the problem being fixed after you leave the room and come back. This makes me think you should follow a good rule of thumb and use preload_seq(158) at the beginning of main. This preloads the sprites created in this script and will may help you avoid many weird problems that sometimes occur when creating sprites through scripting.
Despite that, you mentioned something about the problem being fixed after you leave the room and come back. This makes me think you should follow a good rule of thumb and use preload_seq(158) at the beginning of main. This preloads the sprites created in this script and will may help you avoid many weird problems that sometimes occur when creating sprites through scripting.
Ok. My DinkC Editor didn't find any errors, but it found some warnings. One of them is that &rock_placement wasn't declared in this script, so I assume that this is a global variable.
The second one, which is pretty serious, is that you should use "{" after an if statement.
From the DinkC Reference:
However, there is one critical error. This does not work for anything involving variables.
void talk(void)
{
int &temp = 0;
// This will not work!!
if (&life == &lifemax)
&temp = 1;
}
To properly assign variables in if statements, you must use the curly braces.
void talk(void)
{
int &temp = 0;
// This works fine.
if (&life == &lifemax)
{
&temp = 1;
}
}
I noticed that you used several times, expressions like this one:
if (&place >= 1000)
&place -= 1000;
The second one, which is pretty serious, is that you should use "{" after an if statement.
From the DinkC Reference:
However, there is one critical error. This does not work for anything involving variables.
void talk(void)
{
int &temp = 0;
// This will not work!!
if (&life == &lifemax)
&temp = 1;
}
To properly assign variables in if statements, you must use the curly braces.
void talk(void)
{
int &temp = 0;
// This works fine.
if (&life == &lifemax)
{
&temp = 1;
}
}
I noticed that you used several times, expressions like this one:
if (&place >= 1000)
&place -= 1000;
Also, sp_script does not work very well.
&place is supposed to be subtracted from. It is a temporary variable for &rock_placement. &rock_placement is being used for 4 separate values (one for each digit).
I did notice however that I need to move those &placement -= 1000 (-= 100 ; -=10) into the if statements though (in th check procedure)
Woops
Lol that appears to have fixed the script. I was about to put brackets for what cypry said, but it works without doing that for some reason. I hate brackets.
BTW: I removed the "&junk = is_script_attached(&hole);" line. I was ending it by calling a procedure to the &hole sprite before, but I recently realized that all I needed was to tell the primary sprite to change the script of the &hole sprite.
I did notice however that I need to move those &placement -= 1000 (-= 100 ; -=10) into the if statements though (in th check procedure)
Lol that appears to have fixed the script. I was about to put brackets for what cypry said, but it works without doing that for some reason. I hate brackets.
BTW: I removed the "&junk = is_script_attached(&hole);" line. I was ending it by calling a procedure to the &hole sprite before, but I recently realized that all I needed was to tell the primary sprite to change the script of the &hole sprite.
Striker:
I was trying to be vague in what it's supposed to do. Sorry it was not clear enough, but if you still want to know. Yes you were correct that the sprite is a rock. Actually, the same script is placed on four rocks. The created sprite is &hole, well it's a hole. &hole was created by the primary sprite (the rock) and it does it's thing, which I won't say. I found out that the script would only do their check procedures if all the rocks were pushed (&rock_placement would be 1111). I now know that this happened because the variables in the check procedure weren't subtracted in their if statements, but in the main check procedure brackets instead. That causes them to subtract always, so the variable would have to be = 1111 (I think) for it to work properly. Yes, it was a dumb mistake, but I was really annoyed due to what &hole actually does
Also, I don't need to preload the sprite created because it's a detail sprite thats "loaded now" in the ini.
I was trying to be vague in what it's supposed to do. Sorry it was not clear enough, but if you still want to know. Yes you were correct that the sprite is a rock. Actually, the same script is placed on four rocks. The created sprite is &hole, well it's a hole. &hole was created by the primary sprite (the rock) and it does it's thing, which I won't say. I found out that the script would only do their check procedures if all the rocks were pushed (&rock_placement would be 1111). I now know that this happened because the variables in the check procedure weren't subtracted in their if statements, but in the main check procedure brackets instead. That causes them to subtract always, so the variable would have to be = 1111 (I think) for it to work properly. Yes, it was a dumb mistake, but I was really annoyed due to what &hole actually does
Also, I don't need to preload the sprite created because it's a detail sprite thats "loaded now" in the ini.
Here's a new script. I'm pretty sure this isn't another dumb mistake. This script is supposed to create a sprite, &barr, but it doesn't. I've tested over and over and it seems the x, y cords get screwed up. I've tried reverting them back to Dink's x and y right before the create_sprite command, but that still doesn't work. If it helps, the x cord ends up being 998, and the y cord ends up being 999.
Note: &bar_var; and &check_vars; are globals.
Problem solved, external error, doh!
void main( void )
{
freeze(1);
if (sp_dir(1, -1) == 1) sp_dir(1, 2);
if (sp_dir(1, -1) == 3) sp_dir(1, 2);
if (sp_dir(1, -1) == 7) sp_dir(1, 8);
if (sp_dir(1, -1) == 9) sp_dir(1, 8);
int &xxx = sp_x(1, -1);
int &yyy = sp_y(1, -1);
if (sp_dir(1, -1) == 2) { &xxx -= 1; &yyy += 19; } if (sp_dir(1, -1) == 4) { &xxx -= 28; &yyy -= 6; } if (sp_dir(1, -1) == 6) { &xxx += 25; &yyy -= 3; } if (sp_dir(1, -1) == 8) { &xxx -= 1; &yyy -= 14; }
sp_brain_parm(&check_vars, 10);
sp_brain(&check_vars, 12);
//&xxx = 100;
//&yyy = 100;
int &barr = create_sprite(&xxx, &yyy, 0, 39, 1);
sp_script(&barr, "bexplo");
int &crap_map = &player_map;
&crap_map *= 1000000;
int &crap_x = sp_x(&barr, -1);
&crap_x *= 1000;
int &crap_y = sp_y(&barr, -1);
&bar_var = 0;
&bar_var += &crap_y;
&bar_var += &crap_x;
&bar_var += &crap_map;
wait(1);
kill_this_item("s5-barrel");
unfreeze(1);
kill_this_task();
}
Note: &bar_var; and &check_vars; are globals.
Problem solved, external error, doh!
void main( void )
{
freeze(1);
if (sp_dir(1, -1) == 1) sp_dir(1, 2);
if (sp_dir(1, -1) == 3) sp_dir(1, 2);
if (sp_dir(1, -1) == 7) sp_dir(1, 8);
if (sp_dir(1, -1) == 9) sp_dir(1, 8);
int &xxx = sp_x(1, -1);
int &yyy = sp_y(1, -1);
if (sp_dir(1, -1) == 2) { &xxx -= 1; &yyy += 19; } if (sp_dir(1, -1) == 4) { &xxx -= 28; &yyy -= 6; } if (sp_dir(1, -1) == 6) { &xxx += 25; &yyy -= 3; } if (sp_dir(1, -1) == 8) { &xxx -= 1; &yyy -= 14; }
sp_brain_parm(&check_vars, 10);
sp_brain(&check_vars, 12);
//&xxx = 100;
//&yyy = 100;
int &barr = create_sprite(&xxx, &yyy, 0, 39, 1);
sp_script(&barr, "bexplo");
int &crap_map = &player_map;
&crap_map *= 1000000;
int &crap_x = sp_x(&barr, -1);
&crap_x *= 1000;
int &crap_y = sp_y(&barr, -1);
&bar_var = 0;
&bar_var += &crap_y;
&bar_var += &crap_x;
&bar_var += &crap_map;
wait(1);
kill_this_item("s5-barrel");
unfreeze(1);
kill_this_task();
}










