Weird script problem
April 8th 2006, 08:31 PM
Neo
Take a look at this:
void main( void )
{
int &counter = 0;
ing &wait;
loop:
int &randx = random(630, 20);
int &randy = random(440, 30);
int &en = create_sprite(&randx, &randy, 9, 349, 1);
sp_base_walk(&en, 340);
sp_speed(&en, 3);
sp_timing(&en, 66);
&counter += 1;
if (&counter < 10)
{
goto loop;
}
// pool:
// speak();
// &wait = random(1000, 1000);
// wait(&wait);
// goto pool;
}
void speak( void )
{
int &crap = get_rand_sprite_with_this_brain(9, ¤t_sprite);
say_stop_npc("I'm talking!", &crap);
}
This script is about to create ten people, and then make a routine that every 1-2 seconds one of them will say "I'm talking!".
But it doesn't work.
If I leave this script as it looks above, it works. It makes ten wandering guys.
But if I uncomment commented lines (which should enable the script to randomly call speak() function), it doesn't work properly. There are not TEN people, but ONE HUNDRED (Ack!), and it happens that TEN of them at the same time say "I'm talking!".
Weird. I think that this may be bug either in my code or in DinkC engine either...
void main( void )
{
int &counter = 0;
ing &wait;
loop:
int &randx = random(630, 20);
int &randy = random(440, 30);
int &en = create_sprite(&randx, &randy, 9, 349, 1);
sp_base_walk(&en, 340);
sp_speed(&en, 3);
sp_timing(&en, 66);
&counter += 1;
if (&counter < 10)
{
goto loop;
}
// pool:
// speak();
// &wait = random(1000, 1000);
// wait(&wait);
// goto pool;
}
void speak( void )
{
int &crap = get_rand_sprite_with_this_brain(9, ¤t_sprite);
say_stop_npc("I'm talking!", &crap);
}
This script is about to create ten people, and then make a routine that every 1-2 seconds one of them will say "I'm talking!".
But it doesn't work.
If I leave this script as it looks above, it works. It makes ten wandering guys.
But if I uncomment commented lines (which should enable the script to randomly call speak() function), it doesn't work properly. There are not TEN people, but ONE HUNDRED (Ack!), and it happens that TEN of them at the same time say "I'm talking!".
Weird. I think that this may be bug either in my code or in DinkC engine either...
Complicated! It doesn't look like there's a reason to not just replace all the commented out lines with
set_callback_random("speak",1000,1000);
set_callback_random("speak",1000,1000);
Its a bad idea to int any vaiable within a loop, because they may keep old values. Try int all values before the loop.
also you have ing &wait instead of int &wait.
also you have ing &wait instead of int &wait.
There can't be one hundred people in the same screen, because the sprite limit it's 99.
Try to initialize all the variables at the begining of the script.
Try to initialize all the variables at the begining of the script.
Well, maybe then there are less than 100 sprites, nevertheless the screen is full of them and many of them say "I'm talking" at the same time.
I can't use set_callback_random(); because when I use it, it just makes ONE sprite to speak, and then dies; no one says nothing at all
I can't use set_callback_random(); because when I use it, it just makes ONE sprite to speak, and then dies; no one says nothing at all
Why even use a separate procedure? Custom procedures (and calling of procedures) is a tricky thing in DinkC. It creates a new instance of the script, instead of 'jumping' to it.
You might try (instead of the commented lines):
pool:
&crap = get_rand_sprite_with_this_brain(9, ¤t_sprite);
say_stop_npc("I'm talking!", &crap);
&wait = random(1000, 1000);
wait(&wait);
goto pool;
Also, as Ric said, you should put 'int &crap' and 'int &en' before the loops. Using int in a loop can be tricky. BUT when you keep using the speak() proc, then you do need to 'int &crap'. This has to do with those different script-instances (local variables don't transfer).
You might try (instead of the commented lines):
pool:
&crap = get_rand_sprite_with_this_brain(9, ¤t_sprite);
say_stop_npc("I'm talking!", &crap);
&wait = random(1000, 1000);
wait(&wait);
goto pool;
Also, as Ric said, you should put 'int &crap' and 'int &en' before the loops. Using int in a loop can be tricky. BUT when you keep using the speak() proc, then you do need to 'int &crap'. This has to do with those different script-instances (local variables don't transfer).
There can only be 99 sprites placed on a screen in the editor. The limit of sprites created via script is not 99... there may not be a limit at all, I haven't looked into it too much.
April 9th 2006, 12:10 PM
Neo
Ok, it seems that magicman's solution worked. Thank you!
Also, redink1 is right, script can create more than 99 sprites on screen...
Also, redink1 is right, script can create more than 99 sprites on screen...