Thursday, January 3, 2013

Another Little Update - Generic Menus

As I mentioned in my last post I've been working on some generic menus that I can use in many different situations. I've mostly been working on an upgrade screen the past couple days. It has a three items/skills that can be upgraded if you have the correct amount of money/points. I thought I had the Flash/AS3 side of it done, but as I'm working through the Unreal side of it I found a lot of ways to improve what I already had. By trying to streamline my code I figured out how to use an archetype to quickly edit variables in the editor, as well as how to call an AS3 function from Unrealscript and how to get an Unrealscript variable and use it in AS3. I figured I'd post what I've found out for you guys.

These took me a little bit to figure out how to get them to actually affect my variables, but thanks to some help from Andrew Talarico I figured out a clean way to use them.

For instance I am using an archetype of my GUSProperties class which holds my variables for my GenericUpgradeScreen class. This way all my variables are in their own class(extending from Object) to avoid excess clutter when making the archetype.You can create an archetype by finding the class in the Actor Classes window(Usually next to the Content Browser tab in the Content Browser window.) and right clicking, and selecting 'Create Archetype'. Once you click on the archetype you just made, it will bring up a window showing all the variables that you have declared as editable in the editor. Making them editable can be done by adding () after var, for instance var() int Currency; If a word is put in the parentheses this will put the variable under a category of the same name in the archetype. For example, var(Inventory) int Currency; would make an int variable named Currency in the Inventory category. See below for examples:

If you are making a separate class to hold your variables, then the easiest way to make them work in your main class is by a variable of the properties class, and declaring what archetype is used in the default properties. See below for another code excerpt:
Calling an Actionscript Function:
This gave me a lot of trouble trying to find a way to do this that worked. I tried following the examples given on the UDN(More specifically Here) and I kept running into error after error, even after scouring the Unreal forums. Thanks to a tutorial by Lucas-Williams I was able to figure it out the rest of the way. I found that unless you know what you are doing with AS3 packages/classes/constructors you will have a lot of difficulties with just copying the code on the UDN. What Lucas-Williams did was strip the function down in AS3 and called it like they did in the UDN tutorial. I found that in order to get the Unrealscript call working for me I had to add root. before the AS3 function name in the Unrealscript ActionScriptVoid() function(Shown below).

Getting an Unrealscript variable:
This is pretty much directly taken from the UDN page on it, so not really any original work from me. Good info regardless. I recommend taking a look at the link above if you are interested. The one thing I would like to add to it is if you are trying to get multiple variables of the same type, in the switch(VarName) you can just add both names of the variables. You don't have to add another one to the switch(VarType) since they will both share a type.

I hope this helps you with your own projects. 

No comments:

Post a Comment