I’m not a good coder; nevertheless, I was wondering if anyone could be so generous as to help me figure out why my code won’t run. The script is a word generator intended to make a made-up language for an interactive comic book. I just can’t seem to figure out how to make the script work. I hope someone can help me. It should be a relatively simple script to write, yet I find myself struggling tremendously. In the script, I went as far as to include notes to make it easier to understand.
If the word generator works, I would gladly let others use it.
(Please don’t be daunted by it’s length. It’s long because I reused the switch statement for all of it’s 8 parts)
#pragma strict
var wordCount : int = 10; //set this to desired amount of words (when the code works); use 10 for testing purposes.
function Start () {
//get number of words you want to make.
for (var x = 0; x< wordCount; x++){
wordGenerator(); //execute wordGenerator function to generate words.
}
}
Debug.Log(word);//print words on screen.
//wordGenerator function
function wordGenerator (){
//arrays
var commons : char ["a","i","u","e","o","ka","ki","ku","ke","ko","sa","shi","su","se","so","ta","chi","tsu","te","to","na","ni","nu","ne","no","ha","hi","fu","he","ho","ma","mi","mu","me","mo","ya","yu","yo","ra","ri","ru","re","ro","wa","n"];
var all : char ["a","i","u","e","o","ba","bi","bu","be","bo","da","di","du","de","do","fa","fi","fu","fe","fo","ga","gi","gu","ge","go","ha","hi","hu","he","ho","ja","ji","ju","je","jo","ka","ki","ku","ke","ko","la","li","lu","le","lo","ma","mi","mu","me","mo","na","ni","nu","ne","no","pa","pi","pu","pe","po","ra","ri","ru","re","ro","sa","si","su","se","so","ta","ti","tu","te","to","va","vi","vu","ve","vo","wa","wi","wu","we","wo","xa","xi","xu","xe","xo","ya","yi","yu","ye","yo","za","zi","zu","ze","zo"];
var addOns : char ["à","è","ì","ò","ù","á","é","í","ó","ú","â","ê","î","ô","û","ā","ī","ū","ē","ō","ã","ĩ","ũ","ẽ","õ","ă","ĭ","ŭ","ĕ","ŏ","ȃ","ȋ","ȗ","ȇ","ȏ","°"];
var endAddOn : char ["ll","s","ss","id","ia","ing","ung","eng","ong"];
//variables
var nothing : char = " "; //space varable.
var word : char; //the function will return this as a full word at the end of the function.
//part variables (not sure it should be a int or char).
var p1 : char;
var p2 : char;
var p3 : char;
var p4 : char;
var p5 : char;
var p6 : char;
var p7 : char;
var p8 : char;
/*
var t1 : int; //incase I need a var to get a part variable as a number and convert it using an integer to string statment. T stands for tempuary.
var t2 : int;
var t3 : int;
var t4 : int;
var t5 : int;
var t6 : int;
var t7 : int;
var t8 : int;
*/
var ranNum : int; //random number variable for the switch statments.
ranNum = Math.random(1,100);//gets a random number from 1 to 100 for the switch statment. The 1-100 will also act as my percentages(1%-100%) for the list and random letters in an arrays to select a syllable for a particular part.
//get p1; all parts (p2-p8)have the same code except for part1.
p1 = switch(ranNum){
case 1:
if (ranNum > 30){
p1 = Math.random()*(commons.length-1); //get a random number(or char) number from the commons array.
}
break;
case 2:
if (ranNum >40){
p1 = Math.random()*(all.length-1);//get a random number(or char) from the all array.
}
break;
case 3:
if (ranNum >60){
p1 = Math.random()*(addOns.length-1);//get a random number(or char) from the addOns array.
}
break;
}
ranNum = Math.random(1,100);
// get P2
p2 = switch(ranNum){
case 1:
if (ranNum > 30){
p2 = Math.random()*(commons.length-1);
}
break;
case 2:
if (ranNum >40){
p2 = Math.random()*(all.length-1);
}
break;
case 3:
if (ranNum >60){
p2 = Math.random()*(addOns.length-1);
}
break;
case 4:
if (ranNum >70){
p2 = Math.random()*(endAddOn.length-1); //get a random number(or char) from the endAddOn array.
}
break;
case 5:
if (ranNum >90){
p2 = nothing; //insert a space (after a digit gets a space all other parts get a space.
}
break;
}
ranNum = Math.random(1,100);
//get p3
p3 = switch(ranNum){
case 1:
if (ranNum > 30){
p3 = Math.random()*(commons.length-1);
}
break;
case 2:
if (ranNum >40){
p3 = Math.random()*(all.length-1);
}
break;
case 3:
if (ranNum >60){
p3 = Math.random()*(addOns.length-1);
}
break;
case 4:
if (ranNum >70){
p3 = Math.random()*(endAddOn.length-1);
}
break;
case 5:
if (ranNum >90){
p3 = nothing;
}
break;
}
if (p2 = nothing){
p3 = nothing; //if part before this one gets a space (nothing variable), then it also gets a space; include all the other parts.I mentioned this before in part1's switch statment.
}
ranNum = Math.random(1,100);
//get p4
p4 = switch(ranNum){
case 1:
if (ranNum > 30){
p4 = Math.random()*(commons.length-1);
}
break;
case 2:
if (ranNum >40){
p4 = Math.random()*(all.length-1);
}
break;
case 3:
if (ranNum >60){
p4 = Math.random()*(addOns.length-1);
}
break;
case 4:
if (ranNum >70){
p4 = Math.random()*(endAddOn.length-1);
}
break;
case 5:
if (ranNum >90){
p4 = nothing;
}
break;
}
if (p3 = nothing){
p4 = nothing;
}
ranNum = Math.random(1,100);
//get P5
p5 = switch(ranNum){
case 1:
if (ranNum > 30){
p5 = Math.random()*(commons.length-1);
}
break;
case 2:
if (ranNum >40){
p5 = Math.random()*(all.length-1);
}
break;
case 3:
if (ranNum >60){
p5 = Math.random()*(addOns.length-1);
}
break;
case 4:
if (ranNum >70){
p5 = Math.random()*(endAddOn.length-1);
}
break;
case 5:
if (ranNum >90){
p5 = nothing;
}
break;
}
if (p4 = nothing){
p5 = nothing;
}
ranNum = Math.random(1,100);
//get p6
p6 = switch(ranNum){
case 1:
if (ranNum > 30){
p6 = Math.random()*(commons.length-1);
}
break;
case 2:
if (ranNum >40){
p6 = Math.random()*(all.length-1);
}
break;
case 3:
if (ranNum >60){
p6 = Math.random()*(addOns.length-1);
}
break;
case 4:
if (ranNum >70){
p6 = Math.random()*(endAddOn.length-1);
}
break;
case 5:
if (ranNum >90){
p6 = nothing;
}
break;
}
if (p5 = nothing){
p6 = nothing;
}
ranNum = Math.random(1,100);
//get p7
p7 = switch(ranNum){
case 1:
if (ranNum > 30){
p7 = Math.random()*(commons.length-1);
}
break;
case 2:
if (ranNum >40){
p7 = Math.random()*(all.length-1);
}
break;
case 3:
if (ranNum >60){
p7 = Math.random()*(addOns.length-1);
}
break;
case 4:
if (ranNum >70){
p7 = Math.random()*(endAddOn.length-1);
}
break;
case 5:
if (ranNum >90){
p7 = nothing;
}
break;
}
if (p6 = nothing){
p7 = nothing;
}
ranNum = Math.random(1,100);
//get p8
p8 = switch(ranNum){
case 1:
if (ranNum > 30){
p8 = Math.random()*(commons.length-1);
}
break;
case 2:
if (ranNum >40){
p8 = Math.random()*(all.length-1);
}
break;
case 3:
if (ranNum >60){
p8 = Math.random()*(addOns.length-1);
}
break;
case 4:
if (ranNum >70){
p8 = Math.random()*(endAddOn.length-1);
}
break;
case 5:
if (ranNum >90){
p8 = nothing;
}
break;
}
if (p7 = nothing){
p8 = nothing;
}
//combine all parts to form a word and return it so that it can go back to it's original module to be printed to the screen.
word = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8;
return word;
}