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
1
Question by Ultrapilpo · Jan 19, 2016 at 09:16 PM · shaderlistsclassescrafting

Lists within lists to make a crafting system

Hi,

So I created this class called recipe..All I am trying to do for now is to make a few lists with the different recipe's for items...

so for example..I want a list that contains the stick, rock and vine items and this list will be called 'axeRecipe' because these three things are needed to make an axe.

I have another list with the items my player currently has called 'items1'...so I want to basically go through these items and check if they are in any of the lists such as 'axeRecipe'....But right now I can't even get the lists to work. I am pretty inexperienced.

So how do I create a list containing the three items in the class below?

And then how can I make it so that the script checks my 'items1' list (list of items in players inventory) and goes through them to see if they are in the axeRecipe list?

public class recipe { public Item stick; public Item rock; public Item vine;

 public recipe(Item item1, Item item2, Item item3)
 {
     Debug.Log ("hello");
 }
 

}

Thanks

Philip

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 SterlingSoftworks · Jan 19, 2016 at 10:22 PM 0
Share

H$$anonymous$$$$anonymous$$$$anonymous$$$$anonymous$$ This sounds very similar to a game I'm making right now :P

avatar image Ultrapilpo SterlingSoftworks · Jan 20, 2016 at 08:10 PM 0
Share

making a craft survival game?

avatar image SterlingSoftworks Ultrapilpo · Jan 21, 2016 at 11:11 AM 0
Share

I am! You're a little cave man that has to run around and gather rocks/flint/sticks etc to craft stuff and stay alive during the night time. Eventual goal is find Woman and make Baby. :D

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by ShadyProductions · Jan 19, 2016 at 09:27 PM

You would have to setup if statements to check for the items individually, its not so effective to do it your way.

You would have an Inventory list which contains all the items and you would probably use a for loop to iterate through it, grab the necessary items, remove them and add an axe for example.

and set that up in some kind of method. Here's an example. Note: This is only an example, as I don't know how you have your inventory code set up.

 void makeItem(int itemToMake, int item1, int item2, int item3) {
  //add more if you want more items to be in the recipe
 if (findItem(Inventory, item1) && findItem(Inventory, item2) && findItem(Inventory, item3)) {
 //delete the items from list
 //add new item to the list
 }
 }
 
 bool findItem(List<int> list, int item) {
 for (int i=0; i < list.Count; i++) {
 if (list[i] == item) {
 return true;
 }
 }
 return false;
 }
Comment
Add comment · Show 6 · 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 Ultrapilpo · Jan 20, 2016 at 09:21 PM 0
Share

bool findItem(List list, int item) {

for (int i=0; i < list.Count; i++) { For some reason it won't recognize what a 'List' is here....? So the word 'List' is red and it won't understand list.Count...the'Count' is in red again... I have my using Systems.Collections.Generic up the top......any ideas? Thanks for this. It's eye-opening stuff for someone relatively new like myself.
avatar image ShadyProductions Ultrapilpo · Jan 21, 2016 at 08:41 PM 0
Share

probably because its not List but List<int>

but I wasn't 100% I just wrote this real quick as an example on a way to do things.

avatar image Ultrapilpo · Jan 20, 2016 at 09:54 PM 0
Share

One other thing I don't understand is how I make sure that item1, item2 and item3 are a stick, a rock and a vine....?

In void Update() do I check if my inventory has these three items (using a similar loop found in findItem()) and then I can run void makeItem()?

Thanks for the help so far.

avatar image matthew2 Ultrapilpo · Jan 20, 2016 at 11:18 PM 0
Share

Say something like, if item1.id = blank

avatar image SterlingSoftworks Ultrapilpo · Jan 21, 2016 at 12:21 AM 0
Share

Well, you can't just make item1 = stick.. That's something that you need to remember on your own.

Like, in my inventory system I have 16 different items that are collectible. So, I set up two arrays that were both size 16. One was a String[] and the other was an int[]

So, when I pick up an item, I check the tag of the item I picked up in a for loop. Once the tag is == to the slot in the String[] I then set that slot # in the int[i] to +1. This isn't the most dynamic way to have an inventory system, but it works for my game and it's turned out pretty good. :D

Now that the int[] has been figured out all that's needed now is to set up your recipes.

I hope that helps you understand a little bit more of what's required of you.

avatar image ShadyProductions Ultrapilpo · Jan 21, 2016 at 08:42 PM 0
Share

I guess yeah or make a whole method for it that uses both methods lol, methodception

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Trouble with Add-ing and Retrieving from a List of Custom Class 1 Answer

UNITYSCRIPT - Class's and Instances - Functions/Methods - Correct Usage 0 Answers

How to search a certain variable in a list of a created class (C#) 1 Answer

Trying to make a simple quest system, but i stuck how to do 0 Answers

Save an array with custom classes 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