Hi guys
I am working on the code for the text based side of my Volleyball Manager game, was seeing if I could get some help for the structure of my scripting
function Update () {
if (teamserve == 1 homerotation == 1) { // home team is serving in rotation 1
matchcommentary = matchcommentary + "\n" + home1name + " is serving";
servenumber = Random.Range(1,1000);
passnumber = Random.Range(1,1000);
servedirection = Random.Range(1,3);
if (servedirection == 1) {
matchcommentary = matchcommentary + "\n" + home1name + " has served at " + away2name;
if (servenumber > passnumber) {
if (servenumber >= 0 servenumber <= 100) {
matchcommentary = matchcommentary + "\n" + away2name + " has shanked the ball into the crowd\n*****(" + homescoreset1 + " - " + awayscoreset1 + ")*****";
}
else if (servenumber > 100 servenumber <= 200) {
matchcommentary = matchcommentary + "\n" + away2name + " has passed the ball off the net";
}
else if (servenumber > 200 servenumber <= 400) {
matchcommentary = matchcommentary + "\n" + away2name + " has passed the ball nicely into position";
}
else if (servenumber > 400 servenumber <= 1000) {
matchcommentary = matchcommentary + "\n" + away2name + " passes perfect";
}
}
if (passnumber > servenumber) {
if (servenumber >= 0 servenumber <= 500) {
matchcommentary = matchcommentary + "\n" + away2name + " has passed nicely";
}
else if (servenumber > 500 servenumber <= 800) {
matchcommentary = matchcommentary + "\n" + away2name + " has got the ball high in the middle";
}
else if (servenumber > 800 servenumber <= 900) {
matchcommentary = matchcommentary + "\n" + away2name + " has trouble with the pass";
}
else if (servenumber > 900 servenumber <= 1000) {
matchcommentary = matchcommentary + "\n" + away2name + " has been aced\n*****(" + homescoreset1 + " - " + awayscoreset1 + ")*****";
}
}
}
if (servedirection == 2) {
matchcommentary = matchcommentary + "\n" + home1name + " has served at " + away7name;
if (servenumber > passnumber) {
if (servenumber >= 0 servenumber <= 100) {
matchcommentary = matchcommentary + "\n" + away7name + " has shanked the ball into the crowd\n*****(" + homescoreset1 + " - " + awayscoreset1 + ")*****";
}
else if (servenumber > 100 servenumber <= 200) {
matchcommentary = matchcommentary + "\n" + away7name + " has passed the ball off the net";
}
else if (servenumber > 200 servenumber <= 400) {
matchcommentary = matchcommentary + "\n" + away7name + " has passed the ball nicely into position";
}
else if (servenumber > 400 servenumber <= 1000) {
matchcommentary = matchcommentary + "\n" + away7name + " passes perfect";
}
}
if (passnumber > servenumber) {
if (servenumber >= 0 servenumber <= 500) {
matchcommentary = matchcommentary + "\n" + away7name + " has passed nicely";
}
else if (servenumber > 500 servenumber <= 800) {
matchcommentary = matchcommentary + "\n" + away7name + " has got the ball high in the middle";
}
else if (servenumber > 800 servenumber <= 900) {
matchcommentary = matchcommentary + "\n" + away7name + " has trouble with the pass";
}
else if (servenumber > 900 servenumber <= 1000) {
matchcommentary = matchcommentary + "\n" + away7name + " has been aced\n*****(" + homescoreset1 + " - " + awayscoreset1 + ")*****";
}
}
}
if (servedirection == 3) {
matchcommentary = matchcommentary + "\n" + home1name + " has served at " + away5name;
if (servenumber > passnumber) {
if (servenumber >= 0 servenumber <= 100) {
matchcommentary = matchcommentary + "\n" + away5name + " has shanked the ball into the crowd\n*****(" + homescoreset1 + " - " + awayscoreset1 + ")*****";
}
else if (servenumber > 100 servenumber <= 200) {
matchcommentary = matchcommentary + "\n" + away5name + " has passed the ball off the net";
}
else if (servenumber > 200 servenumber <= 400) {
matchcommentary = matchcommentary + "\n" + away5name + " has passed the ball nicely into position";
}
else if (servenumber > 400 servenumber <= 1000) {
matchcommentary = matchcommentary + "\n" + away5name + " passes perfect";
}
}
if (passnumber > servenumber) {
if (servenumber >= 0 servenumber <= 500) {
matchcommentary = matchcommentary + "\n" + away5name + " has passed nicely";
}
else if (servenumber > 500 servenumber <= 800) {
matchcommentary = matchcommentary + "\n" + away5name + " has got the ball high in the middle";
}
else if (servenumber > 800 servenumber <= 900) {
matchcommentary = matchcommentary + "\n" + away5name + " has trouble with the pass";
}
else if (servenumber > 900 servenumber <= 1000) {
matchcommentary = matchcommentary + "\n" + away5name + " has been aced\n*****(" + homescoreset1 + " - " + awayscoreset1 + ")*****";
}
}
}
}
This is an example of the code I am currently implementing. This example shows how the actions of only ONE skill are decided in the game and inside all of these nested ifs will be branched out to around 4-5 more different skills which I know can create a ton of hassles when debugging in the future. I am not so concerned at the moment about the content of the code but I want to get into good coding habits which will make it easier to debug in the future and was seeing if anyone could help with the structure. One problem I already see is that I have hard-coded the player names in the choices which makes it difficult to substitute players when they are taken off the field or changed into position.
Thanks in advance