- Home /
Help with BurgZergArcade, dice question
I have a list of attributes and want each of them to have 3 dice rolls. Right now, I can only figure out how to get 3 dice rolls overall.
for(int cnt = 0; cnt < Enum.GetValues(typeof(AttributeName)).Length; cnt++){
GUI.Label (new Rect(10, 95 + (cnt * LineHeight), 70, LineHeight), ((AttributeName)cnt).ToString ());
GUI.Label (new Rect(85, 95 + (cnt * LineHeight), 30, LineHeight), _protag.GetPrimaryAttribute(cnt).AcceptedValue.ToString ());
if(rollsLeft == 3){
if(GUI.Button (new Rect(125, 95 + (cnt * LineHeight), 40, LineHeight), "Die")){
dRoll1 = ((int)(UnityEngine.Random.Range(1.0f, 20.0f)));
_protag.GetPrimaryAttribute(cnt).BaseValue = dRoll1;
rollsLeft--;}
Debug.Log (dRoll1.ToString());
}
if(rollsLeft == 2){
if(GUI.Button (new Rect(125, 95 + (cnt * LineHeight), 40, LineHeight), "Do")){
dRoll2 = ((int)(UnityEngine.Random.Range(1.0f, 20.0f)));
rollsLeft--;
Debug.Log (dRoll2.ToString());
if(dRoll2 > dRoll1){
_protag.GetPrimaryAttribute(cnt).BaseValue = dRoll2;
}
}}
if(rollsLeft == 1){
if(GUI.Button (new Rect(125, 95 + (cnt * LineHeight), 40, LineHeight), "Dee")){
dRoll3 = ((int)(UnityEngine.Random.Range(1.0f, 20.0f)));
rollsLeft--;
Debug.Log (dRoll3.ToString());
if(dRoll3 > dRoll2 && dRoll3 > dRoll1){
_protag.GetPrimaryAttribute(cnt).BaseValue = dRoll3;
}
}}
if(rollsLeft < 1){
if(GUI.Button (new Rect(125, 95 + (cnt * LineHeight), 40, LineHeight), "Doh")){
}
}
}
Awful indentation, please edit your question to format the code.
What the hell is "GetPrimaryAttribute" ? Is that part of a commonly used package or something?
@Fattie all of these type questions are based off the BurgZergArcade HacknSlash RPG tutorial. GetPrimaryAttribute is a method not shown in these code snippets.
Answer by robhuhn · Sep 16, 2013 at 10:10 AM
@Edit
I read your question a few times and may be what you need is a dictionary to store the rollsLeft value for each attribute. Actually you should consider splitting your code into several classes but a dictionary should also do it.
Define the initial value of rollsLeft:
using System.Collections.Generic;
// YourType should be a unique identifier - may be the name of the attribute as a string
public Dictionary<YourType, int> rollsLeftForAttribute = new Dictionary<YourType, int>();
void Start ()
{
for(int cnt = 0; cnt < Enum.GetValues(typeof(AttributeName)).Length; cnt++)
{
rollsLeftForAttribute[attributeName] = rollsLeft;
}
}
Then instead of checking for rollsLeft and decrementing it's value you should check for rollsLeftForAttribute[attributeName] within the loop e.g.:
for(int cnt = 0; cnt < Enum.GetValues(typeof(AttributeName)).Length; cnt++)
{
...
if (rollsLeftForAttribute[attributeName] == 3)
{
if (GUI.Button (new Rect (125, 95 + (cnt * LineHeight), 40, LineHeight), "Die")
{
...
rollsLeftForAttribute[attributeName]--;
}
}
...
}
Adding the second for loop isn't working for me. It just makes it so that you can roll forever.
I'm trying to create the dictionary with a yourtype based on one of the attributes (attributeName.Body), but it says it's an "invalid" but a "type" was expected. So I tried creating an attribute for it which was bAtt which was a string that equaled attributeName.Body, now I'm getting that it's a "field" but a "type" was expected. How do I make a type?
I suggest you start a new question about that, and/or search here/forums for questions about Dictionary.
Your answer
![](https://koobas.hobune.stream/wayback/20220613114230im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Melee combat help! 1 Answer
How to start the day at day (Burgzerg Arcade)? 0 Answers
Error CS1503, Error CS1502 1 Answer