- Home /
javascripts and Enum ( for loops get name)
pragma strict
public class Attributes extends BaseStat {
public function Attribute() {
SetExpToLevel(50);
SetLevelModifier(1.05);
}
}
//List of attributes in Game public enum AttributeName { Might, Constitution, Nimbleness, Speed, Concentration, Willpower, Charisma }
//then i want to get the gui function to return trough the for loop Might, Constitution, ect how can i achieve this on javescript??????
function OnGUI() { GUI.Label(Rect(10,10,50,25),"Name: "); _toon._name = GUI.TextArea(Rect(65,10,100,25),_toon._name);
for(var cnt : int = 0; cnt < Enum.GetValues(AttributeName).Length; cnt++) {
GUI.Label(Rect(10,40 + (cnt * 25),100,25), Enum.GetValues(AttributeName.ToString()));
GUI.Label(Rect(115,40 + (cnt * 25),30,25),_toon.GetPrimaryAttribute(cnt).AdjustedBaseValue.ToString());
}
}
heres a video tutorial how to do it in c# but i dont know how to translate it :( help me
Answer by cupsster · Jan 31, 2012 at 10:25 AM
import System;
enum positionInterpolation { easeInOutQuad = 0,
easeInOutCubic = 1,
easeInOutQuart = 2,
easeInOutQuint = 3,
easeInOutSine = 4,
easeInOutExpo = 5,
easeInOutCirc = 6,
linear = 7};
var curentInterpolation : positionInterpolation;
then in your code do:
for (var e:int=0; e < Enum.GetValues(typeof(positionInterpolation)).Length; e++){
if (GUI.Button(Rect(95,50+p,105,18), Enum.GetValues(typeof(positionInterpolation))[e].ToString()))){
// do your stuff here
}
}
do not forget about "import System" at begining of your script.
dont forget to mark as answered.. today I fought with same problem and this worked for me.. thank you
Your answer
Follow this Question
Related Questions
Help with C#(Sharp) to Java Script :) !!! 1 Answer
changing a coroutine's argument at the coroutine's runtime? 1 Answer
Split() into a fixed length array? 1 Answer
Javascript for loops and Arrays. 2 Answers
For Loop GUILayout.Label Problems 1 Answer