Saturday, 23 December 2017

Add jokes to your E2B menu for Xmas

Here is a small grub4dos script that allows you to display one of 36 randomly-chosen jokes on your E2B menus.

You must update to E2B v1.97A or later for this to work properly due to some bugs in older versions of grub4dos.


Instructions...

We could add the RandomJoke.g4b script to the MyE2B.cfg file, but this would always show the same joke on all the the menu screens. We really want to display a different joke whenever a different menu is loaded...

1. Download and copy the RandomJoke.g4b file to the \_ISO folder of your E2B USB drive.
The file can be found in the Alternate Download Area - Other files folder.

2. Ensure your menu layout has enough room for the joke's text to be written on the right-hand side of the menu - e.g. use a menu width of 60 or less in the MyE2B.cfg file, e.g.

set menuw=60

3. Create a $$$$RandomJoke.mnu menu text file to call a small script file (RJ.g4b), so that the joke is changed each time a new menu is loaded, e.g. :

\_ISO\MAINMENU\$$$$RandomJoke.mnu (contains just one line only):

call /_ISO/RJ.g4b

Note: The .mnu file must be enumerated first, before all other .mnu files or payload files are enumerated, so ensure the file name starts with $$$$.

Copy the same $$$$RandomJoke.mnu file to ALL the E2B menu folders...
\_ISO\MAINMENU
\_ISO\WINDOWS       
\_ISO\AUTO              
\_ISO\ANTIVIRUS 
\_ISO\DOS          
\_ISO\BACKUP   
\_ISO\LINUX        
\_ISO\UTILITIES
\_ISO\UTILITIES_MEMTEST
\_ISO\WIN       
\_ISO\WINPE        

4. Create a new \_ISO\RJ.g4b text file containing the following text:
!BAT
call /_ISO/RandomJoke.g4b 65 17 0xFFFFFF


By editing the RJ.g4b file, we can easily change the joke's position and colour in all the menus.

How to modify the joke position and colour

We can change \_ISO\RJ.g4b to adjust the text position.

The RandomJoke.g4b script can be given up to 4 parameters:

# Usage: 
# call /_ISO/RandomJoke.g4b [x-coordinate] [y-coordinate]  [hex colour] [joke number]
# default x value = 65, default y value = 17, default colour = yellow,  joke number (1-36) - default = random

The joke will consist of up to 6 short lines of text.

You can change the x,y position of the first line (e.g. x=65, y=20) as follows:

call /_ISO/RandomJoke.g4b 65 20

You can also change the text colour (always with a transparent background) as follows:
call /_ISO/RandomJoke.g4b 65 20 0xFF00FF

The 24-bit colour is in the format 0xRRGGBB where each 8-bit value is 00-FF. e.g. 0xFF0000 is full red, 0x00FF00 is full green, 0x000080 is half-blue, 0xFFFF00 is full-red+full-green=yellow.

If you always want the same joke (!) (or for testing a new joke which you have added), you can  specify the joke number (e.g. 24):
call /_ISO/RandomJoke.g4b 65 20 0xFF00FF 24


Add more jokes

To add your own jokes, edit the max value in the RandomJoke.g4b file and add more joke lines.
L1 is line 1 of the joke, L2 is line 2 of the joke, etc.
Keep each line short or it will go off the screen.
Hopefully it is fairly easy to see what you need to do...

# get a random number between 1 and max
set max=36

...


if %randnum%==35 set L1="Hedgehogs – why can't" && set L2="they just share the hedge?"
if %randnum%==36 set L1="If you don’t know what" && set L2="introspection is, you need to take" && set L3="a long, hard look at yourself."

#Add more lines here for joke #37, #38, etc.


Random means Random!

When Apple released the iPod it had a random play option.

When people used this, they complained that sometimes it played the same song twice, or it chose the same song too often.

You may find the same issue with the random joke algorithm. You may find that the same joke is repeated twice, or that it seems to 'favour' one joke more than another. This is just the nature of 'random' - if we have 36 jokes, then we have 1 chance in 36 that it will pick the same joke twice or indeed at any time.

Apple 'fixed' this by causing the software to remember the last few tunes and not playing again any of the tunes that had been recently played.

This meant that the 'random' play was no longer truly random!

A later approach was to 'randomly shuffle' the tunes into a list of up to 100 or so tunes. When all tunes in the list had been played, it would re-shuffle the entire list again.

This is a lesson for us all.  I have always found it useful to question a user's requirements - because they don't always really want what they ask for!

P.S. Which one is your favourite joke? Add a comment below and let us know...