Need help with Struts / Arrays / Random

Hi All

I have made an STRUT of 189 names.I would like to use this as a base for a random name generator.

I am running a loop for now to generate random stats (50 people), but can not work out how to get a random name from the list and populate the field…

Have I wasted my putting all of these names in to a STRUT or is this possible.

Regards

Like this I don’t really know a direct way to do this.

Usually you would do this with an Array (or two. One for first names, one for last names). Those are way easier to append, they can easily have different sizes and so on.

Thanks for reply.

So what if I do this, how would I make it work, can see all data in game.

31751-capture.jpg

I don’t know how to dynamically get different parts from a struct. It’s more of a way to logically keep variables together. Like a dictionary in python or hash maps in Java… or whatever language you like the most it should have an equivalent.

Basically you ask for a value with a key (in this case “First Name”, “First Name 1”, etc and get in return the value associated with that key.

What you want is a random name. Two values from a large set of values chosen at random. Usually you would do that by simply adding all those values to an array, get a random integer between 0 and the last index of your array and use the value at this index.

Alright let me go one step back in my explanation.

In most languages there are two main types of keeping values behind a variable. In java for example the way to store variables together is called a collection which I will use as term.Now there are two types of collections.

Arrays which associate a number with each value. The numbers range from 0 to n-1 while n stands for the amount of values you inserted into the array. To get those values back you need the number associated with that value. There are several ways of sorting by specific values or you can just randomize it.
And the second one is a map or (since I like that name more) in python called dictionaries. Instead of associating the values with numbers (like arrays) you associate them with a string. Like this you are always guaranteed to get the value you inserted there. It’s basically a fancy way to store a larger amount of variables and especially to send them and work across multiple classes or computers.

Now a struct is the latter one. You associate a values (e.g. a first name → “Aelianus”) to a string (e.g. “First Name”) and can receive it from the same. However it’s not easily possible to get a random result as each entry inside of a struct is meant to have a specific purpose. Like sharing all attributes of a character. You don’t want a random attribute. If you want to know the HP you want the HP and not the attack damage or any other attribute at random.

For your case (get a random name from a list of names) you simply need to put all those names into an array (not a struct inside of an array but the names as strings (or names, text… a variable type which is capable to directly represent letters)). Then you can get the length of that array (which is an included function) and pick how many you like at random with a random integer (which will receive the value represented by the index of that number).

TLDR: Get rid of your struct. You’re using it correctly for the data but not here

Hi

Tried that, no sucess.

https://forums.unrealengine.com/attachment.php?attachmentid=27715&d=1425301781

https://forums.unrealengine.com/attachment.php?attachmentid=27716&d=1425301932

But No Luck

https://forums.unrealengine.com/attachment.php?attachmentid=27717&d=1425302642

Regards