Knuckle Cracker

Creeper World 3 => The Coder's Corner => Topic started by: Flabort on July 30, 2014, 06:30:58 PM

Title: Help with a mouse-over code
Post by: Flabort on July 30, 2014, 06:30:58 PM
Due to critiques in some of my maps, I find myself requiring a CRPL code that I can't figure out myself.

How would you make a connecting line show up between two cores when you mouse-over either of them, when one is created by the other?

Title: Re: Help with a mouse-over code
Post by: ParkourPenguin on July 30, 2014, 09:21:35 PM
If the mouse is over either the parent core or the child core, the child core can create an image at the midpoint between them, scale it to fit the distance between them, and then rotate it so that it appears as if both cores are connected by that image.

I've attached a couple scripts that show this off. "ParentCore.crpl" only makes a few CRPL cores and attaches the other script, "ChildCore.crpl", to them. "ChildCore.crpl" is the thing that actually does the work.

Also attached is an image I made that's used to connect the two cores. Since it's white, it's easy to modify it's color via SetImageColor.

I hope this helps!  :D
Title: Re: Help with a mouse-over code
Post by: Flabort on July 30, 2014, 10:22:24 PM
OK, so I can modify my own script to attach your script to the child, and that will form lines like I wanted?

Perfect! Thanks. I'll test it out in a moment, just have to modify your script to eliminate any warp notation :P

[Nothing wrong with warp, I just think it looks cleaner and it makes more sense without any ()s :P]
Title: Re: Help with a mouse-over code
Post by: ParkourPenguin on July 30, 2014, 10:59:38 PM
All you should have to do is add that child script to whatever CRPL cores you want to, then just make sure the variable parentUID is set to the correct UID of that core's parent.

You can do that by either telling it directly what the UID of its parent is via the input variable of the child script, or you can set it remotely with another CRPL core by using SetScriptVar. Of course, you'll need the UID of the child core to use SetScriptVar, but you can get that pretty easily with GetUnitAt (you could also use GetCoresWithVar for more flexibility depending on your needs).

I've never experimented with one CRPL core having 2+ scripts on it at once, but I think it should work out like that. I don't see why it wouldn't.
Title: Re: Help with a mouse-over code
Post by: Flabort on July 30, 2014, 11:08:54 PM
I definitely have used cores with multiple scripts; I use one script to act as the (flip) emitter, and one script for each child to spawn.
When the parent core spans it's child, it attaches the slip emitter script that I use, and sets it's own ID into the child's memory (so the slip script works) while remembering it's own ID; with appropriate modification, it should also attach your script to the child and let your script know which ID to use.

I've had parent cores with 5 scripts on them before as a result of my Create Child method of Slip Emitters.
Title: Re: Help with a mouse-over code
Post by: Flabort on July 30, 2014, 11:25:04 PM
OK, the parent and child cores are behaving as expected, but...
The line is not appearing when I mouse over them.

Attached is a test map, where you can see it not working. Put it into your editor to see the scripts attached.
Title: Re: Help with a mouse-over code
Post by: ParkourPenguin on July 31, 2014, 12:41:42 AM
Quote from: Flabort on July 30, 2014, 11:25:04 PM
OK, the parent and child cores are behaving as expected, but...
The line is not appearing when I mouse over them.

Attached is a test map, where you can see it not working. Put it into your editor to see the scripts attached.

Typo. In SlipEmitSetv2.txt, you store the UID into "child", while later on you reference it as "Child" when you try to set the ParentUID. It's case sensitive, so try making that change, and it should work.

Also, in SlipEmitasChild.crpl, you forgot to give CONST_CANREQUESTAMMO a value on line 9. setUnitAttribute is taking an item from an empty stack as is.

On an unrelated note, however, why did you make SlipEmitSetv2 a text file? How does CW3 even recognize that as a script?
Title: Re: Help with a mouse-over code
Post by: Flabort on July 31, 2014, 01:01:11 AM
Typo fixed, and it works!  ;D Thank you so much for your help.

Typo fixed. I meant to make that FALSE, and it's FALSE by default, but I didn't want to take chances. It worked before without it, but better safe than sorry, thank you!

I dunno. I forgot to make it .crpl, and the compiler seems to accept it.