Ataloss Tutorial 1- Random TextAssets

Post a link here for written or video tutorials on uScript.
Post Reply
User avatar
ataloss
Contributor
Posts: 65
Joined: Mon Mar 31, 2014 9:02 pm

Ataloss Tutorial 1- Random TextAssets

Post by ataloss »

Uscript Random TextAsset load
Link to the PDF Version of this tutorial
http://tinyurl.com/obbunhe


Hello everyone. I'm At-a-loss. If you're at a loss when it comes to finding some help on uScript, then I'm here to educated you. Luckily for us, uScript's nodes are so versatile that they can be used to do things that most people wouldn't have thought of.


For today's tutorial, I'm going to share how I stumbled across a simple way to randomly choose a TextAsset from a list then display it's contents. I shouldn't say stumble because I intentionally spent an hour trying to use nodes that I'm very familiar with, to find a solution.

I'm not a genius coder like many of the developers on this site (I'm primarily a Designer). My setup of nodes isn't so perfect that it belongs in a Art museum (some people on here create artwork when they display their graphs, it's a marvelous sight to behold). The goal is for people like me that want results without having a lot of nodes and data to input.

If you're already familiar with uScript skip to the bottom where the entire Graph is displayed. If not, let's begin...one more thing, you already know to connect your nodes together so I won't mention it.


1- Create your scene. For this scene this is all I have.
Image



SIDE NOTE
If you're wondering how I grouped the objects.
1. Create a Empty Game object
2. Select all the things you want to be grouped with that empty game object.
3. Drag them into that Game object (so they will become it's children)
4. Rename that game object.

You're done. That's how you can have groups or categories while you work. Game objects are very versatile on Unity. It's a shame Unity didn't come with this type of grouping system by default.



2- Create a GUI Events node. Of course you can search for it in the search bar, by typing GUI events.
Image


Click on it so this can appear on your graph.
Image

You'll notice that I'm using a “Owner Variable”. I've read on this site that when you use a Owner variable, it's equal to saying “Whatever has this graph attached to it, use what's on this graph when I press the play icon”. Of course I'm paraphrasing.




3- Create the Owner Game Object Variable. To get to the owner variable you: Right click anywhere on the graph then...
Image



4- Connect the Owner GameObject to the GUI Event node.



5- Create the GUI Button node
Image



6- Fill in the information for the node. Here is what I have with my node.
Image





SIDE NOTE
You will need to make the position a public variable so that you can edit it within the Inspector window of Unity. To do that you place your mouse over the little white dot. Then right click on your mouse. Create Linked Variable.
Image



This is what I have for my public variable. You can change it later in the Inspector window.
Image




7- Create the Random Switch node. You can find it by searching in the sear bar.
Image




Here is what I put in my node
Image

SIDE NOTE
I also have this node bookmarked. To bookmark a node in uScript
1. click on a node.
2. click on the star
Image

3. click on any of the available slots.
Image

And you're done. It's now bookmarked for future use. All you do is click on the Favorites bar to select it.


7B- Create a Linked Variable (click on the blue triangle then choose “create Linked Variable”). This is what I put in my Linked Variable. I didn't make it editable in the Inspector window of Unity.
Image



8- Create a Resources Folder inside your Unity Assets folder.
Image


Create three text files inside that folder. You can name them whatever you want. But this is what I have in my folder.
Image



Type whatever you want in each of the text files. But this is what I have inside each of mine.
Image



9- Create a LoadText Asset node (use the search bar). Here is what I have inside of my node.
Image






Click on Browse to select one of your three text files.
Image




Right click on the Loaded Asset and create a Linked Variable. This is what I have on my Linked Variable.
Image


I DID NOT choose a TextAsset in the Value section (that's why it says none). I just created it to be able to see what text would load and if it was working correctly.


10- Create a TextAsset to String node (use the search bar). No need to put any information into the TextAsset to String node, because it will be linked to the Load TextAsset node.
Image



Place your mouse over the Green Triangle. Right Click, then choose Create linked Variable. Here is what I have in my node. I created this just to see if it was working.
Image




11- Create a Print Text node (use the search bar), here is what I have in my node.
Image





Link the Text Variable to the TextAsset to String Variable. Your graph should look like this.
Image



12- Now it's time to Copy and paste. I don't know how you do it, but if you're litreally an infant to uScript this is how I copy and paste.

Zoom out the graph by using your mouse wheel



Hold down the left mouse button and drag a box around the nodes to highlight them
Image





Right click on the highlighted nodes and choose copy
Image





Left click anywhere on an the graph and click paste
Image





13- Go back into your other Load TextAsset and choose one of your other text files. Basically each Load TextAsset should have a different text file. Like this
Image




14- Now it's time to test out a loaded text. Click Save (I don't know if you're saving it as a debug or Released, but I save my texts as a Release). I named my Graph Random_Text. But you can name yours whatever you want.



When you see this message click yes (for the sake of this tutorial).
Image



Assign the Generated Script to the master Gameobject. Theirs two ways to do this.

Method 1
Drag and drop the script from the uScript > uScripts> GeneratedCode folder. Remember you can only use the ones that end in “_Component”.

Method 2 (the method I use)
1. Click on the Game object I want the scripts to be assigned to.
2. Click Add Component
3. Scroll down to uScript and click on it
4. Click on Graphs
5. Click on the name of your graph
That's it.




15- Each time you click on the Load Text button a random text file will load and display the message you wrote within it.
Image


Image


Image


This can be useful if you're creating a game and wish to have a random message congratulate the player. For example:You're Awesome!, Great Job!, You're the best!, etc.

I created it because I wanted random comments for my NPC's (non player controlled characters) for this game I'm creating. I don't know if this can work with Texture assets. But I will test it out and let you know.

I also have other “junk yard styled” graphs I created for procedural spawning an asset, changing Game objects colors at the push of a GUI button, a Mecanim animations, etc. Let me know if you want those tutorials made as well.

Thank you for your time and I'm sorry to all the developers and master coders on this site if my ghetto Graph and methods made your eyes bleed from such sloppiness. But when it comes to things in my life, I like the KISS (Keep It Simple, Stupid) method. KISS is an acronym for "Keep it simple, stupid" as a design principle noted by the U.S. Navy in 1960.
Source: http://en.wikipedia.org/wiki/KISS_principle


The Overall graph for the intermediate and advanced users.
The Overall graph for the intermediate and advanced users.
rahuxx
Contributor
Posts: 142
Joined: Fri Jul 01, 2011 3:26 am

Re: Ataloss Tutorial 1- Random TextAssets

Post by rahuxx »

Excellent!

Great share buddy. I believe if all of us try to make some tutorials on different topics we can make uScript perfect alternative to scripting for non coders.

rahu
rahuxx
Contributor
Posts: 142
Joined: Fri Jul 01, 2011 3:26 am

Re: Ataloss Tutorial 1- Random TextAssets

Post by rahuxx »

Hey If you can make a tutorial on printing a table of texts from CSV file then it will be great.
What I need is something like this to be appear.
example.jpg
some 8000 names in table like this. There need to be a fix sapce between index, name of a person and age, If ever a name is so big that it can not be placed in its fixed area then it should go to second line, but should remain in its area vertically (like 4 in image above).

Hope you can make something like this. If you can do something like this with NGUi table then also it will be great help.
rahu
User avatar
ataloss
Contributor
Posts: 65
Joined: Mon Mar 31, 2014 9:02 pm

Re: Ataloss Tutorial 1- Random TextAssets

Post by ataloss »

Thank you for the reply's.

I have started working on two other tutorials. One is to procedurally spawn and delete content around a player and the other is on showing a stop watch (or countdown) on the screen. Both of which will use as few nodes as possible (well it'll use the most popular nodes).

The CSV chart I'll look into how to do that in a much easier way. I'm sure it's possible, but it'll require a lot of nodes.
rahuxx
Contributor
Posts: 142
Joined: Fri Jul 01, 2011 3:26 am

Re: Ataloss Tutorial 1- Random TextAssets

Post by rahuxx »

Hey Ataloss,

Thanks for your efforts in advance.

rahu
User avatar
TrapZZ
Power User
Posts: 4087
Joined: Sun Jun 26, 2011 12:49 pm

Re: Ataloss Tutorial 1- Random TextAssets

Post by TrapZZ »

These are great! I know how much time it must take you - we really appreciate it.
Need a break from uScripting? Join my brother and I every Thursday as we drink beer and continue our quest to review every US NES game ever made (the actual games on the actual hardware, not emulated).
http://www.brothernights.com
User avatar
ataloss
Contributor
Posts: 65
Joined: Mon Mar 31, 2014 9:02 pm

Re: Ataloss Tutorial 1- Random TextAssets

Post by ataloss »

TrapZZ wrote:These are great! I know how much time it must take you - we really appreciate it.
I'm happy I can help educated some people. I have to give you developers a lot of credit for constantly answering our questions. If it wasn't for you developers taking the time to make the nodes to show us, I wouldn't have learned uScript as quickly.
User avatar
ataloss
Contributor
Posts: 65
Joined: Mon Mar 31, 2014 9:02 pm

Re: Ataloss Tutorial 1- Random TextAssets

Post by ataloss »

rahuxx wrote:Hey Ataloss,

Thanks for your efforts in advance.

rahu
I started looking into your request this past Saturday. Sorry I'm just now getting back to you (I have an app, a website and a game I'm making for some clients).

Anyway...

Last Saturday, I started testing out some methods. And from what I think will be the easiest way to meet your requirement, is to load your CSV as GUI Texture. Basically don't load the CSV files as a text, html, xml or htm, instead take screenshots of the comma separated files, then place them in a folder to be recalled later on when you press a button (or trigger an event).
rahuxx
Contributor
Posts: 142
Joined: Fri Jul 01, 2011 3:26 am

Re: Ataloss Tutorial 1- Random TextAssets

Post by rahuxx »

Hey Ataloo,

I need it to be dynamic so can's use GUITexture.
Need to have some short of database like thing, but I am not able to do it as I am not a programmer.

rahu
rahuxx
Contributor
Posts: 142
Joined: Fri Jul 01, 2011 3:26 am

Re: Ataloss Tutorial 1- Random TextAssets

Post by rahuxx »

Any update?

rahu
User avatar
ataloss
Contributor
Posts: 65
Joined: Mon Mar 31, 2014 9:02 pm

Re: Ataloss Tutorial 1- Random TextAssets

Post by ataloss »

rahuxx wrote:Any update?

rahu
None. It's beyond my abilities for what it is you're trying to do. Maybe one of the developers can help you.
User avatar
TrapZZ
Power User
Posts: 4087
Joined: Sun Jun 26, 2011 12:49 pm

Re: Ataloss Tutorial 1- Random TextAssets

Post by TrapZZ »

ataloss wrote:
rahuxx wrote:Any update?

rahu
None. It's beyond my abilities for what it is you're trying to do. Maybe one of the developers can help you.
rahuxx, go ahead and start a new thread detailing what you'd like to accomplish (not how to do it, but what you want the end result to be). Someone might have some good insight on how to accomplish it.
Need a break from uScripting? Join my brother and I every Thursday as we drink beer and continue our quest to review every US NES game ever made (the actual games on the actual hardware, not emulated).
http://www.brothernights.com
rahuxx
Contributor
Posts: 142
Joined: Fri Jul 01, 2011 3:26 am

Re: Ataloss Tutorial 1- Random TextAssets

Post by rahuxx »

Already did that.

here - viewtopic.php?f=9&t=3052

Rahu
Post Reply