How do I add items to a list from a text input object when a button is pressed?

  • I am trying to add items from a text input object to an array and then to a dropdown list whenever the "Add Story" button from my project is pressed but when ever i try to do this either no list is added to the list box in my project or it keeps adding items to the list without stopping and to help you to debug my code,Here are some pictures from different times from my educational project whose .c3p file i intend to release to help others to expand on this educational project

    Cheers

  • You need to insert TextInput.text into the array. Otherwise the code on your first screenshot is correct.

  • dop2000 I have tried this but this is not working,Have I made a mistake here?,and this is the screenshot of my attempt-

  • Cheers

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • This will put the array elements into a list box, sorted out in Alphabetical order.

  • aicreator I was talking about screenshot #1. You don't need any boolean variables and extra events.

    On button pressed -> Insert TextInput.text into the array, Insert TextInput.text into the list. That's it.

  • I have tried both the advices and even this code of mine which is below code below is not working ,and so can any one help me with this?

  • This code works, you don't need variables, arrays, or anything else, just this one event:

    If you want to add to the end of the list, replace "1" with a big number like "99999"

  • hey dop2000 your code in my project is only working when I do not use variables(whose values can be changed) which are -(Add item-Index : 1,Text:List.Variable 1) instead of exact data which are for example- (Add item-Index:Variable1,Text:List.Variable 1),but I need your code to work with variables as I can change their values later and then use them to add more items on my list without to add similar events again and again and also to follow the "Don't Repeat Yourself" Principal,

    Thank You.

  • Here is a screenshot of my code-

  • You can use variables if you need, just set them to correct values before adding to the list. You mean something like this?

    The code from your latest screenshot will not work, because the function is called on start of layout, when true=false. (Please don't name variables like this, it's really confusing)

  • Yes,but I have tried your code and it is not working for me here are some screenshots of my code -

  • dop2000 sorry for being rude,I made a typing mistake.

  • You mean typing mistake in your code? Is it working now? If not, please post your project file, because I don't see any errors in events, must be something else.

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