Parameters are great! It’s fun to see someone pretty much going through the same motions I did over the last few months realizing all the things you can do. I still think ChoiceScript could do with a few extra QoL improvements for those of us who are more into complicated code / have coding experience, but you can do a lot of things with it that you might not initially expect, even if you have to go back to basics a bit.
I also wanted to use *script initially but as you said, you can’t use it if you want to be published, so that means we have to get creative!
Of course, here you go!
*comment search database function
*label search_function
*looplimit 10000
*temp term_1 "balderdash"
*temp term_2 "barnacles"
*temp term_3 "endometriosis"
*temp term_4 "liverwort"
*temp term_5 "salacious"
*temp term_6 "sautéed"
*temp term_7 "Yoruba"
*temp term_8 "zoinks"
*temp database_size 8
*comment examples of what your database might look like - must be in alphabetical order, which is the biggest downside of this implementation imo, but you can also probably sort this programmatically if you really want to
*label player_facing_search_box
*temp search_term ""
*input_text search_term
*set search_term "$!!{search_term}"
*temp current_string_pos 1
*temp current_search_scope_end database_size
*temp current_search_scope_begin 1
*temp term_index_number 1
*temp match false
*temp lookup ""
*label search_database_loop
*set lookup "$!!{{\"term_\"&term_index_number}}"
*if (current_string_pos > 1) and (length(lookup) != length(search_term))
*goto no_match
*if current_search_scope_begin = current_search_scope_end
*if lookup = search_term
Term successfully found.
*set lookup {"term_"&term_index_number}
Term is: ${lookup}.
*else
No terms found!
*page_break Go again?
*goto search_function
*if (lookup#current_string_pos) = (search_term#current_string_pos)
*if match = false
*set current_search_scope_begin term_index_number
*set match true
*if term_index_number < current_search_scope_end
*set term_index_number + 1
*else
*set term_index_number current_search_scope_begin
*set current_string_pos + 1
*set match false
*else
*label no_match
*if match = true
*set current_search_scope_end (term_index_number - 1)
*set current_string_pos + 1
*set term_index_number current_search_scope_begin
*elseif term_index_number = current_search_scope_end
No terms found!
*page_break Go again?
*goto search_function
*else
*set term_index_number + 1
*set match false
*goto search_database_loop
Having tested it out, it works quite well and it’s not too bulky code-wise. Obviously you’d have to change a few things if you wanted to fully implement it into a game (converting the database to global variables; implementing some things as parameters if this section is a gosub; etc), but I’m quite happy with it for a start.
Advantages are that 1) you don’t have to store your terms in allcaps, so you can print them into the text freely if you want to, and 2) it also works with any length of word and any number of letters and/or symbols, including diacritics, without the need for verifying the user’s input.
Main disadvantage / possibility to break things right now is probably the fact that your database of terms has to be laid out in alphabetical order as shown at the top (and the number suffixes MUST start at 1 and increment by 1 with no exceptions or gaps). You could probably write exception handlers to imprve stability for these cases and/or write something to sort the terms programmatically (arrays come to mind), but I didn’t get that far.
Let me know if you have any questions or are curious about anything else @myeraland (or anyone else). As I said I love tackling these problems. Coding is like my ice cream that I treat myself to after lots of writing my vegetables.
Side tangent, but it’s also why I love IF so much! There are so few careers where you get to use both logical / mathematical and creative / artistic parts of your brain at the same time, pretty much daily. I understand it’s not for everyone, but we should all cherish it imo! There are lots of good writers and lots of good coders in the world but very few people who are both. Y’all are a special breed!
