Is it possible to find a value in a data table based on the column values?

Sorry if the title is confusing.

What I want to do is be able to dynamically compare the values of 2 objects to get a float value from a certain row of a data table to use in a calculation.

Example

Say I have a data table like this with the columns ‘Fruit1,fruit2,points’:

Apple,orange,5.4
Apple,banana,7.9

and the game works by giving you a random fruit and a random fruit to compare to which award some points based on what fruits are being compared…

I have an apple object in my possession and an orange to compare to. Is it possible or even a good idea to get the value ‘apple’ and ‘orange’ from the objects and use that to find the point value of the ‘Apple,orange,5.4’ row?

Yes, but to me, the best way of achieving this is using code. Here is the idea. You have a 2D array with all fruits along the x axis and all fruits along the Y axis. Each xy location holds the points. Then you just need a single other array to map the text of the fruit to the index in the 2D array.

If you are only doing this through blueprints or code you can use enums and skip the translation table alltogether.

Would an array not be too resource intensive if you had a large enough number of objects? I figured out a way anyway.

Also, I thought that enumerators can only hold single values.

Ended up creating a datatable with all the possible fruit combinations as a single value.

eg.

AppleOrange,5.4
AppleBanana,7.9

Then:

  1. Took the fruitType values of the Apple and Orange objects
  2. Converted them both into string variables
  3. Appended them together
  4. Converted output into a name variable
  5. Input the name variable to a GetDataTableRow node
  6. Printed the points value from the output struct to see if it worked, and it did!

You are using an array as well. My solution is much faster to execute as it is constant time. It might be a bit more expensive on the memory unless you handle your duplicates. If you do, however, you have a system that is as fast as you can get and as space efficient as you can get.

Yes, enumerators can only hold 1 value per option, but if you make n options you have n values. As such it is perfect for your job as it allows you to read the code much easier and it makes the code efficient. If you can, use enums. You will love yourself later when you go back to the code in the future.