The Dink Network

save_x and save_y

FIFO & Variables in DinkC

September 17th 2008, 06:06 PM
girl.gif
joshriot
Peasant United States
keep it real 
can anyone explain to me exactly what you need to do with emake.c in order to delete the save_x and save_y globals? there arent really any instructions that i can understand im pretty much confused as to what the author is talking about, other than that its a good file but any clarification please?
September 17th 2008, 06:37 PM
dinkdead.gif
You can use &current_sprite in emake.c because it's called using external() from a script that is attached to a sprite, so using globals is unnecessary.

Basically, think of emake.c as if it is attached to the sprite that just died.

Instead of carrying the x & y positions across in globals, just put sp_x(&current_sprite, -1); in emake.c instead of in the sprite's script and it will work.

Hope that makes sense
September 17th 2008, 07:23 PM
girl.gif
joshriot
Peasant United States
keep it real 
so just adding int &save_x = sp_x(&current_sprite); at the top of emake.c script alone would let you delete &save_x global, right?
September 17th 2008, 07:28 PM
dinkdead.gif
Yes I suppose so, if emake.c really is the only script that uses them. And you'd need to do it at the top of each procedure (medium, large etc), not just once for the whole script.
September 18th 2008, 04:41 PM
slayer.gif
rabidwolf9
Peasant Male United States steam
twitch.tv/rabidwolf9 
I'm not sure using &current_sprite in the external script would work, but you can carry over variables from the original script to the external script if it doesn't. I think you can carry over up to 8 variables this way.

//for the main script
int &this_x = sp_x(&current_sprite,-1);
int &this_y = sp_y(&current_sprite,-1);
external("emake","small",&this_x,&this_y);

//for the emake.c script
int &save_x = &arg1;
int &save_y = &arg2;

Edit: After testing I see that &current_sprite does in fact work with external (just as sparrowhawk said) so just ignore this post
September 21st 2008, 07:58 AM
fairy.gif
Someone
Peasant Male Australia
 
Yeah the tutorial is unclear in several parts.. but Sparrowhawk does know what I meant there.

It's a little funny that Seth went to so much trouble putting two lines in every enemy script and reserving two globals in order to save the position information across the transfer from the enemy script to emake... when really the transfer is a bit of an illusion and that information isn't lost in the first place. Calling a script with external() will use the same script number and that's all dink.exe cares about (not the script name).. hence why &current_sprite still works.

So:
put
int &save_x = sp_x(&current_sprite,-1);
int &save_y ...

at top of each emake function (small, medium, large I think they are called)
and you can del &save_x and &save_y.. you should also delete the 2 lines which involve &save_x/y from each enemy script die procedure.

Also, from memory, the newer versions of Prophecy of the Ancients don't have &save_x/y. Nexis used the (less efficient) strategy rabidwolf detailed in this thread. So that proves you can delete those variables (i.e. there are no internal calls to them, as that would crash dink.exe).