Any way to foreach loop rows in a data table?

hi there
im trying to (maybe not the best way) using data table for creating a dialogue system, and i was thinking about using the row name as integers so i could somehow do a foreach node onto the data table so it would loop throught all the number of rows as i have as a different dialogue pass(if i can actually make it pause the loop for the player having to click before going to the next row, also not super sure how to do that), but as it is for the moment, im getting errors…im missing an array…
ideas suggestion and help much appreciated. thank you

well i got the first part on how to do the for each loop work, now i need to figure out how to pause and wait for input during each row

I think the data table has a node for getting all the keys in the table. Then you can for each over the keys

I believe you are looking for something like this.

First you can get data table row names and do a for each loop on that, this feeds into the get data table row node and finally add the results to an array that you could easily work with.

Example of what you could do on begin play. You could also instead of adding it to an array at the end (which you need to plug the array you make into): break the out row struct and do calculation on the data first before adding it to the array or not adding it and jut making a decision on it. Its really up to you want you want to do.

2 Likes

can you please explain a bit simpler? I don’t fully understand your answer i just started learning bp’s)

Use what Steve showed you to create an array of keys to loop over and you use each key to access its corresponding row in the datatable during an OTHER loop.

its really simple, what hes showing is that you use the get data table row names node to get a list (array) of all the rows in the data table. he then runs a for each loop on the list, so for each row he does something, in this case gets the data from each row. beyond getting the data you can do whatever you like with the information.

as for your question on pausing a loop thats not possible. loops run between frames and will run until they complete or in the case of some loops until a break is found. you could however create your own looping logic that doesnt use the actual loop nodes but instead uses custom events.

Yes you could use a timer or even a tick and a separate index variable and run a specific number of times each timer or tick cycle, doing a little or a lot at a time (but not the whole thing) until the index is bigger number than the last row. Instead of one loop that runs all the way in one tick (which can freeze the game until it’s done if it has to do a lot), then you rely on the master game loop (tick) or timer and do one or more at a time, then next time it fires you do the next one or batch, and so on.

thanksguys
im still not totally sure of what you guys are talking about so if you can shed more light on how to access each row individually would be great.
Right now i was able to make it work using custom events(thanks Thompson), but its a fairly long and complicated set up(automated, but still complicated. Basically i added a NextDialogueID that im feeding as a variable and then feeding it back onto the row name)

next big challenge is how to set this up for branching dialogue. If you guys have any suggestions please do. Also, before someone recommends(as ive seen in the foruns) i already bought 2 different dialogue plugins for ue4, but they are giving me errors so not very useful on that(not to mention they are quite hard to customize as well for what i need to do)

this is what i am after Danganronpa V3: Prologue [Part 1] (English-No Commentary) [PS4] - YouTube

looking forward to see your next replies and thank you so much for all the help so far

how to access each row individually

thats not what you were asking for, you asked about using loops. to get the info from a row individually you just need to use the get data table row node. this will give you a struct which contains the rows information.

After you have created an array of table row keys or names (whatever it calls them), then you can have an index integer variable to keep track of which row you want to access next. Increment it every time you access a row, and then next time it will access the next name in the list, which you then use to access the data table row that name/key/whatever indicates.