• 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 /
  • Help Room /
avatar image
0
Question by 22ecvvw · May 22, 2016 at 09:21 PM · error message

Error with my script

 ![using UnityEngine;
 using System.Collections;
 
 public class MainInv_Lab3 : MonoBehaviour {
 
     PF1_IO myIO;
     LAA_Inventory  inv;
     LAA_Items  tempItems;
     LAA_Weapons  tempWeapons;
     LAA_Defense tempDefense;
 
 
     enum STATE { none, name, value, att_def, inputItem };
 
     STATE curState = STATE.none;
 
     string iName = "";
     int value = 0;
     int att_def = 0;
 
     string userInput;
 
     void Start () {
         myIO = PF1_IO.pf;
 
         printInventory();
 
     }
 
     void Update () {
 
         string sInput = ""; 
          
         int itemp = 0;
 
 
         if(myIO.IsThereInput()){
             sInput = myIO.getString();
 
             itemp = myIO.getInteger();
 
             myIO.ClearPreviousInput();
 
 
         }
 
         switch(curState){
 
         case STATE.name:
             myIO.replaceText("Please enter a name for the item.");
 
             if(sInput != ""){
                 print(sInput);
                 iName = sInput;
                 curState = STATE.value;
             }
             break;
 
         case STATE.value:
             myIO.replaceText("Item Name: " + iName + "\nPlease enter a value for the item.");
 
             if(itemp > 0){
                 value = itemp;
                 itemp = 0;
                 curState = STATE.att_def;
             }
             break;
 
         case STATE.att_def:
             myIO.replaceText("Item Name: " + iName + "\nItem Value: " + value + "\n");
 
             if(userInput ==){
                 myIO.appendText("Please enter a stat for the item.");
             }
             else if(userInput ==){
                 myIO.appendText("Please enter a stat for the item.");
 
             if(itemp > 0){
                 att_def = itemp;
                 itemp = 0;
                 curState = STATE.inputItem;
             }
             break;
 
         case STATE.inputItem:
 
             if(userInput == ){
                 
                 myIO.replaceText("Your item has been added to your inventory!");
 
                 WouldYouLikeTo();
             }
     
             if(userInput == ){
 
 
                 
                 myIO.replaceText("Your item has been added to your inventory!");
 
                 WouldYouLikeTo();
             }
             break;
 
         case STATE.none:
             string temp = sInput.ToLower();
 
 
             if(temp ==  || temp == ){
 
                 print(sInput);
                 userInput = temp;
                 sInput = "";
                 curState = STATE.name;
             }
             else if(temp == "inventory"){
                 printInventory();
                 sInput = "";
             }
             break;
 
         }
 
 
 
 
     }
 
     void printInventory(){
 
         myIO.replaceText("You currently have " +  + 
             " items in your inventory. Consisting of:\n");
 
 
         
         WouldYouLikeTo();
 
 
     }
 
     void WouldYouLikeTo(){
 
 
         myIO.appendText("\n\nWould you like to add another type of \"\" or \"\" item to your inventory?" +
             "\n\tOr would you like to see your \"inventory\" again?");
 
         curState = STATE.none;
 
         iName = "";
         value = 0;
         att_def = 0;
         userInput = "";
         
 
 
     }
 
 }][1]
 


[1]: /storage/temp/70554-screen-shot-2016-05-22-at-52033-pm.png

screen-shot-2016-05-22-at-52033-pm.png (115.8 kB)
Comment
Add comment · Show 1
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 22ecvvw · May 22, 2016 at 09:21 PM 0
Share

alt text

screen-shot-2016-05-22-at-52033-pm.png (115.8 kB)

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by TBruce · May 23, 2016 at 01:07 AM

I have fixed the obvious errors baring the fact that I do no have access to these classes

 PF1_IO
 LAA
 LAA_Items
 LAA_Weapons
 LAA_Defense
 and do not know if there are any other further errors.

The main problem though was ther is a lot of missing data. I placed temporary place holders so that you can find and fix the problems. Here is the modified code

 using UnityEngine;
 using System.Collections;
 
 public class MainInv_Lab3 : MonoBehaviour
 {
     PF1_IO myIO;
     LAA_Inventory  inv;
     LAA_Items  tempItems;
     LAA_Weapons  tempWeapons;
     LAA_Defense tempDefense;
 
     enum STATE { none, name, value, att_def, inputItem };
 
     STATE curState = STATE.none;
 
     string iName = "";
     int value = 0;
     int att_def = 0;
 
     string userInput;
     
     // fill in this information below with the correct data
     string missingUserInput1 = "1";      // you need to set the appropriate value for this below, you can then remove this
     string missingUserInput2 = "2";      // you need to set the appropriate value for this below, you can then remove this
 
     string tempString1 = "1";            // you need to set the appropriate value for this below, you can then remove this
     string tempString2 = "2";            // you need to set the appropriate value for this below, you can then remove this
 
     int inventoryItems = 5;              // you need to set the appropriate value for this below, you can then remove this
     
     string yourInventory = "X, Y, Z";    // you need to set the appropriate value for this below, you can then remove this
     string yourInventory1 = "X";         // you need to set the appropriate value for this below, you can then remove this
     string yourInventory2 = "Y";         // you need to set the appropriate value for this below, you can then remove this
 
     void Start ()
     {
         myIO = PF1_IO.pf;
         printInventory();
     }
 
     void Update ()
     {
         string sInput = ""; 
         int itemp = 0;
 
         if(myIO.IsThereInput())
         {
             sInput = myIO.getString();
 
             itemp = myIO.getInteger();
 
             myIO.ClearPreviousInput();
         }
 
         switch(curState)
         {
             case STATE.name:
                 myIO.replaceText("Please enter a name for the item.");
                 if(sInput != "")
                 {
                     print(sInput);
                     iName = sInput;
                     curState = STATE.value;
                 }
                 break;
             case STATE.value:
                 myIO.replaceText("Item Name: " + iName + "\nPlease enter a value for the item.");
                 if(itemp > 0)
                 {
                     value = itemp;
                     itemp = 0;
                     curState = STATE.att_def;
                 }
                 break;
 
             case STATE.att_def:
                 myIO.replaceText("Item Name: " + iName + "\nItem Value: " + value + "\n");
 
                 if(userInput ==)
                 {
                     myIO.appendText("Please enter a stat for the item.");
                 }
                 else if(userInput ==)
                 {
                     myIO.appendText("Please enter a stat for the item.");
                 }
 
                 if(itemp > 0)
                 {
                     att_def = itemp;
                     itemp = 0;
                     curState = STATE.inputItem;
                 }
                 break;
 
             case STATE.inputItem:
                 if(userInput == missingUserInput1)
                 {
                     myIO.replaceText("Your item has been added to your inventory!");
 
                     WouldYouLikeTo();
                 }
 
                 if(userInput == missingUserInput2)
                 {
                     myIO.replaceText("Your item has been added to your inventory!");
 
                     WouldYouLikeTo();
                 }
                 break;
             case STATE.none:
                 string temp = sInput.ToLower();
 
                 if ((temp == tempString1) || (temp == tempString2))
                 {
                     print(sInput);
                     userInput = temp;
                     sInput = "";
                     curState = STATE.name;
                 }
                 else if(temp == "inventory")
                 {
                     printInventory();
                     sInput = "";
                 }
                 break;
         }
     }
 
     void printInventory()
     {
         myIO.replaceText("You currently have " + inventoryItems + " items in your inventory. Consisting of: " + yourInventory + "\n");
 
         WouldYouLikeTo();
     }
 
     void WouldYouLikeTo()
     {
         myIO.appendText("\n\nWould you like to add another type of \"" + yourInventory1 + "\" or \"" + yourInventory1 + "\" item to your inventory?" +
         "\n\tOr would you like to see your \"inventory\" again?");
 
         curState = STATE.none;
         iName = "";
         value = 0;
         att_def = 0;
         userInput = "";
     }
 }
Comment
Add comment · Show 4 · 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 22ecvvw · May 23, 2016 at 02:24 AM 0
Share
 using UnityEngine;
 using System.Collections;
 
 public class LAA_Weapons : LAA_Items {
 
     int damage;
     int ammosize;
 
     public LAA_Weapons()
     {
         this.Type = "Weapon";
         this.Name = "Assualt Rifle";
         this.Price = 750;
         damage = 100;
         ammosize = 25;
 
     }
     public LAA_Weapons(string n, int p, int d)
     {
         this.Type = "Weapon";
         this.Name = n;
         this.Price = p;
         damage = d;
         ammosize = 0;
     }
     public int getDamage()
     {
         return damage;
     }
     public int getAmmosize()
     {
         return ammosize;
     }
 
     public string sendInfo ()
     {
         string send;
 
         send = "\nname: " + this.Name + " price " + this.Price + " damage " + this.damage;
 
         return send;
     }
 }    
avatar image TBruce 22ecvvw · May 23, 2016 at 02:35 AM 0
Share

First you need to fix the issues I pointed out above. You will see these variables that I added to the class where you need to place the intended data.

 // fill in this information below with the correct data
 string missingUserInput1 = "1";      // you need to set the appropriate value for this below, you can then remove this
 string missingUserInput2 = "2";      // you need to set the appropriate value for this below, you can then remove this
 
 string tempString1 = "1";            // you need to set the appropriate value for this below, you can then remove this
 string tempString2 = "2";            // you need to set the appropriate value for this below, you can then remove this
 
 int inventoryItems = 5;              // you need to set the appropriate value for this below, you can then remove this
 
 string yourInventory = "X, Y, Z";    // you need to set the appropriate value for this below, you can then remove this
 string yourInventory1 = "X";         // you need to set the appropriate value for this below, you can then remove this
 string yourInventory2 = "Y";         // you need to set the appropriate value for this below, you can then remove this

this.Type and this.Name are errors because they are not apart of LAA_Defense or LAA_Items.

this.name is valid (lowercase) because it is available to all objects. You need to define this.Type or this.type but make sure you use the correct case.

When having errors you can also place something like in the code to help show where the error is.

avatar image 22ecvvw · May 23, 2016 at 03:02 AM 0
Share

alt text

screen-shot-2016-05-22-at-104706-pm.png (183.3 kB)
avatar image TBruce 22ecvvw · May 23, 2016 at 03:28 AM 0
Share

You need to fix one problem at a time before adding new code. Also when posting code, please do not post screen shots. People can not help much that way. Please format ALL you code properly and paste the code directly into the body of the question. To do that copy the code to your clipboard and press the "101010" button in the toolbar of the UA text editor. This will format the code so it can be easily read in the forum.

But your problem here is that you are using GetType() as if it is a variable. GetType() is a function and needs to be called like so

 if (inv.GetAutoAt (i).GetType().ToString().ToLower() == "weapons")
 {
 }

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

54 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 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 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

How i do fix this error? Assets/CameraController.cs(17,13): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement,Unity Scripts error 1 Answer

Position is infinite 0 Answers

Unity Package Manager Error 4 Answers

"Gradle Build Failed" when building for Android 0 Answers

Unity Project Crash."An abnormal situation has occurred PlayerLoop internal function has been called recursively." 0 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