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 /
  • Help Room /
avatar image
0
Question by Wolfrik_Creations · Jan 19, 2016 at 04:12 AM · javascriptstringindexfor

String Array = Anything?

Hi, I need to figure out how to get any string value in for(). For instance using int/float you can do

 for(var i=MINNUMBER; i<MAXNUMBER; i++){
    if(aTextFieldString=="setplayerhealth "+i){
       do stuff in here
    }
 }

so can I do this with any string and get what has been inputted? Thanks in advance for any answers! :D

Comment
Add comment · Show 3
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 Wolfrik_Creations · Jan 21, 2016 at 03:34 PM 0
Share

Is anyone gonna reply?

avatar image MFen · Jan 21, 2016 at 03:41 PM 0
Share

Not sure what you're asking for, can you expand on your question?

avatar image Wolfrik_Creations MFen · Jan 22, 2016 at 03:42 PM 0
Share

Read the comment I put on Jessespike's answer.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Jessespike · Jan 21, 2016 at 06:37 PM

Your question is not clear. Are you asking how to check strings in an array with a for-loop?

 public var arrayOfStrings : String[];
 
 function Start () {
     for(var i = 0; i < arrayOfStrings.Length; i++){
         if(arrayOfStrings[i]=="setplayerhealth"+i){
             //TODO: do stuff here
         }    
     }
 }
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 Wolfrik_Creations · Jan 22, 2016 at 01:46 AM 0
Share

Thanks for the reply Jessespike!

That's similar but I need it to be any string at all yet get the string, I'm being confusing cause I don't know how to explain it. I'll try.

I'm making mods and need to be able to write into the text file something like "debug to the log (I eat rocks)" and then in my code it would detect if I have "debug to the log" and then find out what is inside those parentheses and make it run Debug.Log(whatsInTheParentheses);

I don't know if that makes since either but you can have my code and take a look at what I have now (which has nothing to do with strings because I haven't started coding them yet because I need help with this).

 #pragma strict
 import System.IO;
 import System.Collections.Generic;
 private var allObjects:GameObject[];
 private var allSounds:AudioClip[];
 var chars:$$anonymous$$eyCode[];
 var contents:String[];
 private var mods:String[];
 private var spawns:GameObject[];
 private var connected=false;
 
 function Start(){
     allSounds=Resources.FindObjectsOfTypeAll(typeof(AudioClip));
     var di=new DirectoryInfo(Application.dataPath+"/$$anonymous$$ods");
     mods=Directory.GetFiles(Application.dataPath+"/$$anonymous$$ods", "*.drmod");
     allObjects=GameObject.FindObjectsOfType(GameObject);
     if(di.Exists==false){
         di.Create();
     }
     yield;
     for(var mod=0; mod<mods.Length; mod++){
         contents=mods;
         yield;
         contents[mod]=File.ReadAllText(mods[mod]);
     }
 }
 
 function OnConnectedToServer(){
     yield WaitForSeconds(1);
     spawns=ClientControls.cc.spawnItems;
     allObjects=GameObject.FindObjectsOfType(GameObject);
 }
 
 function OnServerInitialized(){
     yield WaitForSeconds(1);
     spawns=ClientControls.cc.spawnItems;
     allObjects=GameObject.FindObjectsOfType(GameObject);
 }
 
 function Update(){
     if(Network.isServer||Network.isClient){
         connected=true;
     if(mods.Length==0){
         Destroy(this);
     }
     for(var mod=0; mod<mods.Length; mod++){
         if(Has(contents[mod],"instance.dupeAtPlayer.clientSide")){
         for(var a=0; a<allObjects.Length; a++){
             if(Has(contents[mod],"instance.dupeAtPlayer.clientSide ("+allObjects[a].name+")")){
                 for(var chara=0; chara<chars.Length; chara++){
                     if(Has(contents[mod],"script.activatedViaConsole()")){
                         if(ClientControls.whatToYell=="modFile."+mod+".Run()"){
                             ClientControls.whatToYell="";
                             Instantiate(allObjects[a], ClientControls.cc.itemSpawnLocation.position, ClientControls.cc.itemSpawnLocation.rotation);
                         }
                     }
                     if(Has(contents[mod],"input.keyPress ("+chars[chara]+")")){
                     if(Input.Get$$anonymous$$eyDown(chars[chara])){
                         Instantiate(allObjects[a], ClientControls.cc.itemSpawnLocation.position, ClientControls.cc.itemSpawnLocation.rotation);
                     }
                     }
                 }
             }}
         }
         for(var ad=0; ad<allSounds.Length; ad++){
             if(Has(contents[mod],"sound.play.Audio ("+allSounds[ad]+")")){
                 for(var chr=0; chr<chars.Length; chr++){
                     if(Has(contents[mod],"script.activatedViaConsole()")){
                         if(ClientControls.whatToYell=="modFile."+mod+".Run()"){
                             ClientControls.whatToYell="";
                             GetComponent.<AudioSource>().PlayOneShot(allSounds[ad]);
                         }
                     }
                     if(Has(contents[mod],"input.keyPress ("+chars[chr]+")")){
                     if(Input.Get$$anonymous$$eyDown(chars[chr])){
                         GetComponent.<AudioSource>().PlayOneShot(allSounds[ad]);
                     }
                     }
                 }
             }
         }
         for(var t=-100.0; t<100.0; t++){
             if(Has(contents[mod],"deadReign.timeScale ("+t+")")){
                 for(var chch=0; chch<chars.Length; chch++){
                     if(Has(contents[mod],"script.activatedViaConsole()")){
                         if(ClientControls.whatToYell=="modFile."+mod+".Run()"){
                             ClientControls.whatToYell="";
                             Time.timeScale=t;
                         }
                     }
                     if(Has(contents[mod],"input.keyPress ("+chars[chch]+")")){
                     if(Input.Get$$anonymous$$eyDown(chars[chch])){
                         Time.timeScale=t;
                     }
                     }
                 }
             }
         }
         if(AnimationCore.farts!=null){
         for(var s=0; s<AnimationCore.farts.Length; s++){
             if(Has(contents[mod],"sound.play.shitIndex ("+s+")")){
                 for(var charc=0; charc<chars.Length; charc++){
                     if(Has(contents[mod],"script.activatedViaConsole()")){
                         if(ClientControls.whatToYell=="modFile."+mod+".Run()"){
                             ClientControls.whatToYell="";
                             GetComponent.<AudioSource>().PlayOneShot(AnimationCore.farts[s]);
                         }
                     }
                     if(Has(contents[mod],"input.keyPress ("+chars[charc]+")")){
                     if(Input.Get$$anonymous$$eyDown(chars[charc])){
                         GetComponent.<AudioSource>().PlayOneShot(AnimationCore.farts[s]);
                     }
                     }
                 }
             }
         }}
         if(Has(contents[mod],"instance.spawn$$anonymous$$enu.spawn")){
         for(var b=0; b<spawns.Length; b++){
             if(Has(contents[mod],"instance.spawn$$anonymous$$enu.spawn ("+spawns[b].name+")")){
                 for(var chare=0; chare<chars.Length; chare++){
                     if(Has(contents[mod],"script.activatedViaConsole()")){
                         if(ClientControls.whatToYell=="modFile."+mod+".Run()"){
                             ClientControls.whatToYell="";
                             Network.Instantiate(spawns[b], ClientControls.cc.itemSpawnLocation.position, ClientControls.cc.itemSpawnLocation.rotation, 0);
                         }
                     }
                     if(Has(contents[mod],"input.keyPress ("+chars[chare]+")")){
                     if(Input.Get$$anonymous$$eyDown(chars[chare])){
                         Network.Instantiate(spawns[b], ClientControls.cc.itemSpawnLocation.position, ClientControls.cc.itemSpawnLocation.rotation, 0);
                     }
                     }
                 }
             }}
             if(Has(contents[mod],"player.addToInventory")){
             if(Has(contents[mod],"player.addToInventory ("+spawns[b].name+")")){
                 for(var charf=0; charf<chars.Length; charf++){
                     if(Has(contents[mod],"script.activatedViaConsole()")){
                         if(ClientControls.whatToYell=="modFile."+mod+".Run()"){
                             ClientControls.whatToYell="";
                             var tempaddtoinv=Network.Instantiate(spawns[b], ClientControls.cc.itemSpawnLocation.position, ClientControls.cc.itemSpawnLocation.rotation, 0);
                             tempaddtoinv.transform.parent=InventoryCore.bpack;
                         }
                     }
                     if(Has(contents[mod],"input.keyPress ("+chars[charf]+")")){
                     if(Input.Get$$anonymous$$eyDown(chars[charf])){
                         tempaddtoinv=Network.Instantiate(spawns[b], ClientControls.cc.itemSpawnLocation.position, ClientControls.cc.itemSpawnLocation.rotation, 0);
                         tempaddtoinv.transform.parent=InventoryCore.bpack;
                     }
                     }
                 }
             }}
         }
     }
     }
 }
 
 function Has(orig:String,convert:String){
     for (var i = 0; i < 100000; i++){
         return orig.IndexOf(convert, System.StringComparison.OrdinalIgnoreCase) != -1;
     }
 }

and here is an example of one of my player made mods that I've implemented into the game.

 input.keyPress (G)
 sound.play.Audio (Nuke (UnityEngine.AudioClip))
 instance.spawn$$anonymous$$enu.spawn (UFO)

In a more simple way of putting it... I'm trying to make my own coding language that translates to unity script.

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

46 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 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

Combining multiple strings in Javascript 1 Answer

Format Exception when trying to parseFloat(String) 2 Answers

Finding all the same strings in a List 2 Answers

A certain string is causing trouble! (Javascript) 0 Answers

how I change this Js code for 2D 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