Understanding Arrays

0 favourites
  • 7 posts
  • Hi All,

    I have read few posts regarding arrays. Some were simple some were abit complicated but having fun reading it anyway. <img src="smileys/smiley36.gif" border="0" align="middle" />

    Okay so I just want to understand abit further on arrays and I also have read in the Manual.

    But Qn is, for simple one,

    eg. Set size Array(2,1,1)

    then we passed in values, Set Value at 0 to 4

    and if I were to retrieve using array.At(0) it will return me 4.

    then we passed in values, Set Value at 0 to "Test"

    and if I were to retrieve using array.At(0) it will return me Test.

    So I read some about converting the values to int or str but when do we do that?

    And can we set the array value from an instance variable of an object into it?

    Eg. Object name: object1

    variable for the object is named "itemText"

    type "Text"

    value is "TestVariable"

    Can we set it Set Value at 0 to object1.itemText?

    Will it return TestVariable?

    Warm Regards


  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • kbfc00 did you try it? What you described should work fine. Arrays can store and return either numbers or strings.

    You generally don't need to convert the types of values. Construct 2 will do it for you.

  • Hi Ash,

    yes, i've tried. but when i try to do the Set Value at 0 to object1.itemNum >> (itemNum is a Number type for the variable)

    and the value for this variable is 4

    and I use Set Text to array.At(0) for de-bugging

    but the value return shows 0

    And the thing is now that my object is being placed at, lets say, Layout1.

    And im using an event sheet from Layout2 to do the events.

    So basically Im trying to retrieve the object instance variable value from Layout1 and set it at event sheet for Layout 2.


    When I tried placing the object in layout2 itself, it works. it return the value.

    But is it possible to retrieve the value like what I described above ?

  • Can you share your .capx?

  • The problem is that there is no instance of "object1" in the layout where the events happen.

    So basicly, the instance variable doesn't exist and indeed returns 0.

    Also, you should pay attention to the window size, which is bigger than the layouts size (never a good idea).

    If you set the correct events in layout 1 you can see things work like in this capx

    You need to create an instance of the array in the first layout (as the array was created only in the second layout).

    If you want to continue with a similar setting I strongly suggest you to start a project from scratch and create the array in the first layout (of execution) as you'll probably want it to be global to have only one instance storing values through all layouts.

  • Now I see it. Make sense now. As where the event happens.

    So correct, no instance of 'object1' in the layout = 0.

    So that's it !

    Simple solution when thought about how the process goes.

    Thanks Ashley, Kyatric for the quick & easy to understand replies!

    Now onwards to success ! <img src="smileys/smiley4.gif" border="0" align="middle" />

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