How do I maintain pinned objects within functions

Get help using Construct 2

Post » Sat May 16, 2015 4:00 pm

Why do pinned objects become unpinned in functions? Let me explain by example.

I create two objects. Let's call them Donkey and Tail. Then I pin Tail to Donkey so that moving or rotating Donkey also causes Tail to move and rotate along with it. Great. So far so good.

OK, let's create a function to move any instance of any Donkey that is spawned. We create a function that is intended to handle all movement of any spawned Donkey. Let's call the function "MoveDonkey", and give it two parameters. The first parameter contains the UID of any given Donkey. The second parameter is the distance to move that Donkey along the X axis. So, to move Donkey, I simply call the function MoveDonkey and pass in the parameter Donkey.UID in Param(0) and an integer value representing how far I wish to move Donkey in Param(1). Within the MoveDonkey function I reference the Donkey instance by calling Donkey's "Pick instance with UID Function.Param(0)". Once picked, I can use Set X on Donkey to Donkey.X+Param(1). This moves Donkey forward or back along the X axis. Works great. So far so good.

Here's the problem. Inside the MoveDonkey function, Tail has become unpinned from Donkey. Outside of the function, when I move Donkey the Tail moves along with it. But inside the function, the Tail no longer moves with Donkey. It has become unpinned within the context of the function. Why is that and how do I resolve this problem? Do I need to re-pin the Tail on the Donkey within functions?

EDIT: After further testing, I can confirm this is nothing to do with functions. Forget everything I said about functions. The problem occurs with the "Pick by unique ID" event. Apparently, using this event to pick an object and then moving or rotating that object will not move or rotate objects pinned to it. Still don't know why.
B
5
Posts: 2
Reputation: 231

Post » Sat May 16, 2015 5:03 pm

Are you picking the correct donkey in the event where you pin the tail? If not maybe you pin the tail to the wrong donkey? Just a guess...
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,630

Post » Sat May 16, 2015 5:48 pm

Yes. That was the problem. Due to sloppiness, I had two Donkey instances created and I was moving the one that did not already have a tail pinned to it. Rookie mistake.

In C2, knowing which instance of an object your events are manipulating is not always intuitive. There's no distinction between an object and an instance of an object. It's just called "Donkey". That may get you one Donkey object, several Donkey objects, or none depending on your context. At least, that's my understanding thus far. Please correct me if I'm wrong.
B
5
Posts: 2
Reputation: 231


Return to How do I....?

Who is online

Users browsing this forum: bluesun66, plinkie and 3 guests