numbering instances in arrays

  • 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.

  • 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.

  • Is this what you want? numberedGrid.capx

  • 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.

  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

    as you can see in my first post, unfortunately this is my original problem :/

  • 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.

  • 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 :)

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