Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Luzhien · Jul 03, 2011 at 04:49 PM · booleancheck

Check slected mission status in inspector

Hi, I'm working in an adventure game where multiple missions can be done and some NPC will react to you different if you complete a concret one. So I need my NPC to check if the player has this mission as acomplished or not but there will be 100+ of tasks to do so I would need to expose the mission to check in the inspector (var missionToCheck = 1; or something)and type directly the one to check in every NPC. Missions are stored in MissionStatus.js as booleans (var mission1 = false, var mission2 = false, etc) and when one is complete it turns true in this script. How to tell my NPC wich boolean to check? If I use a String in the inspector and type mission1 for instance it doesn't work (or I made a mistake) cause it send a String to check and I need to check the boolean. When the script checks if the String is true or false allways returns true cause it has a String, it doesn't check if the String says mission1 or mission22 and then check for the boolean, and that's what I need.

Sorry if it's too long and for my english. Thanks in advance

Comment
Add comment
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

1 Reply

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

Answer by SilverTabby · Jul 03, 2011 at 08:32 PM

It looks like you are looking for a Hashtable. A hashtable stores a variable number of key and value pairs.

A key is an object that is used like an address, usually a string like a user name: "guest1", "Leroy Jenkins", etc.

A value is what you are trying to store, this can be anything. An example is a password: "letmein", "p4ssw0rd", etc.

In the username/password example, whenever I input the username to the Hashtable, it will spit out the associated password. I can then check that against what the user said is their password and accept or deny a login request.

Hashtables are very processor efficient usually finding your stored value in a short, constant amount of time no matter how many objects are stored, but can become major memory hogs if there is too much information stored in them.

Here is an example of how to use a Hashtable (in C#, not javascript):


 using UnityEngine;
 using System.Collections;
 using System.Collections.Hashtable;
 Class Example : MonoBehaviour
 {
     int SIZE = 32;
     void Start()
     {
         //creates an empty Hashtable that can store SIZE key/value pairs
         Hashtable quests = new Hashtable(SIZE);
         //will automatically resize if more than SIZE keys are added.
 
         //you might need to use this if it says it can't find the namespace
             //System.Collections.Hashtable ... = new System.Collections.Hashtable();
 
         //creates a new key "MainQuest" and assigns the value -1 to it.
         quests.Add("MainQuest", -1);
         Debug.Log(quests["MainQuest"]);//outputs -1
 
         //thorws an exception if a key already exists
         try
         {   quests.Add("MainQuest", 0);//throws an exception    }
         catch
         {   Debug.Log("The value \"MainQuest\" already exists!");    }
         Debug.Log(quests["MainQuest"]); //outputs -1
 
         //can return and change values in this manner
         quests["MainQuest"] = 1;
         Debug.Log(quests["MainQuest"]);//outputs 1
 
         //can create new key/value pairs in this manner
         quests["SideQuest"] = 2;
         Debug.Log(quests["SideQuest"]);//outputs 2
     }
 }




There is a lot more to Hastables than I have written here, but these are the basics to using them.

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 Luzhien · Jul 04, 2011 at 11:40 AM 0
Share

hi SilverTabby, thanks a lot for your answer. When I read it yesterday I didn't understand it cause I'm not familiar with hashtables so I was reading about them before reply. Now I have created some arrays with values and all the stuff but I have a doubt. The array it's created in the Start function so every time I hit Play it is created and working fine. So if I acces from other script and change some value cause a quest was finished it works and I can check this values from my NPC in order to react according whith them. But... if the array is recreated every time I strart the game the values are reset to the ones in the Start function. If I wanted to use booleans was cause they are easy to work with but I don't see the way to mantain the arrays values for playing next time without loosing the work done. Sorry for my limited knowledge but I will apreciatte some more help if you have the time. Thanks in advance. (I vote possitive your reply cause I assume it works and it's just my fault)

avatar image Luzhien · Jul 04, 2011 at 06:08 PM 0
Share

Sorry, stupid question. I can store data in a xml file. Thanks a lot for your help :)

avatar image SilverTabby · Jul 04, 2011 at 11:28 PM 0
Share

Hashtables and other data structures like them are complex things. The only reason I knew about Hashtables is because I took a formal Computer Science course in school. If you don't understand it at first, that's normal - it's quite literally a concept people go to college to learn.

Just look it over, try a few things, take a break if you're having trouble, and then come back and try a few more things. You'll figure it out eventually.

Good luck with your quests!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Pass bool value from multiple objects to one file to check their values? 1 Answer

Problem with OnTriggerStay2D function 2 Answers

Boolean Uncheck Inspector if False 2 Answers

How do I check a boolean from another script in C#? 0 Answers

Why would a boolean change when checked by another script? 1 Answer


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