The Dink Network

Another problem about external

June 28th 2005, 04:02 AM
knightg.gif
cypry
Peasant He/Him Romania
Chop your own wood, and it will warm you twice. 
In my DMOD, a sprite runs a script, where I put the following command:
external("dot1", "change");
to change the frame of another sprite. The "change" procedure is the following:

void change(void)
{
Playsound(17,22050,0,0,0);
sp_pframe(&d1, 2);
&s1 = 10;
}

in the main procedure of dot1, I put the command : &d1 = &current_sprite , and &d1 is a global variable.
If I let the &current_sprite, the sprite who calls the external(...) changes.(I guess he is the current sprite in that moment)
Sometimes, it does the specified action, but sometimes it changes the frame for another dot, or sprite (I have 9 dots). I guess the sprite number changes.
Can someone tell me how to fix this bug?
June 28th 2005, 11:50 AM
goblinm.gif
First, you have nine globals for this? That's a lot, considering the variable limit.

Second, that is honestly one of the weirdest bugs I've ever seen. In my experience, sprite numbers are steady. Put the &d1 = &current_sprite at the very beginning of the main procedure of dot1, (before any create_sprite or sp_script commands or whatever) and see if that helps...
June 28th 2005, 11:59 AM
goblinm.gif
I had a problem once with my stair drawing procedure (which is attached to a bench and draws a lot of other benches based on the position of the one it's attached to.) It would draw in the stuff it was supposed to, then start putting stuff in the upper left hand corner. Since that's the home of the 0-sprite, I figured that &current_sprite had to become 0. But when I added say("&current_sprite", &junk); commands (&junk was the number retrieved from create_sprite) to the script, ALL of the correctly drawn benches said 42 instead of 2. The benches in the upper left said 0. So, yeah, the bug was easy to fix, I just had the thing return when &current_sprite was 0... but the point is that &current_sprite assumes very strange values after a create_sprite.
June 28th 2005, 12:06 PM
custom_magicman.gif
magicman
Peasant They/Them Netherlands duck
Mmmm, pizza. 
Did you create the dots with create_sprite() or did you put 9 dots on the screen with the editor. In any case, make sure they have different scripts.
June 28th 2005, 04:44 PM
goblinm.gif
The "best" way to do this is with get sprite with this brain. So you'd have dot1.c:

void main( void )
{
//This is the same behavior as brain 0
sp_brain(&current_sprite, 501);
}

and then:
void change( void )
{
int &crap = get_sprite_with_this_brain(501, 0);
if (&crap > 1)
{
sp_frame(&crap, 2);
//just changing frame to 2 does nothing if seq isn't set.
//but evidently this isn't a problem
}
}
June 28th 2005, 04:45 PM
goblinm.gif
Bah.

As I commented, you need to set the seq. So you'd have to add that to the main procedure. Sorry.
June 29th 2005, 01:42 PM
knightg.gif
cypry
Peasant He/Him Romania
Chop your own wood, and it will warm you twice. 
This is the entire script for dot1 The rest are the same)

void main(void)
{
sp_brain(&current_sprite, 14);
sp_touch_damage(&current_sprite, -1);
&d1 = &current_sprite;
}

void buttonon(void)
{
If (&s1 == 0)
sp_pframe(&current_sprite, 3);
}

void buttonoff(void)
{
If (&s1 == 0)
sp_pframe(&current_sprite, 1)
}

void click(void)
{
If (&s1 == 0)
{
Playsound(17,22050,0,0,0);
sp_pframe(&current_sprite, 3);
&s1 = 1;
external("move", "main");
}
}

void change(void)
{
Playsound(17,22050,0,0,0);
sp_pframe(&d1, 2);
&s1 = 10;
}

I want to make the game x-0(The game where you have a 3x3 board, and one plyer put X, and the other one 0, and you have to fill a line, collumn or diagonal with your sign) using DinkC.

The "change" procedure is called when computer moves.
Another question: how many global variables may I put?(I already have 23, and the program isn't finished yet)
June 29th 2005, 03:07 PM
goblinm.gif
The absolute variable limit is 250 or so, including both locals and globals.

In my case, that means a lot of lccals and very few globals. For others, it goes the other way.

Keep in mind that &mcounter is used in most enemy scripts, and weapons often use 5-10 variables. So (theoretically) if you'll have at most twenty monsters on the screen at a time, and considering the 20 or so engine-used globals, you could add about 140 and still be around two hundred. In practice... way fewer.

Edit: maybe you should find another way to do the the tic-tac-toe game... I don't see how you can tell which dot1 is being referenced for change(), unless you fiddle with &d1 elsewhere, in which case, moving the playsound line to the end of the change() procedure is the only thing I can think of that would help.