Algorithm hall of fame and code examples: sorting, shuffling, dev tools

Hi there. In this post I want to collect a few pearls I have seen over time in the forum, some generic algorithms and tools that people may use in a variety of situations. (Note this is a Wiki and not all edits are mine).

The table below (by @cup_half_empty) has links you can follow to find code examples and information on usage. You will find some common algorithms (sorting, shuffling) and some interesting ChoiceScript extensions, useful to develop and debug your game.

Feel free to contribute to this thread with other examples. Have fun!


General algorithms in Choicescript

Name Description Credits
Insertion Sorting Sorting algorithm. It can be used to sort arrays, find the max/min of several values and more. @stainedofmind
Array Shuffle Creates a random shuffle of a sequence of values. It can be used to make your game different every time. @Lan
Library for strings and arrays String manipulation and list simulation. Functions: substring, indexOf, contains, replaceFirst, replaceAll @Twiger_Fluff

Plugins, Hacks & Mods (using Javascript)

:warning: These extensions modify the Choicescript engine and/or use *script. As such, they may not be fully supported.

Name Description Credits
Game Transcription A modified version of the ChoiceScript engine that will output a transcript of the game, based on the player’s choices. @Sargent
Game Statistics A modified version of the ChoiceScript engine that will output statistics of the game. @Sargent
Multi-player library Implement multiplayer in ChoiceScript, by sending requests to a 3rd-party server. @Twiger_Fluff
Debugging tool Debugging plugin which offers choice recording and playback . @Twiger_Fluff

Development environments

Name Description Credits
CSIDE ChoiceScript development environment. Edit and run your game in a very flexible environment @CJW
Visual Studio extension Develop your game in Visual Studio @Sargent

Other useful code snippets

Name Description Credits
Gender and Pronoun Sample Code Sample code for setting variable MC and NPC pronouns @HannahPS
Inventory Code to present items from an inventory CS Wiki
18 Likes

That short little MinMax gosub_scene one to make sure none of your stats have gone above 100/below zero is nice.

I’d also add that the code for dynamically listing your inventory (on the stat screen) is also super helpful.

@choicehacker – Thanks for taking the time and effort to do this; I pinned your topic; it is a great resource

5 Likes

I suggest making your first post a wiki so that contributors can add directly to the list.

2 Likes

Wiki done. Sorry for not thinking that far ahead CJW! :slight_smile:

3 Likes

This week’s update features a library by @Twiger_Fluff that implements a few basic string operations (replace, find etc). It also has supports for unbounded arrays (implemented as strings). Check it out! Working String Manipulation (no *script used) (substring, substr, indexOf, contains, replace)

This week, I added some Javascript tricks that may be very helpful during development and debugging (see top post). As usual, remember *script is not fully supported (and frowned upon at times) and may make your story unpublishable. Still, I believe these extensions may make your life much easier when you write your story. Have fun!

2 Likes

This is really cool. My small suggestion is to make it a table instead of a list.

2 Likes

Thank you for this! It’s already helped me out with my own game.

For the record, my two contributions don’t require *script and won’t make your game unpublishable. They require edited versions of the Choicescript engine. The stats-generating extension requires you to add specially-formatted *comment lines to your game specifically so vanilla Choicescript won’t care and will ignore the changes.

2 Likes

I’ve edited OP to include the table. @choicehacker, can you edit it? @Sargent does the note I included make sense? @Twiger_Fluff as well, can you take a look at the note and check if it makes sense?

1 Like

Thanks @Sargent for the clarification and thanks @cup_half_empty for the table. I didn’t know one could edit other people’s posts! What’s the magic trick?

It’s because its a wiki, so anyone can edit. Otherwise it would not be possible. It’s common courtesy however not to edit someone else’s post, I only did that to save you time formating the table (in case you decide to use it).

2 Likes

Yep, perfect!

In this particular case, we made the OP a wiki, so everyone can collaborate together. This is a project that more than one person adds to.

Meaning it is ok to edit it without fear of breaking rules.

3 Likes

Thanks. It’s confusing because my name remains there even after the edits. I may add a disclaimer on top.

1 Like

Well… in the forum software’s eyes… you started this “discussion.”

Sorry for the confusion.

1 Like

Hey, there. I think @HannahPS’s gender and pronoun code sample would fit it in here. What do you think?

4 Likes

That’s a nice idea! I’ve added it onto the original post.

3 Likes