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
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 = "";
}
}
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;
}
}
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.
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
Follow this Question
Related Questions
Error while trying to build XCode project 0 Answers
Navmesh spam console when desactivated 1 Answer
Failed extracting collision mesh error 0 Answers
Scripting problem 1 Answer