this logic isnt working as intended, I'm trying to dynamically slightly change quality…
- User
this logic isnt working as intended, I'm trying to dynamically slightly change quality and duration based off of length of speak string
else { if(speak.Length > 10) { MusicGenQuality.Text = "13"; MusicGenDuration.Text = "4"; } if (speak.Length < 10) { MusicGenQuality.Text = "10"; MusicGenDuration.Text = "3"; } if (speak.Length < 30) { MusicGenQuality.Text = "15"; MusicGenDuration.Text = "6"; } string mixLine = "[verse]" + Environment.NewLine + speak; GenSongLazy(speak); }
- Assistant
Your current logic has overlapping
ifconditions that cause unexpected behavior because multiple conditions can be true for the same length, and there's noelse if. For example, ifspeak.Lengthis 5, it satisfies both< 10and< 30, so the second and third blocks will execute sequentially, overriding previous values.How to fix:
Use
if-else if-elsestructure to ensure only one block executes, and arrange the conditions properly (usually from the most restrictive to the least):csharpif (speak.Length > 30) { MusicGenQuality.Text = "15"; MusicGenDuration.Text = "6"; } else if (speak.Length > 10) { MusicGenQuality.Text = "13"; MusicGenDuration.Text = "4"; } else { MusicGenQuality.Text = "10"; MusicGenDuration.Text = "3"; }