Get current object & instance var

0 favourites
  • 5 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • Hey everyone,

    I have two things I want to acheive in order to make my code more modular when shooting some things through functions. If you know any one of these 2 following questions, I'll hugely appreciate (or point me in a direction). If you can answer both, even better :) Otherwise, any input is appreciated!

    1 - Getting the current object's name

    =====================================

    Say I'm overlapping an object called sign, can I get the name of that object (example "Sprite3") as in the pseudo-code below? :

    (forgive my code below, I don't have the preview or edit option with my limited privileges as new member)

    if { (isOverlappingObject == 'Sprite3') { setTxt("This object's name is: " & currentObjectName); } }

    2 - Getting the current object's instance var(s)

    =====================================

    This one is less important because I can always otherwise do if/elseif's to judge an object's instance variables, but as in my 1st question, when overlapping an object, is it possible to get a list of its instance variables?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I don't think you can get the object name, unless you have an instance variable which is the name of the object, but the question is why would you want that? If you overlap sprite3 it becomes the picked object so technically you could pull the instance variables from it with events and set text to those values.

  • [..] the question is why would you want that?

    The reason is I want text to popup in a 9-patch when you overlap certain objects like Signs, Doors, and maybe some other players. While all this is working quite fine, it becomes hard to maintain when you have 200+ events just for checking which sign type you're currently overlapping (I'm putting "door" and "other player" in the same category as "sign" just for the sake of the example) and then which particular sign. Ie.: Is it the 1st sign where you tell a hint, or the 50th in Level 30 where you're telling the player he needs object X to be able to perform a certain task.

    I know this is very doable in a more procedural fashion, listing

    if signID = 1, do this if signID = 2, do that [so on]

    AND have sub-checks checking if it's a door (using different design for the 9-patch), a sign or whatever. So having ONE function (which I did) handle all of that, and handling which is which all without a thousand if/elseif's seemed a more elegant solution (coming from a programmer's background like myself).

    Good news though is I fell upon "pick by evaluate" which then allows me to make direct reference to that object's instance variable value (which solves my problem for getting an object's instance var), and I put those 3 objects in the same family. I don't understand why "pick by evaluate", which to me seemed to be a trigger that will allow sub-events (those nested under) if their value is not 0, allows to then make direct reference to that (in this case) instance variable current value, but hey, I won't complain, it's solving 99% of my problem!

    If you overlap sprite3 it becomes the picked object so technically you could pull the instance variables from it with events and set text to those values.

    How would you go about that? The only thing I came across (still new to Construct) "pickedCount".

  • Well you would just need one event for this, when you overlap a sign i.e. player is overlapping sign, you set the text to sign.variable where the variable is the text to be displayed.

  • Well you would just need one event for this, when you overlap a sign i.e. player is overlapping sign, you set the text to sign.variable where the variable is the text to be displayed.

    Yah, for that scenario that would work (just tested it). Don't know why I wouldn't get my variable in my case, maybe because I had more than one instance variable? I don't know, will have to test that later. Thanks

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