# 2d coordinate system

Get help using Construct 2

### » Mon Nov 17, 2014 11:40 pm

Ok I am going completely nuts here. Construct 2 is not easy coming from a C oriented language and trying to work without objective thinking. For 2 days I have searched and tried to figure out how to make something as simple as 2 planets that have either and x,y and a name or id of some sort.

In C we would implement a class

class planets
{
planets planet;

planet.name={"Planet1","Planet2"};
planet.x={235,14};
planet.y={45,398};
};

etc, etc. You could call these and for ex. print a sprite at planet.x and planet.y locations etc.

I want these to be saved values. I was thinking of a array such as planet[name_char][x_int][y_int] but I can not figure out how to do this in Construct 2.

1. How do I store values in a 3 dimensional array maybe?
2. How would I go about puting a sprite on the screen with that arrays data?
3. Can you do this with a 3 dimensional array or should you do it some other way?

Like I said for 2 days this simple little stupid function and I cant figure it out. I much have read through 200 forum posts or more and 40 tutorials!

B
9
S
1
Posts: 56
Reputation: 576

### » Mon Nov 17, 2014 11:47 pm

What's wrong with instance variables?

PlanetSprite
- myID: Number
- myX: Number
- myY: Number
- myName: Text

edit: added the ID. You could store the planet ID's in a 2D array mapping to your coord system. That might remove the need to store x,y in each object. But I wouldn't go the 3D array route, it doesn't seem necessary.

sorry if this is too simplistic and I have misunderstood your needs.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

### » Tue Nov 18, 2014 1:52 am

It sounds like your over-complicating it a bit? It is a change coming from something like C or Java to Construct. A lot of the concepts can be modeled the same, but the way of thinking of attacking a problem has be a bit different.

For instance, to attach an array to a sprite you could create a container containing the sprite and the array. Everytime the sprite is created, the array will be created with specific values to that set as well.

As Codah suggested, you could add instance variables to the sprite.

More importantly though,the sprites hold their own values that don't need to be created for these. Like, if you want to reference the X coordinate of planet, in any of the condition or action statements, you would just use planet.X and likewise planet.Y. If you want to create a new object, use the system condition "create object" with whichever X and Y coordinate you want to use, or however you determine them.
Kurieus
Come visit and play Blast Box!
B
15
S
3
Posts: 205
Reputation: 1,349

### » Tue Nov 18, 2014 1:11 pm

Hrm, do you guys mean local instances variables? I was thinking down the line might have issues trying to call local instance variables. If you have other objects traversing my little 2D universe if you dont have a "planet" visiable you can not collide or discover that object unless you add a lot of invisible collision objects.

It all takes time moving from a programming language to a visual design, but it can get Soooooooo frustrating haha.

Thx for the info, will look into the instance variables some more see if I cant figure out how to access them globally etc.
B
9
S
1
Posts: 56
Reputation: 576

### » Tue Nov 18, 2014 1:43 pm

@Cybergod

Instance variables although unique to each instance of the same object can be accessed and passed to global variables & to other objects.

I threw together a little example of setting global variables to the instance variables of a clicked planet. Planets are invisible until the mouse is a certain distance away.

Hope it helps with instance variables.

instancevariables.capx
You do not have the required permissions to view the files attached to this post.
B
46
S
23
G
7
Posts: 459
Reputation: 6,763

### » Tue Nov 18, 2014 2:30 pm

@Minor
Hrm, pretty much what Im looking for, but, where did you put the individual planet info/data???? lol.
B
9
S
1
Posts: 56
Reputation: 576

### » Tue Nov 18, 2014 2:34 pm

In the layout editor.

Click any of the planets in the layout editor and on left you'll see the "Instance Variable" panel you can edit them there on a per planet basis. You could of course add them with events especially if you wanted to randomise the values.

Hope that helps.
B
46
S
23
G
7
Posts: 459
Reputation: 6,763

### » Tue Nov 18, 2014 4:11 pm

@Minor
Ahh omg I thought you had to set it manually in the eventsheet

with the
"Set PLX to random(500)"
"Set PLName "Planet1""

and so forth in the Add Action lol.

Im only about 2 weeks into Construct 2 but yah sometimes it can get really frustrating trying to convert C++ thinking into Visual Thinking hehe.

Thx alot mate, this helps ALOT!
B
9
S
1
Posts: 56
Reputation: 576

### » Tue Nov 18, 2014 6:41 pm

Yep, I've been struggling with the same kind of issues. You really have to approach these kind of things quite differently.
B
9
S
3
G
1
Posts: 346
Reputation: 1,560

### » Tue Nov 18, 2014 7:46 pm

@Minor
You know what, this really wont work either.

I have been playing around with it and because you have local instances of the x,y you can not randomize the locations out. For example

On Start Of Layout Create Object Planet at X=(random(500), Y=random(300)

This above capx you where kind enough to through together for me will only allow you to pre-place the planets and not randomize out tyhe x & y coordinates.

Thx for the try though, still looking at it to figure it out and will post here if and when I do.
B
9
S
1
Posts: 56
Reputation: 576

Next