arrays and the mistery behind them

0 favourites
From the Asset Store
Cave Background Music
$4.40 USD
60% off
Add an exploration, fantasy, mistery and mystical vibe to your games with these 10 themes
  • I followed the tutorials and I know what an array is in other languages, but I don't understand how they work in c2.

    I'm posting the c2 code and my interpretation about how should they work in js.

    Array set size to (3,0,0) //array[0] = false;array[1]=false;array[2]=false;

    Array set value at 0 50 //array[0] = 50;

    Array set value at 1 120 //array[1] = 120;

    Array set value at 2 260 //array[2] = 260;

    Create Object Circle on layer 1 at (array.At(0),0)

    //I expect to create object circle at 50,0 but it's not working why is that?

    Thanks

  • In the example you posted here, you first initialie your array with boolean values and then override them with integers....is that intended?

    it could be, that you receive a string which holds "50" when you do a "at(X)" so you have to cast it to an integer. you could do a "int(x)" to do that

  • Try set size to (3,1,1) rather, it should work.

    Also, you may need to cast the result of an array to make sure it is a number.

    So set X to int(Array.at(0)). (like weishaupt suspects)

    Some leads that will hopefuly help you.

  • I set the size to 3,1,1 but it still won't work. Weishaupt the bool thing wasn't intentional it was my interpretation of what construct2 may do under the hood.

  • A quick test that positions the sprite according to values stored in the array : quick test.

    As long as the array is created in the same layout as you currently are, it should work.

    If you have like two layouts, and that array was created in layout2 and you're trying to use it in layout1 it will not work.

  • Uhmm seeing your example I see that in my c2 in the properties of the array I don't have width height and depth..

    Is it a bug?

  • Sounds like you created the array in a layout that was then deleted, or something like that.

    It is more or less a known bug yes. (Has to do with the fact that you need at least one instance of an object type in the project for it to work).

    Make a new array, set the code to work with it and then destroy the old array.

  • Problem is that any array I create has the same problem.. please tell me there is a fix I don't want to start from scratch..

  • send the capx

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I would prefer not to since it's an almost finished game, is it ok if I strip everything out leaving just the array logic?

  • Ok, stripped everything but the array logic, same thing as the one Kyatric posted, it looks like something bugged and the arrays are not working anymore.. I created another layout and on that I got back the array properties, you may notice that if you create a new one it hasn't got the properties (one included).

    Interesting..

    here it is: dl.dropbox.com/u/1606950/array.capx

    If someone manages to fix this can please explain what happened and why?

  • yeah the array aren't in your layout

    You have to save you're game as project and go into your layout xml to add the array back in it.

  • How this has happened? And what is the syntax for getting the array back into the layout, I looked at the xml but where do I have to put it exactly and what is the syntax for the array object?

  • Create another project and put an array in it, then save it as project and look at how the xml is made.

    You then just have to mimic the syntaxe

  • Thank you very much for you help!

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