How do I use string instance variables to anchor logic?

0 favourites
  • 4 posts
From the Asset Store
100 items casual and logic games. All icons are of a high quality.
  • If I have SPRITE1 and it has an instance variable 'varX' that's of type string, for some reason I'm not able to set logic around different strings that could possibly go into that instance variable. So if I generate 5 instances, but each time I generate an instance I want to say "if varX = "James" do this; if varX = "Bill" do that, etc." but Construct 3 doesn't seem to want to acknowledge this as valid.

    However, if I make a 'varY' that is a type number, and I say "if varY = 1 do this; if varY = 2 do that," it works perfectly. But if I have an Array, for instance, where I'm saving strings and I want to associate those strings with my SPRITE1 instances on creation, and then do some other logic around them after creation, I can't put a nested logic branch that's smart enough to read the string instance variable (because setting the string instance variable is easy enough).

    I don't want to have to make my array numeric just to get around this, because that would make it very hard to debug. I'm sure the solution is right in front of my face, but I've been staring at this problem for like 3 hours.

  • Won't know what's wrong with yours if you don't show what you did, but here is an example of conditions by comparing string instance variables. dropbox.com/s/2iwbdrwvt9o8whw/conditionbystring-example.c3p

  • Thanks for the example project you added, oosyrag. I think this works but my version's not much different other than how I have the strings attached to arrays rather than the buttons you have in yours. Not sure how much difference that makes.

    There are too many moving parts to really show the whole thing, but here's what I do:

    • First, I have an array that's 4 by 2. The first row (y=0) has the names of the people ("bob", "sam", "jim", etc.), and the second row (y=1) has the numerical rating value that I'm associating with the name. Ends up looking like: "bob, 1" "sam, 4" "jim, 20" etc.
    • Next, I have a layout that throws compound sprites (one base sprite with another sprite pinned to it at creation) across the screen with bullet speed, and the player has to tap them before they go off screen to get points. Upon tap, the sprite is destroyed, but when it's first created I wanted to associate values from the array with the sprite. So the base sprite has 4 frames, and the pinned sprite has 6. Depending on the y=0 (name of people) value of the array, and the x column of the array, I want to select a frame of the pinned sprite to associate with "bob" or "sam" or "jim".
    • At the same time of creation of the base sprite, with the y=1 (person rating) value of the array, and the x column of the array, I want set the frame of the base sprite according to the value (i.e., if less than 5, frame 1, if between 5 and 10, frame 2, etc.).

    I hope this is better info. Like I said, I can't really pull this whole thing out of the system and have it work how I'm trying to explain....I mean....maybe I can try to put something together. I guess I've been avoiding building an entirely separate example project.

    Tell you what, if above is not enough, I'll put together a project to the best of my ability. I'm still pretty new to game dev (only like <5 years), so I've just wanted to stick to this one project while I'm focused on it.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I figured it out. I was adding quotation marks to the text field of the instance variables several steps back on a previous mini-game that affected this mini-game I was trying to match the results up with.

    DO NOT put quotation marks in your instance variable fields, people!!!!!!! Learn from me, and save yourself the heartache and lost time.

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