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 T-D-M-3 · Jun 21, 2015 at 10:48 PM · scripting problemvariablescriptingbasicssave dataquest

Scan for a variable based upon an integer

so i am trying to make a quest system for a game and the problem currently at hand is that each one of the 60 quests has a save data variable. what i need to do is make it so the script checks a variable without running if statements 60 times.

 if(questvar == 1){
 status = Savedata.Quest1;
 }
 
 if(questvar == 2){
 status = Savedata.Quest2;
 }
 
 if(questvar == 3){
 status = Savedata.Quest3;
 }
 
 if(questvar == 4){
 status = Savedata.Quest4;
 }
 
 //and continues all the way to 60
 

if there is already an answer out there please point me to it, if not any help on this would be appreciated -T.D.M.3

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by pako · Jun 22, 2015 at 09:20 AM

I think what your are trying to do can be simply accomplished as follows:

  1. Each Quest script should have a public variable "Status", which is what you want to access, and has been assumed to be int in this example (but it can be anything you want). The "Status" variable replaces the QuestX variables.

  2. All Quest scripts should be held (referenced) by the current script, meaning the one that has all the if statements.

Here's the code:

 using System.Collections.Generic; //needed to use List

 //Drag-n-Drop Quests in Inspector
 //Or use GetComponent to populate the Quests List (Quests can then be made private)
 public List<Quest> Quests;  //hold all Quests in a List. 
 private int status;
 

 //Call this method when you want to get the status
 void CheckQuestStatus(int QuestNumber)
 {
     int questIndex = QuestNumber - 1; //First List index = 0
     
     if (questIndex >= 0)
     {
         this.status = Quests[questIndex].Status;
     }
     else
     {
         Debug.Log("Quest Number must be greater than 0");
     }
     
 }


Comment
Add comment · Show 1 · 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 T-D-M-3 · Jun 22, 2015 at 11:04 AM 0
Share

I forgot to mention that i work in java script so i don't Quite know how to convert this. aside from that, I think this will work. Thanks!

avatar image
0

Answer by Xarbrough · Jun 21, 2015 at 11:20 PM

What are you exactly trying to do? I think you can greatly improve your design by getting rid of the integer "questvar".

In what form is your SaveData.QuestX?

Generally you should store all of your quests in either a Dictionary, so that you can retrieve a quest by its Dictionary key (a string name) or in a List, if they are consecutive. Then you could have a method "GetNextQuest" which just takes the current quest and returns the next item in the list.

Comment
Add comment · Show 1 · 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 T-D-M-3 · Jun 22, 2015 at 01:30 AM 0
Share

i am trying to make a single script to display progress on any given Quest. There will be 60 instances of the Quest script, however i am just trying to make a lighter simpler script to compensate. the data is actually preloaded on start-up so i just need to access a variable on the load side of the save script.

i am also trying to make it so can have all 60 Quests available at once not just a series of tasks (more free-roam style)

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

23 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

Related Questions

Hello can anyone help me i am new in scripting 1 Answer

How to make door open and close with Input.GetButtonDown? 1 Answer

How to check if variable defined in script is present in shader? 1 Answer

Importing a class into multiple scripts 0 Answers

how can I change a light with multiple triggers. ? 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