Degausser commented on a Page, Bar Script (Randomized) v2  -  Jul 24, 2017

You should really cut down this script a bit. Here are a couple examples.

For the last "else" block in the whole script, you randomly select 1-8, and describe as appropriate. With only 8 options, a good method is adding a local alias which just returns a string of possibilities. In this case i would add something like this near the top of my page:

alias -l listSnacks return Boost.Flake.Cherry Ripe.Mars Bar.Snickers Bar.box of Chocolate Hearts.box of Florentins.box of Mont Chocos

Each result is seperated by a dot. The idea is, you can easily add another element to your list, and the code will handle it. If this alias were present within your script, your last else statement could look like this:

else { describe $chan gives $nick a $gettok($listSnacks,$rand(1,$numtok($listSnacks,46)),46) }

Like this, you're simply selecting a random element from your list, using ASCII value 46 (a dot) as your token separator. If you have a longer list of elements, Okay next, you repeat everything twice. Once if %name exists, and once if not. Again taking the last TEXT event as an example, you can replace both if and else statements with a function call, passing in either $2 or $nick. The function will take care of the describe commands. So first the new if and else statement:

if (%name) { describeSnack $chan $2 }
else { describeSnack $chan $nick }

Then youd create a describeSnack alias, with your commands, such as:

alias -l describeSnack {
  var %snack $rand(1,8)
    if (%snack == 1) { describe $1 gives $2 a Boost }
    ... etc / or
    describe $1 gives $2 a $gettok($listSnacks,$rand(1,$numtok($listSnacks,46)),46)
}

And of course, you can minimise these a little more using $iif, so your if/else statement in the end wouldn't need a separate function, or even separation within itself. It would just look like:

describe $chan gives $iif(%name,$2,$nick) a $gettok($listSnacks,$rand(1,$numtok($listSnacks,46)),46)

Just some ideas to save you time!

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.