How do I retrive array value

Just started using Construct 2? Post your questions here

Post » Tue Jan 26, 2016 10:32 am

So i set my layout with one botton and 2 texts
tsxt1, text2 click

I create an array called names and create few name in it.
I make an event "ON CILCK" than i set "APPENT TEXT" to the text1 to check a value of an array based on index number.
Names.At(0, 0, 0)
I also try
Names.At(0)
Names.At(1)
and so on.

I am trying to make auto name generating for pc characters based on array list.

Questions:
1. What's wrong with the code?
2. I need an function to retrive only one name randomly from the list, How can i do it?

And of course, Thank You!
B
4
Posts: 17
Reputation: 234

Post » Tue Jan 26, 2016 11:00 am

At(index) should work, as it says in the manual, if Y and Z are not provided, then they are set to 0.

I think the problem comes from the initialization of your array. How do you fill it with names?

You need a one dimensional array of names. Personally, I would first set the size of the array to (NAMESCOUNT, 1, 1), where NAMESCOUNT is the number of names you have, then I would fill each X index with a string value.

Maybe you set the height or depth to 0 by mistake. From the manual : "If any of the dimensions are 0 the entire array is empty, so usually all the dimensions are at least 1."

Please provide a capx or a screenshot of your code at least for us to provide a more detailed answer.

Btw, you can read the manual for Array here : https://www.scirra.com/manual/108/array
ImageImage
B
44
S
14
G
10
Posts: 166
Reputation: 7,779

Post » Tue Jan 26, 2016 9:44 pm

Thanks,
Still not working.
This is the image from the problem please check


Image
B
4
Posts: 17
Reputation: 234

Post » Tue Jan 26, 2016 9:59 pm

The Text object is useless for array manipulation, you only need it to display some text (like the content of your array) on screen.

Second mistake : Array elements are different from the object's instance variables. You don't need instance variables at all in the Array object.

To add an element to an array, use the array's Push action.

In your event sheet, this should look like :
- push "alex" at the end of name
- push "martin" at the end of name
- ... and so on.

You should check out a tutorial for using arrays in the tutorial section on this website, there are really good ones, or check out the usage of arrays in the manual.
ImageImage
B
44
S
14
G
10
Posts: 166
Reputation: 7,779

Post » Wed Jan 27, 2016 11:33 pm

Thank you!
B
4
Posts: 17
Reputation: 234


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 1 guest