Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by igfi · Sep 15, 2013 at 08:42 PM · burgzergarcade

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")){
 
         }
         }
         }
Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image KiraSensei · Sep 16, 2013 at 09:55 AM 0
Share

Awful indentation, please edit your question to format the code.

avatar image Fattie · Sep 17, 2013 at 07:50 AM 0
Share

What the hell is "GetPrimaryAttribute" ? Is that part of a commonly used package or something?

avatar image getyour411 · Sep 21, 2013 at 08:28 AM 0
Share

@Fattie all of these type questions are based off the BurgZergArcade HacknSlash RPG tutorial. GetPrimaryAttribute is a method not shown in these code snippets.

avatar image Fattie · Sep 21, 2013 at 08:34 AM 0
Share

I see, how annoying.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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]--;
         }
     }
     ...
 }
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image igfi · Sep 16, 2013 at 05:06 PM 0
Share

Adding the second for loop isn't working for me. It just makes it so that you can roll forever.

avatar image igfi · Sep 21, 2013 at 01:06 AM 0
Share

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?

avatar image Fattie · Sep 21, 2013 at 07:46 AM 0
Share

I suggest you start a new question about that, and/or search here/forums for questions about Dictionary.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Melee combat help! 1 Answer

How to start the day at day (Burgzerg Arcade)? 0 Answers

Error CS1503, Error CS1502 1 Answer

"public GameObject" not appearing in Inspector 1 Answer

BurgZergArcade RPG - BaseCharacter script errors. 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges