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
Not sure what you're asking for, can you expand on your question?
Read the comment I put on Jessespike's answer.
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
}
}
}
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.