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 Calesurf · Jun 07, 2015 at 03:18 PM · javascriptlistplayerprefslists

Java Lists

I am making a pokemon like game where you can catch pokemon in the wild. I have everything down to where a boolean is true if I caught it. I want to then if that boolean is true to add the caught pokemon to a list in the player prefs. Basically I don't remember how to make list because I learned how to a long time ago and forgot and I don't know how to store a list in the player prefs. I was looking at the classes unity created in Javascript has and I couldn't find one called list. Is it called something else or is there none. I know c# has it why not javascript.

Here is my code for catching a pokemon.

 #pragma strict
 
 private var    Enemyscript : Enemy;
 private var Healthscript : Health;
 var strength : int;
 var health : int;
 var Monster : GameObject;
 var once : boolean;
 var RandNum : int;
 var catchable : boolean;
 var caught : boolean;
 
 
 function Start () {
     caught = false;
     RandNum = Random.Range(0,50);
 }
 
 function Update () {
      if(catchable){
          if(strength*health >= 480 && RandNum < 3){
              caught = true;
          }
          if(strength*health >= 460 && strength*health< 480 && RandNum < 5){
              caught = true;
          }
          
          if(strength*health >= 440 && strength*health< 460 && RandNum < 7){
              caught = true;
          }
          if(strength*health >= 420 && strength*health< 440 && RandNum < 10){
              caught = true;
          }
          if(strength*health >= 400 && strength*health< 420 && RandNum < 12){
              caught = true;
          }
          if(strength*health >= 380 && strength*health< 400 && RandNum < 14){
              caught = true;
          }
          if(strength*health >= 360 && strength*health< 380 && RandNum < 16){
              caught = true;
          }
          if(strength*health >= 340 && strength*health< 360 && RandNum < 17){
              caught = true;
          }
          if(strength*health >= 320 && strength*health< 340 && RandNum < 19){
              caught = true;
          }
          if(strength*health >= 300 && strength*health< 320 && RandNum < 20){
              caught = true;
          }
          if(strength*health >= 280 && strength*health<  300 && RandNum < 22){
              caught = true;
          }
          if(strength*health >= 260 && strength*health< 280 && RandNum < 24){
              caught = true;
          }
          if(strength*health >= 240 && strength*health< 260 && RandNum < 26){
              caught = true;
          }
          if(strength*health >= 220 && strength*health< 240 && RandNum < 28){
              caught = true;
          }
          if(strength*health >= 200 && strength*health< 220 && RandNum < 30){
              caught = true;
          }
          if(strength*health >= 180 && strength*health< 200 && RandNum < 32){
              caught = true;
          }
          if(strength*health >= 160 && strength*health< 180 && RandNum < 34){
              caught = true;
          }
          if(strength*health >= 140 && strength*health< 160 && RandNum < 36){
              caught = true;
          }
          if(strength*health >= 120 && strength*health< 140 && RandNum < 38){
              caught = true;
          }
          if(strength*health >= 100 && strength*health< 120 && RandNum < 40){
              caught = true;
          }
          if(strength*health >= 80 && strength*health< 100 && RandNum < 42){
              caught = true;
          }
          if(strength*health >= 60 && strength*health< 80 && RandNum < 44){
              caught = true;
          }
          if(strength*health >= 40 && strength*health< 60 && RandNum < 46){
              caught = true;
          }
          if(strength*health >= 20 && strength*health< 40 && RandNum < 48){
              caught = true;
          }
          if(strength*health >= 0 && strength*health< 20 && RandNum < 50){
              caught = true;
          }
          //I Want to add the caught monster to a list here
           if(caught == true && !once){
              print("You Caught A " + Monster.name);
              Monster.gameObject.active = false;
              once = true;
 
          }
          if(caught == false){
              Monster.gameObject.active = true;
              print("The " + Monster.name + " escaped!");
              Destroy(gameObject);
      }
          
      }
     
     
 }
 function OnTriggerEnter(other : Collider){
     if(other.tag == "Monster"){
         other.gameObject.active = false;    
         rigidbody.isKinematic = true;
         Enemyscript = other.GetComponent("Enemy");
         Healthscript = other.GetComponent("Health");
         strength = Enemyscript.strength;
         health = Healthscript.health;
         Monster = other.gameObject;
         if(health*strength >500){
             print("The " + Monster.name + " is to strong!");
              other.gameObject.active = true;
              Destroy(gameObject);
          }
          if(health*strength <= 500){
              catchable = true;
              other.gameObject.active = false;
          }
     }
 }

 
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 fafase · Jun 07, 2015 at 05:29 PM

you need to import

 #import System.Collections.Generic;

then you can use it with a slight alteration:

 var myList : List.<Type> = new List.<Type>();

See the dot after the List? The rest is pretty much the same as C#.

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 Calesurf · Jun 07, 2015 at 09:54 PM 0
Share

Thanks I tried that but didn't put `#import System.Collections.Generic; now it works perfectly

avatar image tanoshimi · Jun 07, 2015 at 10:02 PM 0
Share

So please mark this as having answered your question.

avatar image Calesurf · Jun 07, 2015 at 10:05 PM 0
Share

How would I put this into the player prefs

avatar image fafase · Jun 08, 2015 at 03:52 AM 0
Share

You cannot save a list, you'd have to either save each independently or turn them into a string.

avatar image zRevenger · Jul 19, 2015 at 05:17 PM 0
Share

but how do i add something to this list?

Show more comments

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

20 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

Related Questions

Check if List contains specific object values (JS) 1 Answer

A node in a childnode? 1 Answer

Add Object to list error (JS). 1 Answer

How to make a List Constructor? 1 Answer

from list of entries, select and add to scene beneath previous 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