How do I pick instance variable of one sprite in family?

0 favourites
  • 12 posts
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • Shortest version of this question possible. How can I add 1 to a particular instance variable of the sprite I've selected?

    There are 3 sprites in the same family, all with instance variable: Food. I want one of the sprites to get +1 food and somewhere show this sprite has ## food now and the other two sprites have 0.

    How?

    I've spent 2.5 hours watching C3 Youtube vids, tutorials, backwards engineering C3 built games and I don't get it. Patience with explanation is appreciated.

  • wackytoaster.at/parachute/picking.c3p

    Here's a basic setup. Keep in mind that there are countless ways to "pick" your instance and it's up to you to find out what your game needs. Here's some links so you understand what I did.

    construct.net/en/make-games/manuals/construct-3/interface/layout-view

    Picking instances

    construct.net/en/make-games/manuals/construct-3/plugin-reference/common-features/common-conditions

    construct.net/en/make-games/manuals/construct-3/system-reference/system-conditions

    Things like "compare instance variable" will also pick all instances that match. E.g. Instance variable > 5 will pick all instances where food > 5 or compare X < 100 will pick all instances that are X < 100 on the layout.

    And obviously you can chain picking to filter out more and more instances until you are left with one (or more if you need)

    E.g. pick instance variable > 5, pick instance variable < 10, pick lowest

    Will first pick all instances where food > 5, then from those all where food < 10 and than from those it picks the one lowest on food.

  • Your reply and contained information ended up being a huge help! When I saw your name pop-up as viewing the post, I knew help was on the way. Thank you!

    What I was struggling to do was use the right "terms/code" to find the value of the instance variable of one of the sprites. Through sheer luck (and His guidance), I found the right coding.

    With what you provided, I'm going to expand on the game now instead of spending hours figuring out which way to hold the mouse and keyboard.

    I did have one item I haven't been able to figure out. How would one configure a text/sprite font box to reflect the value of the instance variable of a sprite? For now I'm using the Black Arrow overlapping the sprite which sets the text box but there has to be a way that would reflect it constantly without needing to use the overlap method.

    Man you nailed that with the example you provided!! I know it looks simple but to this caveman, it's like FIRE!

    Again, I know I can't buy you a coffee/beer but I sincerely thank you for your time.

  • wackytoaster.at/parachute/picking.c3p

    Here's a basic setup. Keep in mind that there are countless ways to "pick" your instance and it's up to you to find out what your game needs. Here's some links so you understand what I did.

    https://www.construct.net/en/make-games/manuals/construct-3/interface/layout-view#internalH1Link4

    Picking instances

    https://www.construct.net/en/make-games/manuals/construct-3/plugin-reference/common-features/common-conditions#internalH1Link7

    https://www.construct.net/en/make-games/manuals/construct-3/system-reference/system-conditions#internalH1Link7

    Things like "compare instance variable" will also pick all instances that match. E.g. Instance variable > 5 will pick all instances where food > 5 or compare X < 100 will pick all instances that are X < 100 on the layout.

    And obviously you can chain picking to filter out more and more instances until you are left with one (or more if you need)

    E.g. pick instance variable > 5, pick instance variable < 10, pick lowest

    Will first pick all instances where food > 5, then from those all where food < 10 and than from those it picks the one lowest on food.

    Progress as I've been testing and building off your example. Here's a new question for you.

    What would the coding look like for the system to detect if one of the sprites have a food value (instance variable) of 1 or greater and if so, do x (in the below example I have a new yellow sprite created)? I've been trying various combinations of code but no success yet.

  • More progress but I can't seem to get the behavior to work on all four sprites (all in the family). Maybe 3 of the 4, sometimes 2.

  • Hmm, put the second event as a sub-event of the first one. Right now it is checked every tick and that usually isn't what you want to do.

  • Good call. Updated the script accordingly.

    This creates the box now but I can't add to the value (coal) in the box when I right click on it.

  • i think i did it!! Maybe not the most efficient way and I'm open to advice but man...

    maybe not. coal values increase in sprite that isn't being right-clicked on. Piss!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Any hints or links?

  • Figured it out myself. Thanks?

  • Sry I'm not here 24/7 on helper duty :) Unless Ashley starts paying me or something :V

    I do recommend finding things out yourself though. It may take an hour or two longer but those are not wasted hours by any means. You will learn significantly more doing so than when someone just fixes your project for you whenever something doesn't work. Read through the docs, do searches and good ol' trial and error, and then, if still nothing works, then go ask for pointers.

  • Sry I'm not here 24/7 on helper duty :) Unless Ashley starts paying me or something :V

    I do recommend finding things out yourself though. It may take an hour or two longer but those are not wasted hours by any means. You will learn significantly more doing so than when someone just fixes your project for you whenever something doesn't work. Read through the docs, do searches and good ol' trial and error, and then, if still nothing works, then go ask for pointers.

    Nah, you're fine as I never expected/assumed you to be but I also know there are others who can lend a hand as well. I donate several hours of my time a week to a forum (Experts Exchange) regarding questions about servers, networks, etc, etc. Not paid a dime and realized early what a difference helping others makes as what comes easy to me can be an extreme challenge to others. But there are also others (most are way smarter than I) on that forum who can pick up where I left off if I get tied up with family or work commitments. Again, I appreciate your time as I understand the fruitless rewards of volunteering.

    That said, there comes a point when someone can spend hours and hours and hours trying to figure out how to accomplish X. If you sat me in front of a SQL server and told me to accomplish 10 tasks, you better not pay me by the hour because I'm going to be there awhile. So I know what you're saying about finding my own solution but as someone on this side of the mountain, it can be a little bit overwhelming. Few things are most frustrating to spend hours going down one path just to find out I need to spend hours trying a different path.

    I enjoy the challenge and when I finally got it, yes it was rewarding but the time I spent researching (tutorials, vids, reading) was gone. For example, I helped a new tech with an issue with group policy in Win. He spent hours trying to get a policy to apply but it just wouldn't. When I explained one part, he took it from there. I didn't do his homework, just told him how to do it. That's all I could ask for.

    Wrapping up, I posted that this site should have classes. Let us vote on what we'd like to see the experts like you and some of these other super-brains do so we can take notes. I've spent plenty of time doing that with cisco and vmware classes, no reason C3 can't offer it up too.

    Thanks for the reply and being open-minded/patient while donating your time. Sometimes it's nice to be an elevator for those stuck this far down the mountain. Until next time, friend!

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