The Dink Network

Script created Sprite that can be commanded from multiple other scripts

April 30th 2020, 09:15 PM
knightgl.gif
Zeddexx
Peasant He/Him New Zealand
I'm pretty sure I'm worth atleast SIX goats... 
So basically made a script that creates a dude via the whole

int &dude = create_sprite

Thing but like say I want him to walk to dink when dink "clicks" on a bookcase over there as well as when he "clicks" on a chair over here?

Cuz obviously when the bookcase or chair scripts just have move_stop(&dude,blahblah);
It doesnt work since that separate script has no idea who or what &dude is.

How do I affect mr &dude from the chair and bookcase scripts?
April 30th 2020, 09:25 PM
spike.gif
You can make &dude a global variable. Then you could just do &dude = &current_sprite in the dude's script, and you could move him with move_stop(&dude, blah blah blah) from the bookshelf's script.

Alternatively, if the dude is the only sprite on the screen with a specific brain (such as 9 or 16), or you give him a custom brain, getting his sprite from the bookshelf script is as easy as:

int &dude = get_sprite_with_this_brain(9,0)
move_stop(&dude, blah blah blah)

Even if there are multiple sprites with the same brain on the screen, it's possible to single out the dude by giving him some unique property that other sprites don't have and looking for that in the bookshelf script. That's a little more complicated, though, so I won't go into it unless that's needed. =)
April 30th 2020, 10:11 PM
knightgl.gif
Zeddexx
Peasant He/Him New Zealand
I'm pretty sure I'm worth atleast SIX goats... 
So like make &dude a global variable in MAIN?

Then hows the syntax for that last bit?

&dude = &current_sprite; ?

EDIT:
Btw
Im using Also windinkedit plus 2 and it wont save properly? I put a Sprite down and then save, exit, load back up and proof it's gone.

EDIT2: Yep nothing I do on windinkedit will save after I exit.
April 30th 2020, 10:32 PM
spike.gif
So like make &dude a global variable in MAIN?

Yep. In main.c do:

make_global_int("&dude",0)

Them in the script where you create the dude:

&dude = create_sprite(blah blah blah)

Then in the bookshelf script when you want to move the dude, you just move &dude:

move_stop(&dude, blah blah blah)

Im using Also windinkedit plus 2 and it wont save properly? I put a Sprite down and then save, exit, load back up and proof it's gone.

Can't help you there. (I'm a Dinkedit purist if anything. =)) What operating system are you using, and where is Dink located? (It could be a permission error, where Windikedit isn't allowed to save changes to files in the Dink folder)
April 30th 2020, 10:37 PM
knightgl.gif
Zeddexx
Peasant He/Him New Zealand
I'm pretty sure I'm worth atleast SIX goats... 
Ahhhhhh yes I think it very well may be a permission error, thank ye! you sexy beast

EDIT: that was indeed why it wasnt saving, ran as admin and I can save just fine.
You are the sexiest.

Now to see if I can get &dude off his ass.
April 30th 2020, 10:53 PM
pq_knight.gif
ExDeathEvn
Peasant He/Him New Zealand rumble
"Skinny Legend" 
Original Dink uses &temphold through &temp4hold (or maybe 5), though they may not be added automatically in the skeleton you use.
Outside of the area involving the sprite you're setting up to control, you can re-use the same global variable to label sprites so other scripts can send some instructions to 'em, I believe.
April 30th 2020, 11:05 PM
knightgl.gif
Zeddexx
Peasant He/Him New Zealand
I'm pretty sure I'm worth atleast SIX goats... 
Thanks muchly guys, I instead realized that the orginal game had a similar script so I studied it and realized I could use the sp ( ) command to just command a Sprite based on its screen number. Was totally easy.

(I'm referring to the farmer that tells you off for trying to go upstairs to see libby)

But its probably thanks to yall that I thought of it so ur all just as sexy.

And long time no see by the by
May 1st 2020, 07:32 PM
duck.gif
toof
Peasant He/Him
I disagree. 
I'm probably mistaken, but cant you get sprite based on sprite number? Or you can use screen variables
May 1st 2020, 08:27 PM
knightgl.gif
Zeddexx
Peasant He/Him New Zealand
I'm pretty sure I'm worth atleast SIX goats... 
Ya that's what I ended up doin. Crazy simple but I didnt even realize it was a thing.
May 2nd 2020, 11:13 AM
spike.gif
Getting sp() works, but I myself stopped using sp() at some point, because the sprite numbers have an annoying habit of changing as long as the screen is still being worked on. Nothing worse than decorating and prettifying a screen, only to have the shopkeeper's script attach to a hatrack because of it.
May 2nd 2020, 07:08 PM
knightgl.gif
zeddexx
Peasant He/Him New Zealand
I'm pretty sure I'm worth atleast SIX goats... 
Oof, I'll keep that in mind.

Yeah I looked into my unfinished dmod the other day for nostalgia but got a huge burst of motivation from lookin through it. I've been working on it every day all day since lol.

All this free time from isolation

forgot how much fun it was to work on a dmod.
May 2nd 2020, 10:53 PM
custom_robj.png
Robj
Jester He/Him Australia
You feed the madness, and it feeds on you. 
"Getting sp() works, but I myself stopped using sp() at some point, because the sprite numbers have an annoying habit of changing as long as the screen is still being worked on. Nothing worse than decorating and prettifying a screen, only to have the shopkeeper's script attach to a hatrack because of it."

Not sure how it works in dinkedit because I havent used it for a while but in Windinkedit, I use sp all the time.

The number of a sprite will only change if you pick it up and put it back down in the editor, after deleting a sprite with a lower sprite number than the one you moved. This is because when you put down a sprite in the editor, it defaults to the lowest available sprite number. So either don't move it, or, if you haven't deleted any sprites (or you have and you've already placed down more sprites to replace the deleted ones), it'll be fine, because there's no free sprite number lower than the one currently assigned to it.

Best thing is to just check the sprite number of the sprite after moving it to see if it's the same... in windinkedit you can hold the 'i' key to show all sprite numbers, or enable sprite info on mouse hover, and just mouse over the sprite to view the number.

-------------------------------------------------------------------------

If you don't want to use sp, and don't want to waste global variables your other options are:

- Use a fake brain (you can assign a fake brain to the sprite, such as brain 20). And then retrieve the brain 20 sprite from the other scripts and store it in a local variable.

- save the sprite in a sp_custom key attached to one "control" sprite that has a fake brain, with this method, you can access as many sprites as you want, and only have to assign one fake brain to control them all. The way this works is to set a sprite to fake brain 20 for example. And then in the script of ANY sprite that you want to be able to access, get it to retrieve the brain 20 sprite, and then store itself in a unique sp_custom key attached the fake brain sprite. Then to access it, you just do the same thing, but retrieve the sp_custom key instead.
.... if that makes sense. It's a bit of run around, but it works well for certain scenarios.