Ineracting sprites
Yo, it's me again with a question:
I create a sprite with a script, say gold500.
When Dink does something like punching a different sprite with a different script, is there any way of changing the gold's frame via that scripts void (hit)?
I found examples and know how to change the frame, but not when there are two different scripts.
I create a sprite with a script, say gold500.
When Dink does something like punching a different sprite with a different script, is there any way of changing the gold's frame via that scripts void (hit)?
I found examples and know how to change the frame, but not when there are two different scripts.
Sure. I'd do it by giving the gold a unique brain- say 49.
Then in the hit procedure of the different sprite run &variable = get_rand_sprite_with_this_brain(49, 0);
sp_pframe(&variable, newframe);
That should work.
If you use get_sprite_with_this_brain() without a variable I'm unsure whether or not it will return a value in &result.
Then in the hit procedure of the different sprite run &variable = get_rand_sprite_with_this_brain(49, 0);
sp_pframe(&variable, newframe);
That should work.
If you use get_sprite_with_this_brain() without a variable I'm unsure whether or not it will return a value in &result.
Yes, no problem at all. What you need is the sprite number. Then you can just use that in sp_frame.
Getting the sprite number may be done in several ways. If your sprite doesn't need a special brain, you can use that as was suggested. If it does, then you can use the target sprite's main function to store its ¤t_sprite into a global, which you then use in your other script.
Finally, what I would do, is use sp() on the editor number of the sprite. However, this requires you to know the editor number, and I'm not sure how constant that is with other editors. In my editor, it is not constant at all, but I can refer to the sprite by name, and it will fill in whatever editor number it has generated for it (as in sp_frame (sp ("chest"), 4); ) . AFAIK in other editors doing something similar would be very fragile, but I might be wrong about that. Actually, I'm sure that in regular dinkedit it would work fine; it will not rearrange the sprite editor numbers, so it isn't fragile at all; just unreadable. But that's DinkC for you.
Getting the sprite number may be done in several ways. If your sprite doesn't need a special brain, you can use that as was suggested. If it does, then you can use the target sprite's main function to store its ¤t_sprite into a global, which you then use in your other script.
Finally, what I would do, is use sp() on the editor number of the sprite. However, this requires you to know the editor number, and I'm not sure how constant that is with other editors. In my editor, it is not constant at all, but I can refer to the sprite by name, and it will fill in whatever editor number it has generated for it (as in sp_frame (sp ("chest"), 4); ) . AFAIK in other editors doing something similar would be very fragile, but I might be wrong about that. Actually, I'm sure that in regular dinkedit it would work fine; it will not rearrange the sprite editor numbers, so it isn't fragile at all; just unreadable. But that's DinkC for you.
