numbering instances in arrays

Get help using Construct 2

Post » Thu Sep 20, 2012 9:42 pm

hi everyone

i am searching a way for giving different numbers (e.g. 0 to99) to each object instance on a 2D array. i am trying to do this by changing their instance variables but i couldn't find a way to set their instance variables differently according to their positions in the array.

to sum up my ultimate objective is to number each square on a 2D grid 0-99 so i could use these numbers to make a 1D board game (like monopoly or backgammon) while it look like a 2D board game (like chess or checkers)

i hope i was clear :/

thanks in advance.
B
14
S
4
G
3
Posts: 101
Reputation: 3,499

Post » Sat Sep 22, 2012 10:03 pm

maybe i should be more clear to get an answer. i'll try to explain my situation more precisely.

i need to identify every single sprite instances created by an array. i have a 10, 10, 1 array and this array creates 100 instances. what i need is to identify differently every instance so i can set orders like "when global variable A changes (from y to y+n) move the player from instance(x) to instance(x+n)". or "when player is on instance(z) move it back to instance(w)" etc.

as you can see i want to use these instances as different "identified" positions in my game.

how can i do that "numbering" ?

ps: if this explanation is not clear enough either, please don't hesitate to ask questions. this will help me to explain my problem more explicitly.
B
14
S
4
G
3
Posts: 101
Reputation: 3,499

Post » Sun Sep 23, 2012 1:47 am

Is this what you want? numberedGrid.capx
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Mon Sep 24, 2012 7:27 pm

thank you ramones. but can this help me to set an event like, "<condition> ---> move player to 53" ? can the system "read" these numbers like me? if yes, how?

thanks again in advance.
B
14
S
4
G
3
Posts: 101
Reputation: 3,499

Post » Mon Sep 24, 2012 11:28 pm

You could give each sprite an instance variable 'number' and set it to the number. Then move the player to the position of the sprite with 'number' = 53.
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Wed Sep 26, 2012 11:12 pm

[QUOTE=ebrar]i am trying to do this by changing their instance variables but i couldn't find a way to set their instance variables differently according to their positions in the array.[/QUOTE]

as you can see in my first post, unfortunately this is my original problem :/ebrar2012-09-26 23:12:43
B
14
S
4
G
3
Posts: 101
Reputation: 3,499

Post » Wed Sep 26, 2012 11:31 pm

I'm still not sure what your problem with the arrays is really about, but I've implemented a board-like movement of a pawn using no array.
I hope it can help you, or else you might want to explain again what is your issue, what you're trying to do, what you've reached and what you would expect.

Example capx

If the issue was picking, as ramones said, you need to set a variable instance on the instance of your "cells" to identify them.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795

Post » Wed Sep 26, 2012 11:55 pm

i can't see exemple.capx because of my C2 version for now (i will check it as soon as i update my C2) but i think my problem is now solved. je te remercie kyatric, and thank you too ramones, for your patience and effort.

i was desperately trying to set instance variables of non existing objects (i am saying non existing because these objects are being created when game starts, i am using an array to create them on start of layout) but all i have to do is to use these CELLs of course.

sorry :)ebrar2012-09-27 00:20:27
B
14
S
4
G
3
Posts: 101
Reputation: 3,499


Return to How do I....?

Who is online

Users browsing this forum: GSquadron and 25 guests