compare variables between specific instances

Get help using Construct 2

Post » Thu Dec 06, 2012 10:43 pm

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.
B
4
Posts: 15
Reputation: 330

Post » Thu Dec 06, 2012 10:56 pm

[code]Object(A).B[/code]Where A is the IID of the object and B is the variable name.

[code]System: Compare two values ( Object(0).V1 = Object(1).V1 )[/code]Will compare the instance variable V1 in the first two instances of 'Object'. Would that work in your case?
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Fri Dec 07, 2012 12:31 am

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.

https://www.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
B
4
Posts: 15
Reputation: 330

Post » Fri Dec 07, 2012 4:30 am

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...
B
4
Posts: 15
Reputation: 330

Post » Fri Dec 07, 2012 5:41 am

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:

https://www.dropbox.com/s/8qtzoesyouq5evk/events.JPGblah6262012-12-07 05:42:51
B
4
Posts: 15
Reputation: 330

Post » Fri Dec 07, 2012 8:37 am

You should use a detector sprite
Doing a "sprite is overlapping sprite" you'll never get what you want.

You should do a
[code]+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[/code]

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 codeYann2012-12-07 08:39:28
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Fri Dec 07, 2012 4:08 pm

So... I don't think local variables exist in the free edition. Any workaround, or do I have to buy it?
B
4
Posts: 15
Reputation: 330

Post » Fri Dec 07, 2012 4:37 pm

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 (?)
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Fri Dec 07, 2012 4:51 pm

I just found them :)
B
4
Posts: 15
Reputation: 330

Post » Fri Dec 07, 2012 5:05 pm

Still doesn't seem to work Did I do something wrong?

https://www.dropbox.com/s/oco6lcolgn6ipgh/v16.capxblah6262012-12-07 17:06:48
B
4
Posts: 15
Reputation: 330

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 2 guests