Array of text input : show on screen a column of TEXT INPUT and connect them easily with an array of text

Hi,
I would like to fill a whole array of text using TEXT INPUT.

On screen It would show a column of input boxes, myInputBox0 ,
myInputBox1 ,
myInputBox2,
myInputBox3,
etc…
and each one when filled by player would fill automatically the relevant element in the array mytextinput[ ].

So when player fills the first input box, it connects it directly with the array mytextinput[0]
and the second box is automaticaly put into mytextinput[1]
and third box into mytextinput[2]
etc…

for now I would only think of connecting each input box with an element of the array, using
mytextinput[0] set-to myInputBox0.Text() ,
mytextinput[1] set-to myInputBox1.Text() ,
etc…
… which is not feasible for many element in the array (and by the way creating all the input boxes is also quite difficult).

Is there a simple way to do this ?
Or is it possible to program it using loops…
(I’m quite new to Gdevelop, and can’t think of a way of doing it with loops.)

Actually my perfect end result would even allow to fill a 2D matrix of text input boxes into an array of array, for instance as :
mytextinput[0][0] mytextinput[1][0] mytextinput[2][0]
mytextinput[0][1] mytextinput[1][1] mytextinput[2][1]
mytextinput[0][2] mytextinput[1][2] mytextinput[2][2]
etc…

Hoping my question is clear.
Thanks.

Hi Boblib. Welcome. Can we get the bigger picture? What are you making? Sometimes there’s an easier way of doing things.

There is an extension that would help called Create multiple copies of an object

https://wiki.gdevelop.io/gdevelop5/extensions/create-multiple-copies-of-object/

It creates rows and columns of an object. It even assigns row and column variables. I personally never used it in that way but it seems perfect for your situation.

For reference:
https://wiki.gdevelop.io/gdevelop5/extensions/search/

I still think there might be an easier solution. Let us know your plan and we can give you more specific help.

Thanks @Keith_1357, I didn’t know about this Create multiple copies of an object which is very interesting. I managed to create a table of Input Boxes, like below :

However I couldn’t print back their values. I know that they should be called using :

After the objects are created, you can reference their object variables to manage the objects:
RowID: what horizontal row does this object reside in,
ColumnID: what vertical column does this object reside in,
CreationID: starting top-left, and proceeding from left to right, what is the number of the created object,
BatchID: optional identifier assigned to all objects created

But unfortunately I didn’t find the correct syntax… and also I’m not sure that it would be useful in my case (although very interesting for future use)

I can give now the precise wider picture to help understand :
I’m willing to create a Gdevelop tutorial game : that is to say a game which can be played as a presentation with slides (each scene being a new slide), and with animations related to the Gdevelop function being explained.
For that I intend to store on an external JSON file the content of the tutorial, which could look like this :

structure of all elements taught : ID_elementtaught, related to an other structure being like below :

  • Title of the element taught (for instance “how to create and Object”
  • first paragraph of the explanation
  • second paragraph of the explanation
  • third paragraph of the explanation
  • level of this element (beginner, intermediate, advanced)
  • date of teaching that element
  • planned date for reminding that element to students.
  • boolean : element is well understood Yes/No

Then I want to be able to read that JSON file and show it on screen in the following manner :
being able to select the ID_elementtaugh (in an input box), and after print the content of the relevant paragraphs in text boxes just below, and also being able to modify these paragraph on the very page.

After that the modified paragraphs will be saved on an updated JSON file. (The JSON file is important because it is partially already written with many elements and paragraphs. and It would be a simple way to work collaboratively on it.)
To summarize, the aim is to build UI that allows to write a book with titles and paragraphs…
Therefore creating a read/write table of text paragraph (and also other type of information as date or booleans) within a UI. And show on screen the table elements in a specific order, and also to save in JSON all these elements.

I hope this is clear, and I’m very interested to read possible solutions you may think of.
Thanks

I see the bigger picture. Which part do you need help with?

I have zero experience with JSON files but I believe they’re just a way to store variables. I can’t help with JSON.

As for strategy. If I understand your premise. I would use an array of structures. Each structure could have children like for type, text, wait for input, width, height… anything you need.

You could then read the children or array elements one at a time using a counter variable. Check the element type like ArrayName[variable Counter].Type and add the object type that is applicable.

The objects could be in a group so you can add them with [other conditions] [objects] [add object by name] The object name could be another child variable, the x could be 0 and the y would be the bounding box bottom of the previous object plys a gap. You could then add text or whatever setting from the structure.

You would then either wait for a response, a button click or keypress or move automatically to the next element . Increase the counter and check the next element.

I know I skipped a lot but that would be my initial thought for a strategy. Strategies usually change as soon as you add your first object.

Yes, there is a reasonably easy way to achieve this.

You’ll only need one myInputBox object, with an numeric object variable called id (or want of a better name).

Where you have each input box currently, replace it with a new myInputBox objects. Set the id variable of the input box to the number that was in the name of the one it replaced.

So, myInputBox.id = 0 for the object replacing myInputBox0 myInputBox.id = 1 for myInputBox1 etc.

You can then use a GDevelop style loop to set the boxes:

Thanks for this, I will look into it and come back soon.
Cheers

Thanks @MrMen , when I try

Where you have each input box currently, replace it with a new myInputBox objects. Set the id variable of the input box to the number that was in the name of the one it replaced.

I can’t set a variable value different for each input box… if I set to to 1 in the first box, it automatically changes it in the second box also…

Could you please explain how I should do that ?

Thanks @Keith_1357 for your strategy proposal. It seems appropriate to what I need.
My level in Gdevelop programming being “in progress” it may take me some time to manage it, but I will go in that direction and let you know when It’s done.
Would you have by any chance some example similar to this that I could copy or inspire from ?

Change it in the scene editor, not the object editor. Click on the object you’ve dragged onto the scene, and on the left hand side the object properties panel appears. The instance variables can be modified in that (you may need to scroll down the panel to see it):

@MrMen Good advice.
I found the answer of my translation problem : I’m using Gdevelop in French, and I can’t find REPEAT … (neither in condition nor in action lists) and it is normal, because I should do a right click and then “ajouter Répéter”…

the following question is important but I will ask it in a different thread
( - Do you know if there is a way to know what words are used in the different languages ? )

So I carry on implementing your proposal…

I’m moving forward…
and in your advice (@MrMen ) I can’t manage to perform

here is how I tried


it probably isn’t the correct way… (and even with other variable type I failed).

Could you please explain how you do it ?

Have you defined the structure as a scene variable. Right click on the scene in the scene editor and select "Open scene properties" to get:

image


Click on the edit scene variable on the bottom left, and add the variable:


And finally:

image