Can Function make my code more efficient?

0 favourites
From the Asset Store
Global plugin that allow for relatively easy and efficient implementation of an in-game inventory system
  • Thanks for the c3p, igortyhon. You've streamlined the code so well. I'm still learning a lot from it, even though some parts are a bit challenging for me. But I couldn't ask for anything better.

    Oosyrag, thanks for your response. I've been using C3 for quite some time, but I've never attempted these advanced concepts. Thanks to you and others, my understanding is becoming much clearer.

    I will attempt to replicate what igortyhon has efficiently done in just a few lines of code, whereas I took around 100 lines for the same task. Please pardon me if I ask any further basic questions in the future.

  • I still do not understand, why this function is not working.

  • Simply put, functions do not preserve picking from the event calling it, unless you pass that information as a parameter. So all the instances of button are being moved to the same position at the far right, overlapping each other, since there are no instances of the button being picked in the function event.

    One of the reasons when not to use a function unless you're doing something where a function specifically would benefit you.

  • If the function can't PICK on its own, that's why we include the comparison logic. But still, it's not honoring the comparison logic. It's a bummer, I thought the function parameter was designed to be used like this.

    I frequently come across this type of situation, and I had believed that functions could assist me in these scenarios using parameters. 😩

  • It can be. Just pass the uid of the picked instance as a parameter to the function, and add a pick by uid condition into the function.

    Again though, it's just extra steps that you don't need to take to do the same thing, more easily, by just putting the actions in a "for each" event. (Or a "repeat object.count" times as in the example, which is the same thing)

  • It can be. Just pass the uid of the picked instance as a parameter to the function, and add a pick by uid condition into the function.

    Just shake of learning, Could you be more specific,

    I tried many ways, yet couldn't figure it out.

    like

    + Touch: On touched AddButton

    -> System: Create object Button on layer 0 at (0, 0), create hierarchy: False,

    -> System: Set uid_gv to Button.UID

  • The "Pick by unique id" goes in the function, so that the function actions only apply to that instance of the object. You don't need a separate instance variable for it and you don't need to set the uid.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Like this? Still I am unable to do so 😔

  • Ok sorry, looks like you didn't need UID. You can pick by the instance variable as you originally intended -

    But here's how to use UID anyway if you were to do it that way.

  • While I'm at it, here's how I would do it

  • Thanks, Oosyrag sir. You've really helped me understand a lot better. :) :)

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