How do I maintain pinned objects within functions

0 favourites
  • 3 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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...

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)