After several hundred years of searching and not finding then leading into immense brain-hurting and issues, I've come up with a decent random name generator that allows you to load up a text file with whatever you want to throw into it, and I feel like sharing my results with the vast majority of people around the place.
For this tutorial you will need a few things:
Any type of text editing tool that can save a file to txt
Rich Edit object
Arrays
WARNING! This tutorial assumes you are an idiot an have never used click products before.
The first step to getting this underway is loading up your text file(s) with whatever names you want to place into it in a specific way. Each interchangeable part must have its own line, i.e.
George
Steve
Ben
Ted
Fabio
Ect.
It is always adventagous to end each file with at least two blank paragraphs. If you want the option to have that particular section blank, leave one blank paragraph at the top or at the bottom. If you are using more than one set of names (for example, first and last names would need two text files, one for first names and one for last names) and you want to have the first name have the possibility of being blank, add one space to the end of each name on the list, otherwise it might complicate things.
Now that the prep work is done, you will now load up whichever click product you want to use (so long as it has Rich Edit and Arrays). In a random frame, add in a rich edit object (make sure its wide enough to fit all your text on one line evenly, not sure if that will effect the outcome, but better safe than sorry) and add an array.
Now in the events page you are going to start loading each text file you are using and getting the line count at the start of the frame. To do this, select a new event, and right click on the frame options (the chess board with the knight piece) you will select Start of frame. Right click the box under the rich edit object and select Files:Load ASCII text. Inside the quotations type the exact name of the first text file (make sure to include the .txt). After that, right click on the box under rich edit again and select Control:Goto:Line Number and in the box leave it at 0 and hit okay. Now you are going to save the next value wherever you feel, but for the time being we are just going to put all of them as global values (for more expirienced users, you know what to do). Under the special conditions box (it looks like two computers, one with a ?. It's in the first spot by default) right click and select Change a global value:Set. In this box you are going to select Retrieve data from an object. Right click on the rich edit object and select Scrolling:Get line count. Repeat these steps for each and every text file that you have. Once you are done, right click under special conditions and select Fast Loops:Start Loop. Put any name of the loop in the quotions, but take note of it, then hit okay. In the conditions, select Retrieve data from an object, right click on special conditions and select Retrieve a global value and select the first line count of the first text file. If you have multiple text files, in the calculations window add a '+' after the first variable and keep adding in the text files, so it looks like:
valueA + valueB + valueC + ect
Load up the first text file again, then under the rich edit object, select Alterable Values:Add to. Select the first unused alterable value. Finally, under the array select Change Current Position:Set Y Dimention to... (0 or 1 depending on your base index).
Now that we have the line counts done, you are going to have the array start reading each text file and copying down the contents into itself. Make sure that you have your array set to a text array and take note weather or not it is base 1 index (base 1 index indicates weather the array starts from 1 or from 0). You can set those by right clicking on the array in the frame window and selecting properties (or just left clicking on it and looking at the window to the side).
Start a new condition, right click on special and select On Loop and in the quotes type in the name of your loop. Add another condition, under rich edit select Alterable Values:Compare to one of the Alterable values. Select the same one you used previously. (take note you can rename them by selecting the rich edits properties in the frame window.) And set the conditions to Greater than > and the number 0. Add one last condition, the same condition as the other, but in this case set it to Less than < and the number you will Retrieve data from an object and select the line count of the first text file.
Under the rich edit box, set an new alterable value. Lets call this one, currentPos. You are going to set it to Retrieve data from an object, rich edit Caret:Get Caret Position. The next action will be under rich edit box, Control:Goto:Goto Line and in the calculations set it to Retrieve data from object, Rich Edit Caret:Get Caret Line then back in the calculations add a + 1 to the end so it says:
Get Line (Rich Edit Object) + 1
Now you are going to start messing with the Array. For the next action, right click under the array, select Change Current Position:Set X Dimention to... and you are going to set the number to the line count you set in the global value. Now the array is going to copy the current line. Add the action (under the array) Write:Write string to XY. Set the X to the first alterable value you made, and Y to 0 or 1 based on your base index. In the box it needs to say:
GetText$( Rich Edit Object, currentPos( Rich Edit Object ), GetChar( Rich Edit Object ))
Basically that says it is going to get the text from where the line was before (one line up) to where it is right now, which is in front of the next line. So keep in mind when testing and using this, there is going to be an extra paragraph in there. The last thing you need to do is to add 1 to that first alterable value you set up.
From there, weather you are going to start a new text file or finish out the conditions will be
On Loop yourLoop
Alterable Value of (Rich Edit Object) >= firstTxtGlobal
If you are adding another text file, load that text file, set the line to 0, add one to a new alterable value (which will function like the first one), set the first alterable value to -1 (just to be safe) and set the Y index to the next spot, then copy the last event and change the alterable value and XY index. If you are finished, set the current alterable value to -1, and save the array to a file. It also might be adventagious to save those line counts to the array (just make sure you add the value to string conversions under special conditions in the calculation window so that the array can read it. Make sure when you call it back in you plug in the string to value conversion).
Now your array is filled with all of your text files. Now the only thing we have left to do is recall it.
Break out a string that you want to use. You only need one. Think about how many text files this string is made up of, and you need to set up a Alterable value and Alterable string for each file except the last one. So if you have one file, you don't need any values, if you have two you need one, three you need two and so on. First off, load the array from the file you just saved on the last frame. If you need to reload the line counts, do so now. Set the first alterable string to:
StrAtXY( array, Random(firstTxtLinecountGlobalvaluemajig), 1)
This function takes a string at XY, the coordinates being X=the line count of the first text file and Y=the Y coordinates of the first text file.
Now set up the first alterable value to:
Len(Alterable String( string ))
This value grabs the length of the randomly selected name you just selected.
Do this for each text file except the last one.
To display the text, change the alterable text of the string to:
Left$(firstString( string ), firstValue( string )-2)+ +StrAtXY( array, Random(secondTxtLinecountGlobalvaluemajig-1), 2)
Basically, when you call Left$, that lets the editor know you want to get the specific characters from a string starting from the left, and when you plug in the character count from that value it selects all of it (including the paragraph). then you subtract it by two, which gets rid of the paragraph completely. If you didn't add a space at the end of each name on the txt file, add the +" "+. If you already added a space, just put +. the second part calls another random name from the second text file.
It's like 2 in the morning now, so I'm tired as hell. If I started trailing off at the end there, let me know what I can clarify up on. Otherwise, hope you guys liked it, and hope I helped someone! Yay!
|