//Written by Zichqec https://ukagaka.zichqec.com/ //v1.0.1 /* This is an improved version of my original Junior Jumble game. In this version of the game, the user is prompted with a category for the words they will be solving, because as it turns out unscrambling words is hard when you have no idea what they might be! By default, the user is asked to solve 5 words before they win. You can adjust this at the top of the OnWordJumble.Start function. To start the game, call the event OnWordJumble.Start in a menu option/raise tag/etc. Example: \![*]\q[Play Word Jumble,OnWordJumble.Start] */ //——————————————— Dialogue ——————————————— //I set these up to display the final words at the end. If you'd rather have your ghost say something about the user winning, you can replace it with simple dialogue or what have you. /* Quick reference for the local variables in the following functions, in case you want to change things up. In particular, you might be interested in _word and _scrambled, but the rest you can probably ignore. _guess - only available if the user loses. Their incorrect guess, with sakurascript tags escaped _category_name - the name of the current category _word_list - a list of all the words yet to be guessed, delimited by C_BYTE1 _word - the current word that is being guessed _correct_guesses - words that have been guessed correctly so far, delimited by WordJumble.Delimiter (set to "||" by default) _scrambled - the scrambled version of the word to be guessed */ OnWordJumble.Win : all { _category_name = reference2 _word_list = reference3 _word = SPLIT(_word_list,C_BYTE1)[0] _correct_guesses = reference4 _scrambled = reference5 "\0\b[2]\![set,autoscroll,disable]\_q" "You win!" "\nCategory:\_w[] %(_category_name)" "\n\n" "\![*]\__q[OnWordJumble.Start]Play again\__q \![*]\__q[OnBlank]Done\__q" "\n\n" WordJumble.MakeDisplay(_correct_guesses) } OnWordJumble.Lose : all { _guess = SHIORI3FW.EscapeAllTags(reference0) _category_name = reference2 _word_list = reference3 _word = SPLIT(_word_list,C_BYTE1)[0] _correct_guesses = reference4 _scrambled = reference5 "\0\b[2]\![set,autoscroll,disable]\_q" "Game over: the correct word was %(_word)" "\nCategory: %(_category_name)" "\n\n" "\![*]\__q[OnWordJumble.Start]Play again\__q \![*]\__q[OnBlank]Done\__q" "\n\n" if _correct_guesses != ""; WordJumble.MakeDisplay(_correct_guesses) "\f[color,disable]%(_scrambled)\f[color,default]\n" "\f[strike,1]%(_guess)\f[strike,default]\n\n" } OnWordJumble.Quit : all { _category_name = reference2 _word_list = reference3 _word = SPLIT(_word_list,C_BYTE1)[0] _correct_guesses = reference4 _scrambled = reference5 "\0\b[2]\![set,autoscroll,disable]\_q" "\![close,inputbox,OnWordJumble.Guess]" "Game over: quit" "\nCategory: %(_category_name)" "\n\n" "\![*]\__q[OnWordJumble.Start]Play again\__q \![*]\__q[OnBlank]Done\__q" "\n\n" if _correct_guesses != ""; WordJumble.MakeDisplay(_correct_guesses) "\f[color,disable]%(_scrambled)\f[color,default]\n" "\f[strike,1]%(_word)\f[strike,default]\n\n" } //——————————————— Categories / Words ——————————————— //You can write as many categories as you want. Just copy one of these, and pick a new name. //The name of the function after the "WordJumble.Category." part doesn't matter, but for simplicity's sake, I'd make it the name of the category (minus any special characters/spaces) //The first string in each array should be the name of the category. //The more categories and words in each category you have, the better! But mind that anagrams can be mean. Also, be mindful of things that can scramble into profanity, etc. WordJumble.Category.Fruit : array { "Fruit" "Apple" "Apricot" "Banana" "Canteloupe" "Cherry" "Dragonfruit" "Kiwi" //"Lemon" - this is an anagram with "melon"! "Lime" "Lychee" "Mandarin" "Mango" "Orange" "Persimmon" "Pineapple" "Plum" "Tomato" "Watermelon" } WordJumble.Category.Noodles : array { "Noodles" "Bucatini" "Cavatappi" "Conchiglie" "Farfalle" "Fettucine" "Lasagna" "Linguine" "Macaroni" "Penne" "Ravioli" "Rigatoni" "Rotini" "Spaghetti" "Ziti" } WordJumble.Category.Winter : array { "Winter" "Snow" "Snowman" "Icicle" "Thawing" "Melting" "Freezing" "Slush" "Shoveling" "Slippery" "Frosty" "Quiet" "Dazzling" } //——————————————— Game logic ——————————————— OnWordJumble.Start { //The maximum number of words that you want the user to have to guess before they win. //Note that if there are not this many words in the category, it will simply use all the available words once. _max_words = 5 //Picking a category _categories = GETFUNCLIST("WordJumble.Category.") _category = EVAL("%(ANY(_categories))") _category_name = _category[0] _category[0] = IARRAY _word_list = "" for _i = 0; _i < _max_words && ARRAYSIZE(_category) > 0; _i++ { if _i != 0; _word_list += C_BYTE1 _word_list += ANY(_category) _category[LSO] = IARRAY } "\![close,inputbox,OnWordJumble.Guess]\![raise,OnWordJumble.Display,start,,""%(_category_name)"",""%(_word_list)""]" } //Main game window OnWordJumble.Display : all { _category_name = reference2 _word_list = SPLIT(reference3,C_BYTE1) _correct_guesses = reference4 if !(reference0 == "start"); _word_list[0] = IARRAY if _word_list[0] == "" { "\C\![raise,OnWordJumble.Win,,,""%(_category_name)"",""%(_word_list)"",""%(_correct_guesses)"",""%(_scrambled)""]" return } _word = _word_list[0] _scrambled = WordJumble.Scramble(_word) _word_list = WordJumble.MakeMultiArray(,_word_list) "\C\![lock,balloonrepaint]\c" "\0\b[2]\_q\*\t" "\![no-markdown]" //I'm silly and testing this in a ghost with markdown. But maybe I'll leave it? Shouldn't hurt "\![open,inputbox,OnWordJumble.Guess,--reference=""%(_category_name)"",--reference=""%(_word_list)"",--reference=""%(_correct_guesses)"",--reference=""%(_scrambled)""]" "Unscramble the words!" "\n" "Category: %(_category_name)" "\n\n" "\![*]\__q[OnWordJumble.Quit,,,""%(_category_name)"",""%(_word_list)"",""%(_correct_guesses)"",""%(_scrambled)""]Give up\__q" "\n\n" if _correct_guesses != ""; WordJumble.MakeDisplay(_correct_guesses) "%(_scrambled)" "\![unlock,balloonrepaint]" } OnWordJumble.Guess { _category_name = reference2 _word_list = reference3 _word = SPLIT(_word_list,C_BYTE1)[0] _word = SHIORI3FW.EscapeAllTags(_word) _correct_guesses = reference4 _scrambled = reference5 if reference0 == ""; "\C\![open,inputbox,OnWordJumble.Guess,--reference=""%(_category_name)"",--reference=""%(_word_list)"",--reference=""%(_correct_guesses)"",--reference=""%(_scrambled)""]" elseif TOLOWER(reference0) == TOLOWER(_word) //Correct guess, game continues { if _correct_guesses != ""; _correct_guesses += WordJumble.Delimiter _correct_guesses += "%(_word)%(C_BYTE1)%(_scrambled)" "\C\![raise,OnWordJumble.Display,,,""%(_category_name)"",""%(_word_list)"",""%(_correct_guesses)"",""%(_scrambled)""]" } else //Lose { "\C\![raise,OnWordJumble.Lose,""%(reference0)"",,""%(_category_name)"",""%(_word_list)"",""%(_correct_guesses)"",""%(_scrambled)""]" } } //——————————————— Utility functions ——————————————— //If for some reason the double pipe doesn't work as a delimiter for you, you can pick something else here WordJumble.Delimiter { "||" } //Scrambles whatever word is input WordJumble.Scramble { _word = TOLOWER(_argv[0]) _output = "" //Try up to 100 times to scramble the word without just outputting the original word again. //There is a chance someone puts in a word that can't be scrambled, like if they just put "aaa". So this stops after 100 tries so as not to potentially crash SSP for _i = 0; _i < 100; _i++ { _output = "" while STRLEN(_word) > 0 { _n = RAND(STRLEN(_word)) _output += SUBSTR(_word,_n,1) _word = ERASE(_word,_n,1) } if _output != TOLOWER(_argv[0]); break } _output } //Make a general purpose array into a simple array //The first argument is the delimiter. YOU MUST INCLUDE THIS ARGUMENT. //If you want to use C_BYTE1, you may leave the argument blank. But it MUST exist, even if it's empty. //All other arguments are elements of the array that will be made into a simple array WordJumble.MakeMultiArray { //I hate this _delimiter = C_BYTE1 if _argv[0] != ""; _delimiter = _argv[0] _argv[0] = IARRAY _output = "" foreach _argv; _arg { if _output != ""; _output += _delimiter _output += _arg } _output } WordJumble.MakeDisplay : all { _correct_guesses = _argv[0] _correct_guesses = SPLIT(_correct_guesses,WordJumble.Delimiter) foreach _correct_guesses; _guess { _w = _guess[0,C_BYTE1] _w = SHIORI3FW.EscapeAllTags(_w) _s = _guess[1,C_BYTE1] "\f[color,disable]%(_s)\n" "\f[color,default.anchor]%(_w)\f[color,default]\n\n" } }