The Dink Network

Weird script problem

April 8th 2006, 08:31 PM
anon.gif
Neo
Ghost
 
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, &current_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...
April 8th 2006, 09:39 PM
spike.gif
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);
April 8th 2006, 10:27 PM
pq_frog.gif
Ric
Peasant Canada
 
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.
April 9th 2006, 06:34 AM
knightg.gif
cypry
Peasant Male Romania
Chop your own wood, and it will warm you twice. 
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.
April 9th 2006, 07:49 AM
goblins.gif
Neo
Peasant Male Poland
He Who Would Steal The Flame Must Die 
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
April 9th 2006, 08:22 AM
custom_magicman.gif
magicman
Peasant Netherlands steam duck
Mmmm, pizza. 
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, &current_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).
April 9th 2006, 09:18 AM
custom_king.png
redink1
King Male United States xbox steam bloop
A mother ducking wizard 
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
anon.gif
Neo
Ghost
 
Ok, it seems that magicman's solution worked. Thank you!

Also, redink1 is right, script can create more than 99 sprites on screen...

April 9th 2006, 05:01 PM
goblinm.gif
I read somewhere that the total sprite limit was 299.