compare variables between specific instances

0 favourites
  • 10 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • I have a bunch of instances of an object. Each instance has 3 variables (say, V1 V2 and V3). I want to compare variables between 2 specific instances.

    So, I want to say, "if V1 on instance1 is equal to V1 on instance2, add a point."

    Is there any way to do this?

    I've tried using UIDs and a 4th "identifying" variable that is unique to each instance, but I think I'm using them wrong.

  • Object(A).B

    Where A is the IID of the object and B is the variable name.

    System: Compare two values ( Object(0).V1 = Object(1).V1 )

    Will compare the instance variable V1 in the first two instances of 'Object'. Would that work in your case?

  • Thanks. It works, but now my score goes up uncontrollably...

    doing this 1 by 1 comparison is really a last resort. what I really want is to compare all adjacent tiles of a target tile.

    dropbox.com/s/cuaqz5imj3byb0d/board.JPG

    In the picture, for instance, if the target tile is 14, I want to compare its variables to those of 13, 12, 4, 16,(the surrounding tiles) but no others. (#s on tiles represent current UIDs)

    If you have a suggestion for making this more efficient way work, that would be great.

    also, # of tiles are fixed. no new ones generate, if that matters

  • Im trying to say if "selected tile" (a specific instance of "blank tile") overlaps another instance of "blank tile" at an offset (since the distances are always the same), compare their personal variables. Either I'm doing it wrong or that just doesn't work the way I think it should...

  • Ok. Fixed for the most part. Points aren't out of control, but they go up by 3 every time, never just 1 or 2. Anyone know how to fix it? Here's my event sheet:

    dropbox.com/s/8qtzoesyouq5evk/events.JPG

  • You should use a detector sprite

    Doing a "sprite is overlapping sprite" you'll never get what you want.

    You should do a

    +Mouse: on left button clicked on okay
      OR
    +Keyboard: on Return pressed
       +system: foreach tile
          local number dist = ...  //distance between each tile
          local number diet = 0
          local number habitat = 0
          local number texture = 0
          -> system: set diet to tile.diet
          -> system: set habitat to tile.habitat
          -> system: set texture to tile.texture
    
          +system: repeat 6 times
             -> set detector set X to tile.X + cos(30 + (loopindex*60)) * dist
             -> set detector set X to tile.Y + sin(30 + (loopindex*60)) * dist
    
             +system: pick all tile
             +tile is overlapping detector
                 +tile.diet = diet
                     -> system: add 1 to score
                 +tile.habitat = habitat
                     -> system: add 1 to score
                 +tile.texture = texture
                     -> system: add 1 to score

    1/ you use local variable to keep the value of the instance variable of the current tile, because you will lose the picking afterward

    2/ you do a loop on the 6 possible surrounding tile. The little trigo thing should place the detector on each these tile. (you have to provide the distance between tiles in the dist variable though)

    3/ you pick all tile to reset the picking an be able to pick other tile thanks to the detector.

    4/ you apply the rules by comparing the detected neigboring tile's instance variables to the value you stored on the local variables

    note: pay attention on how I indented the code

  • So... I don't think local variables exist in the free edition. Any workaround, or do I have to buy it?

  • local variables exist in the free edition

    the limitations of the free edition are:

    • 100 events
    • 4 layers
    • 2 fx
    • no family
    • dunno about containers (?)
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I just found them :)

  • Still doesn't seem to work <img src="smileys/smiley5.gif" border="0" align="middle" /> Did I do something wrong?

    dropbox.com/s/oco6lcolgn6ipgh/v16.capx

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