///////////////////////////////////////////////////////////////////////////// // crystalball.mel Version 1.1 by Andrew Osiow Copyright 2009 // // fun script to emulate a fortune teller in Maya // User can type in a question and get back one of a few standard answers // // Uses sytem to generate random number - current set for Windows only // // The interface consists of a dummy question area and random generated answer // ///////////////////////////////////////////////////////////////////////////// global proc crystalball() {// opens a Crystal Ball/Fortune Telling interface // delete any old Crystalball window preferences if (`windowPref -ex crystalBallWindow`) windowPref -remove crystalBallWindow; // delete any old Crystalball window structures if (`window -ex crystalBallWindow`) deleteUI crystalBallWindow; // create a window structure string $crystalBallWin = `window -title "CrystalBall v1.0" -iconName "CrystalBall" -rtf 1 -s 0 // resize to fit - no size gadget crystalBallWindow`; // create Crystal Ball layout string $crystalBallForm = `formLayout -w 200 -h 110 -numberOfDivisions 100`; text -label "State Your Question." cbQuestionLabelText; text -label "Response:" cbAnswerLabelText; textField -text "Type a \"Yes or No\" Question" -width 190 cbQuestionGadet; textField -text "" -ed false -width 116 cbAnswerGadet; button -width 90 -height 26 -label "Tell Me!" -align "center" -command "makeCrystalBallAnswer" crystalBallTellMeButton; // Answer Question button -width 90 -height 26 -label "I'm Done." -command "deleteUI crystalBallWindow" closeCrytalBallButton; // Closes Interface formLayout -e -af "cbQuestionLabelText" "left" 20 -af "cbQuestionLabelText" "top" 6 -af "cbQuestionGadet" "left" 5 -af "cbQuestionGadet" "top" 26 -af "cbAnswerLabelText" "left" 20 -af "cbAnswerLabelText" "top" 54 -ac "cbAnswerGadet" "left" 5 "cbAnswerLabelText" -af "cbAnswerGadet" "top" 52 -af "crystalBallTellMeButton" "left" 4 -af "crystalBallTellMeButton" "top" 80 -af "closeCrytalBallButton" "top" 80 -af "closeCrytalBallButton" "right" 4 $crystalBallForm; // display CrystalBall Window showWindow $crystalBallWin; } global proc makeCrystalBallAnswer() {// Generate a Random Answer // answer List string $answerList[7] = { "Definitely", "Unlikely", "Not Sure. Ask again", "maybe", "Probably", "Yes", "No" }; // grab the current question string $theQuestion = `textField -q -text cbQuestionGadet`; // calculate length int $theLength = size($theQuestion); // get the current Time string $timeResult = system("time"); // break apart string to get at hundredth of a second string $tokenResults[]; int $tokenNumber = tokenize( $timeResult,".",$tokenResults); string $timeString = substring($tokenResults[1],1,2); int $randomTime = ($timeString); //use the length to seed the random generator seed ($randomTime * $theLength); // generate a random number int $randomNumber = rand(1,7); // set the answer textField -e -text $answerList[$randomNumber-1] cbAnswerGadet; }