📧 Message Board Archive

A very weird bug I ran into...
I ran into a very odd bug recently.  I have something like this in the main of some of the sprites in my D-Mod:



void main(void)

{

if (&story == 5) sp_script(&current_sprite, "s1-town");

sp_brain(&current_sprite, 16);

sp_base_walk(&current_sprite, 560);

sp_speed(&current_sprite, 1);

}



However, when &story is 5, it will automatically run the void talk(void) of s1-town when the screen is loaded.  So I came up with this 'solution':



void main(void)

{

int &crap = 5;

(misc checking and setting of vars, will speak sometimes)

}



void talk(void)

{

if (&crap == 5)

{

&crap = 0;

return;

}

(talkandcrap)

}



But this is kind of a pain... has anybody else had this problem, or found a way to fix it?  I know I could just insert the stuff from s1-town right into the original script... but it is done for a reason not evident in the scripts.
Re: A very weird bug I ran into...
: I ran into a very odd bug recently. I have something like this in the main of some of the sprites in my D-Mod:



: void main(void)

: {

: if (&story == 5) sp_script(&current_sprite, "s1-

town");



: sp_brain(&current_sprite, 16);



: sp_base_walk(&current_sprite, 560);



: sp_speed(&current_sprite, 1);



: }





I don't know has it anything to do with this, but the bug could also be at th END of the script, right? I had a bug in Spy13 that after i had done the stuff of some of my voids it runned some other void, for example. I fixed it by simply putting return; in the end of the void.





Re: A very weird bug I ran into...
It IS weird.

Can you post the whole main procedure of S1-town so that we might find out if something is not quite right?





A "bug" (or not) that I found some time ago is not related to redink1's but also quite annoying. Local variables defined at main( void ) can be used in some other procedures in the same script but not in others. I don't know why.
Re: s1-town main source
Fine... I don't think it gives too much away :)

&battles is a global.



void main(void)

{

int &hold = sp_editor_num(&current_sprite);

int &crap = 5;

if (&hold != 0)

{

int &crp = editor_seq(&hold, -1);

}

if (&crp == 50)

{

&battles += 1;

editor_seq(&hold, 1);

}

if (&crp == 51)

{

&battles += 1;

editor_seq(&hold, 2);

}

if (&crp == 52)

{

&battles += 1;

editor_seq(&hold, 3);

}

if (&crp = 53)

{

freeze(1);

say_stop("'1To get off of this island, you must win 20 battles.", &current_sprite);

say_stop("'1The Escape Menu tells you how many you've won.", &current_sprite);

say_stop("'1Then go down under this town, and the Master may give you a bomb.", &current_sprite);

unfreeze(1);

editor_seq(&hold, 3);

}

if (&crp >= 50)

{

int &myx = sp_x(&current_sprite, -1);

int &myy = sp_y(&current_sprite, -1);

sp_x(1,&myx);

sp_y(1,&myy);

editor_type(&hold,8);

sp_kill(&current_sprite, 1);

}

}



void talk(void)

{

if (&crap == 5)

{

&crap = 0;

return;

}

{blah}

}
Re: s1-town main source
I don't know why talk procedure would run, but I do see several problems, although I don't know why it would end up something like that. I'm also curious that after you add "&crap = 5" in main, did the script work as you expect?



1.

int &hold = sp_editor_num(&current_sprite);

if (&hold != 0)

{

 int &crp = editor_seq(&hold, -1);

}



sp_editor_num gives EDITOR number; but I believe editor_seq should use sprite number instead.



==> int &crp = editor_seq(&current_sprite, -1);



2.

if (&crp == 50)

{

&battles += 1;

editor_seq(&hold, 1);

}



Are you trying to do --> If the sprite is seq 50 then change it to seq 1?!

It doesn't make much sense. I don't have any idea what seq 1 is anyway. Even if that is what you intend to do, you should use editor_seq(&current_sprite, 1); instead.



3.

if (&crp = 53)



should be

if (&crp == 53)



4.

editor_type(&hold,8);



should be

editor_type(&current_sprite, 8);

Re: s1-town main source
:  int &hold = sp_editor_num(&current_sprite);

:  if (&hold != 0)

:  {

:  int &crp = editor_seq(&hold, -1);

:  }

: sp_editor_num gives EDITOR number; but I believe editor_seq should use sprite number instead.

: ==> int &crp = editor_seq(&current_sprite, -1);



No, it was right how Redink1 had it.



:  if (&crp = 53)

: should be

:  if (&crp == 53)



You're certainly right about that part.



That probably isn't it though. I still can't figure out what's going wrong though. To see if I can clearify, first of all {blah} would really be several lines of speach, right? (for a second I thought it really said {blah} and was very confused.:o) Also in the real script, as opposed to your example with &story, under what condition does it run talk erroneously?
Re: s1-town main source
: That probably isn't it though. I still can't figure out what's going wrong though. To see if I can clearify, first of all {blah} would really be several lines of speach, right? (for a second I thought it really said {blah} and was very confused.:o) Also in the real script, as opposed to your example with &story, under what condition does it run talk erroneously?



Yes, (blah) would be various lines of speech or choice_start(), depending on the value of some global vars.



Here is a more detailed event of what happens:



Lets say there is a person, and he has a script called "s1-man" (the Main script you referred to).  He is a simple man... just like any other normal character (does not use Paul's Script Trick at all).  When &game (a global) is equal to 5 (which happens during certain circumstances), right when the screen is loaded it will run everything in the 'main' of "s1-town" (because of sp_script), and then proceed to run everything in 'talk' as well, requiring the workaround I have with &crap.  Talk works normally after the workaround (use space, and he talks up right away).  Its almost like there is a "talk();" in the main.



s1-man:
void main( void )

{

if (&game == 5) sp_script(&current_sprite, "s5-s01");

int &myrand;

sp_brain(&current_sprite, 16);

sp_base_walk(&current_sprite, 560);

sp_speed(&current_sprite, 1);

}



void talk( void )

{

if (&duck == 1)

{

say("I hate ducks", &current_sprite);

return;

}
s1-town:
void main(void)

{

int &hold = sp_editor_num(&current_sprite);

int &crap = 5;

if (&hold != 0)

{

int &crp = editor_seq(&hold, -1);

}

if (&crp == 50)

{

&battles += 1;

editor_seq(&hold, 1);

}

if (&crp == 51)

{

&battles += 1;

editor_seq(&hold, 2);

}

if (&crp == 52)

{

&battles += 1;

editor_seq(&hold, 3);

}

if (&crp == 53)

{

freeze(1);

say_stop("'1To get off of this island, you must win 20 battles.", &current_sprite);

say_stop("'1The Escape Menu tells you how many you've won.", &current_sprite);

say_stop("'1Then go down under this town, and the Master may give you a bomb.", &current_sprite);

unfreeze(1);

editor_seq(&hold, 3);

}

if (&crp >= 50)

{

int &myx = sp_x(&current_sprite, -1);

int &myy = sp_y(&current_sprite, -1);

sp_x(1,&myx);

sp_y(1,&myy);

editor_type(&hold,8);

sp_kill(&current_sprite, 1);

}

}



void talk(void)

{

if (&crap == 5)

{

&crap = 0;

return;

}

if (&global_is == 1)

{

say("'1Temporary Text.", &current_sprite);

return;

}

if (&global_on == 0)

{

say("'1Go away.", &current_sprite);

return;

}

freeze(1);

choice_start()

"Challenge Him"

"Leave"

choice_end()

if (&result == 2)

{

unfreeze(1);

return;

}

if (&crp == 0)

{

say_stop("'1You will not last.", &current_sprite);

editor_seq(&hold,50);

&emon = 1101;

}

if (&crp == 1)

{

say_stop("'1You've beaten me once, but not again!", &current_sprite);

editor_seq(&hold,51);

&emon = 1102;

}

if (&crp == 2)

{

say_stop("'1I was weak before, but now I am strong.", &current_sprite);

editor_seq(&hold,52);

&emon = 1201;

}

if (&crp == 3)

{

editor_seq(&hold,53);

&emon = 1201;

}



&oldmap = &player_map;

sp_x(1,370);

sp_y(1,350);

&player_map = 26;

load_screen(26);

draw_screen(26);

kill_this_task();

}
Re: s1-town main source
I'm still a little confused with the two scripts and how they interact... or if they do. But the line I bolding looks suspicious. Are you sure you can put things after an if like that? Or does the real script look that way?



: s1-man:


: void main( void )

: {

: if (&game == 5) sp_script(&current_sprite, "s5-s01");

: int &myrand;

: sp_brain(&current_sprite, 16);

: sp_base_walk(&current_sprite, 560);

: sp_speed(&current_sprite, 1);

: }

: void talk( void )

: {

: if (&duck == 1)

: {

: say("I hate ducks", &current_sprite);

: return;

: }
Re: s1-town main source
: I'm still a little confused with the two scripts and how they interact... or if they do. But the line I bolding looks suspicious. Are you sure you can put things after an if like that? Or does the real script look that way?



: : s1-man:




: : void main( void )



: : {



: : if (&game == 5) sp_script(&current_sprite, "s5-s01");



: : int &myrand;



: : sp_brain(&current_sprite, 16);



: : sp_base_walk(&current_sprite, 560);



: : sp_speed(&current_sprite, 1);



: : }



: : void talk( void )



: : {



: : if (&duck == 1)



: : {



: : say("I hate ducks", &current_sprite);



: : return;



: : }




Yeah, thats the original script, copied exactly.  Seth did some if statements like that in the original source, and I kind of picked up on it.  I'll try it with normal brackets, and see what happens.
Re: s1-town main source
: : int &hold = sp_editor_num(&current_sprite);

: : if (&hold != 0)

: : {

: : int &crp = editor_seq(&hold, -1);

: : }



: : sp_editor_num gives EDITOR number; but I believe editor_seq should use sprite number instead.



: : ==> int &crp = editor_seq(&current_sprite, -1);



: No, it was right how Redink1 had it.



You sure? The following are copied from DinkC help

 int &hold = sp_editor_num(&current_sprite);

 if (&hold != 0)

 {

// this was placed by the editor, lets make the barrel stay flat

  editor_type(&current_sprite, 3);

  editor_seq(&current_sprite, 173);

  editor_frame(&current_sprite, 4);

// type means show this seq/frame combo as background in the future

 }



In fact, I even don't know if editor_seq(&whatever, -1) would return any number. Why don't you just use sp_seq(&current_sprite, -1)?
Re: s1-town main source
: You sure? The following are copied from DinkC help



:  int &hold = sp_editor_num(&current_sprite);

:  if (&hold != 0)

:  {

: // this was placed by the editor, lets make the barrel stay flat

:   editor_type(&current_sprite, 3);

:   editor_seq(&current_sprite, 173);

:   editor_frame(&current_sprite, 4);

: // type means show this seq/frame combo as background in the future

:  }



Yeah can't trust everything you read in there (that's not the only mistake in there either)



Here's a counter example from dam-fire.c



-------

int &hold = sp_editor_num(&missile_target);



>8 snip 8<



if (&hold != 0)

{

 //this was placed by the editor, lets make the tree stay burned

 editor_type(&hold, 4);

 editor_seq(&hold, 20);

 editor_frame(&hold, 29);

 //type means show this seq/frame combo as background in the future

}

-------



: In fact, I even don't know if editor_seq(&whatever, -1) would return any number. Why don't you just use sp_seq(&current_sprite, -1)?



Like redink1 said, it's a trick I discovered. Basically you can store any non-negative number you wish in editor_seq and it won't do anything unless editor_type isn't 2, 3, 4 or 5. But it's a good way to store a value for that sprite without using a global because it's remembered even when Dink leaves the room or saves.
Re: s1-town main source
: : : int &hold = sp_editor_num(&current_sprite);



: : : if (&hold != 0)



: : : {



: : : int &crp = editor_seq(&hold, -1);



: : : }



: : : sp_editor_num gives EDITOR number; but I believe editor_seq should use sprite number instead.



: : : ==> int &crp = editor_seq(&current_sprite, -1);



: : No, it was right how Redink1 had it.



: You sure? The following are copied from DinkC help



:  int &hold = sp_editor_num(&current_sprite);



:  if (&hold != 0)



:  {



: // this was placed by the editor, lets make the barrel stay flat



:   editor_type(&current_sprite, 3);



:   editor_seq(&current_sprite, 173);



:   editor_frame(&current_sprite, 4);



: // type means show this seq/frame combo as background in the future



:  }



: In fact, I even don't know if editor_seq(&whatever, -1) would return any number. Why don't you just use sp_seq(&current_sprite, -1)?



Because I'm using Paul's Script Trick :)  I can't think of anyplace where its described... Paul will probably describe it to you.