Treat Arrays with Pi Stack

Hi, and sorry for my question, it may be considered as a silly question but I’m in the fist approach and merging together Javascript into Pi still create some confusion to me.
I have created an array with 3 elements, and I cannot figure out how to extract the first, the second, the third element and so on.

I have created a pi Math where with a function I create an array, whose elements change thanks to an element selected form a selection box. Everything is working perfectly, if I put inside a field the output I receive the correct array - for example if I choose the first item the array has value [13,12,6], if I choose the second item the array changes into [17,33,20], and so on.

What I still don’t understand is how to get the first, or for example second element of this array, to isolate it and use it in another formula

Many thanks for your help!

AL

Have a look at the Access the Elements of an Array section on https://www.w3schools.com/js/js_arrays.asp

Thank you Joe, I’ve already took a look to that but it’s still not clear to me.
Please take a look to the picture:

I understand that the way is to access - for example the first item - is “name or array”[0], what I still cannot understand is how to refer to the array created in another pi stack

You have an array of arrays. So you need something like this… array[1][0]

Pi does not know how to deal with arrays. Your functions can deal with them but they must return a number to Pi if you want to display the data.

mmmm… this def_vet function returns a simple array, like for example [13,12,6].
It doesn’t seem to me an array of arrays.

Ok, so I should have to use a funcion. But my previous function returns an array.


in vettore-Text field it correctly displays - for example - “13,12,6” when SelectProfile has Value 1

Then you need to have another function that calls the pidef_vet function and puts out the values that you want.

Sorry but I cannot understand… sigh!
I just know that stack “find-array” creates the right array for me, I cannot get first element of {{pi-find_array}} in this way. And I cannot figure out how i can write a function that get that from {{pi-find_array}}… any little help? …please!

Find array is invalid. You cannot store arrays inside Pi values. You would need to create a function that returns the first element of the found array. Basically it would return vettore[vet-1][0]. Then you would have another function that would return vettore[vet-1][1], etc if you needed that.

2 Likes

Thank you, thank you very much, I have changed completely the structure according to your suggestions. I had to triplicate the routines but now everything works. I have to say I have never found before a support system like yours, your personal involvement is admirable.

By the way: the original Find_array function seemed to work, the output of pi stack was (or seemed to be) an array

2 Likes

Now that you have it working… If you want to send me a project file with the form, I can give it a once over and show you how I would do it.

1 Like

Thank you, please wait a coupl of days, I’ll finish it. Thank you once more

Hi Joe, I’d like to send you the project, what is the best way to do it?
I have finished the page, it’s basically an easy calculator, you can find it here:

http://www.lsd-lighting.it/profili_zero/profili_zero.php

Funny thing is that I cannot add any other function to the one I have already created… is there a limit in the functions that PI can treat in a single page?

thanks

AL

Nope. No limits. Download link works.

Create a new project with just the form. Not your entire site.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.