Understanding Arrays

Discussion and feedback on Construct 2

Post » Tue Mar 27, 2012 10:11 am

Hi All,

I have read few posts regarding arrays. Some were simple some were abit complicated but having fun reading it anyway.

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
kbfc
B
5
Posts: 10
Reputation: 395

Post » Tue Mar 27, 2012 3:46 pm

@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.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,590

Post » Tue Mar 27, 2012 5:31 pm

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.

Update:
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 ?
B
5
Posts: 10
Reputation: 395

Post » Tue Mar 27, 2012 9:15 pm

Can you share your .capx?
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,590

Post » Wed Mar 28, 2012 2:42 am

B
5
Posts: 10
Reputation: 395

Post » Wed Mar 28, 2012 4:27 am

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.
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 Mar 28, 2012 6:18 am

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 !
B
5
Posts: 10
Reputation: 395


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 2 guests