# Debugging Challenges

**URL:** <https://forum.choiceofgames.com/t/debugging-challenges/1509>\
**Category:** ChoiceScript Help\
**Created:** [July 6, 2013, 10:41pm UTC](https://forum.choiceofgames.com/t/debugging-challenges/1509 "2013-07-06T22:41:19Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![xmaslightguy](https://avatars.discourse-cdn.com/v4/letter/x/ee7513/32.png) [@xmaslightguy](https://forum.choiceofgames.com/u/xmaslightguy)\
**Post date:** [July 6, 2013, 10:41pm UTC](https://forum.choiceofgames.com/t/debugging-challenges/1509/1 "2013-07-06T22:41:19Z")

</div>

I’ve noticed that we have some very skilled coders on these forums, some middle of the road (like me), and some who really want to learn. Well I figure why don’t we?

I propose that coders with better knowledge about choicescript create a purposefully bugged script, and post it here so the rest of us can practice fixing them. This could also be challenges with a purpose, like ‘make a variable dependent on how many of 5 people like each other’ and we compare who has the most effective and efficient script.

If you would like to propose a challenge, please fill out the below app;

Username: (What is your username)  
Date: (What day is it? mm/dd/yy)  
Title of challenge: (A way to tell your challenge from others)  
Description: (What do we have to do)  
Script: (Either the script copy and pasted or a link to view it)

Finally, if you have any questions or suggestions please post them. Criticism is definitely welcomed here

---

<div class="post-metadata">

**Author:** ![Galador](https://avatars.discourse-cdn.com/v4/letter/g/90db22/32.png) [@Galador](https://forum.choiceofgames.com/u/Galador)\
**Post date:** [July 6, 2013, 11:12pm UTC](https://forum.choiceofgames.com/t/debugging-challenges/1509/2 "2013-07-06T23:12:10Z")

</div>

I like this concept. It would surely help someone like me figure out how to use certain aspects of coding! Only a day ago I learned what the heck a boolean was and how it can be used!

---

<div class="post-metadata">

**Author:** ![FairyGodfeather](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/fairygodfeather/32/16709_2.png) [@FairyGodfeather](https://forum.choiceofgames.com/u/FairyGodfeather)\
**Post date:** [July 7, 2013, 1:37am UTC](https://forum.choiceofgames.com/t/debugging-challenges/1509/3 "2013-07-07T01:37:30Z")

</div>

I have a challenge. Make up a random name generator, that will take syllables and concoct fantasy sounding names. Or which will take words and create werewolf-esque names. I started on one and then got lazy. It’d be great if someone else would do it. Or if they’d tweak my random name code to make it more streamlined.

---

<div class="post-metadata">

**Author:** ![Caddmuss](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/caddmuss/32/424_2.png) [@Caddmuss](https://forum.choiceofgames.com/u/Caddmuss)\
**Post date:** [July 7, 2013, 2:09am UTC](https://forum.choiceofgames.com/t/debugging-challenges/1509/4 "2013-07-07T02:09:18Z")

</div>

Oooh interesting…

I have an open request which might be interesting. Devise any kind of word puzzle using CS, just so I get ideas.

---

<div class="post-metadata">

**Author:** ![Galador](https://avatars.discourse-cdn.com/v4/letter/g/90db22/32.png) [@Galador](https://forum.choiceofgames.com/u/Galador)\
**Post date:** [July 7, 2013, 10:38am UTC](https://forum.choiceofgames.com/t/debugging-challenges/1509/5 "2013-07-07T10:38:48Z")

</div>

@Caddmuss Could you be more specific on exactly what you want this to do?

@FairyGodfeather Where can we view your original name generator so we can compare our own to yours?

---

<div class="post-metadata">

**Author:** ![Caddmuss](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/caddmuss/32/424_2.png) [@Caddmuss](https://forum.choiceofgames.com/u/Caddmuss)\
**Post date:** [July 7, 2013, 11:04am UTC](https://forum.choiceofgames.com/t/debugging-challenges/1509/6 "2013-07-07T11:04:10Z")

</div>

Basically, any semi-interesting puzzle that a player has to complete. It doesn’t have to be ultra-complex, but obviously a bit of thought would be nice. It shouldn’t be riddle-related, though doesn’t necessarily have to be ASCII art. Think of thing’s like the Towers of Hanoi or Peg Solitaire.

---

<div class="post-metadata">

**Author:** ![FairyGodfeather](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/fairygodfeather/32/16709_2.png) [@FairyGodfeather](https://forum.choiceofgames.com/u/FairyGodfeather)\
**Post date:** [July 7, 2013, 12:00pm UTC](https://forum.choiceofgames.com/t/debugging-challenges/1509/7 "2013-07-07T12:00:13Z")

</div>

[www.choiceofgames.com/forum/discussion/1659/random-name-generator](http://www.choiceofgames.com/forum/discussion/1659/random-name-generator) was my thread about creating a name generator. Ignore the earlier pastebin links since I eventually made it to dropbox.

---

<div class="post-metadata">

**Author:** ![P\_Tigras](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/p_tigras/32/626_2.png) [@P\_Tigras](https://forum.choiceofgames.com/u/P_Tigras)\
**Post date:** [July 7, 2013, 12:01pm UTC](https://forum.choiceofgames.com/t/debugging-challenges/1509/8 "2013-07-07T12:01:03Z")

</div>

The most efficient way to code the Towers of Hanoi is via recursion.

---

<div class="post-metadata">

**Author:** ![FairyGodfeather](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/fairygodfeather/32/16709_2.png) [@FairyGodfeather](https://forum.choiceofgames.com/u/FairyGodfeather)\
**Post date:** [July 7, 2013, 12:12pm UTC](https://forum.choiceofgames.com/t/debugging-challenges/1509/9 "2013-07-07T12:12:18Z")

</div>

I’ve played one choice game which was a fantastic puzzle that needed to be worked out and the puzzle itself was so well integrated into the storyline. That was the Paradox Factor which @Lucid wrote. I hope it’s okay to discuss it since there was another version of the game online. I think that’s the way to do puzzles and it was just so very clever. I’m looking forward to it being released and hope that the puzzle remains untouched.

Otherwise I find puzzles frustrating in Choice games. I’ve yet to see them implemented well. I do think there is a lot we could take from text adventures and that style of interactive fiction. I also think ethical dilemmas where you discuss a situation with people, get their viewpoints and then make a decision upon that in order to implement a solution, is the sort of thing that could be done, and done well with choicescript.

I think a puzzle-fight system similar to Gun Mute might also be able to be implemented quite well. [http://ifdb.tads.org/viewgame?id=xwedbibfksczn7eq](http://ifdb.tads.org/viewgame?id=xwedbibfksczn7eq)

---

<div class="post-metadata">

**Author:** ![P\_Tigras](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/p_tigras/32/626_2.png) [@P\_Tigras](https://forum.choiceofgames.com/u/P_Tigras)\
**Post date:** [July 7, 2013, 12:55pm UTC](https://forum.choiceofgames.com/t/debugging-challenges/1509/10 "2013-07-07T12:55:20Z")

</div>

@FairyGodfeather Unfortunately Choicescript doesn’t allow for data structures like associative arrays and hash tables that can store a long list of a hundred names in an easy to access fashion. You could trade away the two hundred \*if’s by creating a pair of “faux” arrays, each with a hundred \*create’s. Then you could dynamically extract the correct name from the correct “faux” array by constructing a string that matches the correct “faux” array member and “referencing” it. While computationally the code would be more efficient, it wouldn’t be any shorter or simpler looking. It would be a hair longer and require quite a bit more brain power to write. One of Choicescript’s major limitations is that it just wasn’t designed with the idea in mind that you might need to store and access a long list of data. This is why writing an inventory system like @CJW’s is such a great amount of work.

---

<div class="post-metadata">

**Author:** ![FairyGodfeather](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/fairygodfeather/32/16709_2.png) [@FairyGodfeather](https://forum.choiceofgames.com/u/FairyGodfeather)\
**Post date:** [July 7, 2013, 1:00pm UTC](https://forum.choiceofgames.com/t/debugging-challenges/1509/11 "2013-07-07T13:00:11Z")

</div>

What’s the difference between using elseif and using if?

---

<div class="post-metadata">

**Author:** ![P\_Tigras](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/p_tigras/32/626_2.png) [@P\_Tigras](https://forum.choiceofgames.com/u/P_Tigras)\
**Post date:** [July 7, 2013, 1:14pm UTC](https://forum.choiceofgames.com/t/debugging-challenges/1509/12 "2013-07-07T13:14:31Z")

</div>

With \*if, every single \*if is always checked every time even if one of the \*if’s has already been matched, unless you also include a \*goto for each \*if to skip the rest of the \*if’s. \*elseif/\*elsif’s only get checked if the previous if and elsif’s haven’t matched. So it’s computationally more efficient, and thus faster, to use elsif’s. Nevertheless I believe there was an issue with \*elsif breaking on the Kindle at one point. So people stopped using \*elsif for this reason. Maybe I’m mistaken, but I was under the impression that this had been fixed.

---

<div class="post-metadata">

**Author:** ![FairyGodfeather](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/fairygodfeather/32/16709_2.png) [@FairyGodfeather](https://forum.choiceofgames.com/u/FairyGodfeather)\
**Post date:** [July 7, 2013, 1:22pm UTC](https://forum.choiceofgames.com/t/debugging-challenges/1509/13 "2013-07-07T13:22:51Z")

</div>

Oh thanks! Once I thought about it I suspected it might be something like that. Would it be better to add gotos after all of them then? I didn’t really understand the point of elsif before so I never used it, but I can see how it’s useful.

---

<div class="post-metadata">

**Author:** ![P\_Tigras](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/p_tigras/32/626_2.png) [@P\_Tigras](https://forum.choiceofgames.com/u/P_Tigras)\
**Post date:** [July 7, 2013, 1:34pm UTC](https://forum.choiceofgames.com/t/debugging-challenges/1509/14 "2013-07-07T13:34:26Z")

</div>

Actually, the best thing is probably to ask @dfabulich, the author of choicescript, if there is any reason to avoid using elseif/elsif at this point, because a lot of people are still clearly avoiding it. Nevertheless I notice that it’s still in the recently rewritten online _Introduction to Choicescript_ doc, I’ve seen it used occasionally in some of the newer official CoG games, albeit sparingly, and I recall seeing a few commits to the choicescript git code repository relating to elseif/elsif over the past year or so.

---

<div class="post-metadata">

**Author:** ![xmaslightguy](https://avatars.discourse-cdn.com/v4/letter/x/ee7513/32.png) [@xmaslightguy](https://forum.choiceofgames.com/u/xmaslightguy)\
**Post date:** [July 7, 2013, 2:36pm UTC](https://forum.choiceofgames.com/t/debugging-challenges/1509/15 "2013-07-07T14:36:14Z")

</div>

If anyone has experience with JavaScript they could go in an alter the base code that choicescript runs on. Do you think the authors would get mad if we did that?

---

<div class="post-metadata">

**Author:** ![FairyGodfeather](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/fairygodfeather/32/16709_2.png) [@FairyGodfeather](https://forum.choiceofgames.com/u/FairyGodfeather)\
**Post date:** [July 7, 2013, 2:43pm UTC](https://forum.choiceofgames.com/t/debugging-challenges/1509/16 "2013-07-07T14:43:03Z")

</div>

I made a thing! It’s an extremely basic Rock Paper Scissors game. It was inspired by this thread. I wanted to implement a gun if you hit 10 loses and from that point you can cheat, and a tropy if you hit 10 wins but I got bored since the random generator kept cheating.

I was also too lazy to work out how to upload it in a playable way so just copy the code into the online tester at [www.choiceofgames.com/forum/discussion/comment/67680/](http://www.choiceofgames.com/forum/discussion/comment/67680/)

Anyway the Rock Paper Scissors code is at [https://www.dropbox.com/s/96km7wumkq1ptjp/rockpaperscissors.txt](https://www.dropbox.com/s/96km7wumkq1ptjp/rockpaperscissors.txt) I think it works but since I just churned it out quickly it might not.

---

<div class="post-metadata">

**Author:** ![CJW](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/cjw/32/111787_2.png) [@CJW](https://forum.choiceofgames.com/u/CJW)\
**Post date:** [July 7, 2013, 2:45pm UTC](https://forum.choiceofgames.com/t/debugging-challenges/1509/17 "2013-07-07T14:45:07Z")

</div>

I’ve got one:

**Title of challenge:** Choicescript Hangman Coding Challenge  
**Description:** Provided is some basic code for a hangman game in choicescript. There are no particular goals to achieve, but you should try and improve upon the current design - there are definitely things missing, or things that could be done more efficiently.  
**Script:** [http://pastebin.com/b3qaqNS4](http://pastebin.com/b3qaqNS4)

[Online Choicescript Tester](https://dl.dropboxusercontent.com/u/7840892/CJW/choicescript/tools/online-cs-tester/mygame/input.html)

---

<div class="post-metadata">

**Author:** ![dfabulich](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/dfabulich/32/198373_2.png) [@dfabulich](https://forum.choiceofgames.com/u/dfabulich)\
**Post date:** [July 7, 2013, 5:19pm UTC](https://forum.choiceofgames.com/t/debugging-challenges/1509/18 "2013-07-07T17:19:53Z")

</div>

\*elseif is supposed to work as you’d expect; I know of no known issues/bugs with it.

It doesn’t improve performance at all. But it does serve two purposes:

1. It’s a lot easier to read/understand \*if/\*elseif/\*else than it is to just read \*if/\*if/\*if.

2. Specifically, using \*else helps the Quicktest automated testing program to avoid “fake bugs,” as explained here. [http://www.choiceofgames.com/make-your-own-games/testing-choicescript-games-automatically/#fakes](http://www.choiceofgames.com/make-your-own-games/testing-choicescript-games-automatically/#fakes)

---

<div class="post-metadata">

**Author:** ![dfabulich](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/dfabulich/32/198373_2.png) [@dfabulich](https://forum.choiceofgames.com/u/dfabulich)\
**Post date:** [July 7, 2013, 5:42pm UTC](https://forum.choiceofgames.com/t/debugging-challenges/1509/19 "2013-07-07T17:42:48Z")

</div>

Indeed, arrays suck in ChoiceScript. But remember that you can use \*setref and curly parens (without “$”) to indirectly refer to variables, allowing you to simulate a lot of fancy array stuff. See the “Truly bizarre references” section at the end of the Advanced guide. [http://www.choiceofgames.com/make-your-own-games/choicescript-advanced/](http://www.choiceofgames.com/make-your-own-games/choicescript-advanced/)

```
*temp fibonacci_0 1
*temp fibonacci_1 1
*temp fibonacci_2
*temp fibonacci_3
*temp fibonacci_4
*temp fibonacci_5
*temp fibonacci_6
*temp fibonacci_7
*temp fibonacci_8
*temp fibonacci_9

*temp i 2
*temp j
*temp k
*temp fib
*label loopstart
*if i < 10
  *set j i-1
  *set k i-2
  *setref "fibonacci_${i}" {"fibonacci_${j}"} + {"fibonacci_${k}"}
  *set fib {"fibonacci_${i}"}
  ${i}: ${fib}

  *set i +1
  *goto loopstart

```

I’ll admit, that’s still pretty annoying. One feature I’ve yet to code that would make that a little less annoying would be to allow you to define a bunch of numbered temp variables at once, like this:

```
*temp_list fibonacci 10

```

It would also be nice to allow arbitrary expressions in ${}, like this:

```

*setref "fibonacci_${i}" {"fibonacci_${i-1}"} + {"fibonacci_${i-2}"}
${i}: ${"fibonacci_${i}"}

```

Those together would let you rewrite the Fibonacci code as something like:

```
*temp_list fibonacci 10
*set fibonacci_1 1
*set fibonacci_2 1

*temp i 3
*label loopstart
*if i <= 10
  *setref "fibonacci_${i}" {"fibonacci_${i-1}"} + {"fibonacci_${i-2}"}
  ${i}: ${"fibonacci_${i}"}

  *set i +1
  *goto loopstart

```

Sadly, stuff like this just isn’t at the top of my list right now. ☹

---

<div class="post-metadata">

**Author:** ![Galador](https://avatars.discourse-cdn.com/v4/letter/g/90db22/32.png) [@Galador](https://forum.choiceofgames.com/u/Galador)\
**Post date:** [July 8, 2013, 9:19pm UTC](https://forum.choiceofgames.com/t/debugging-challenges/1509/20 "2013-07-08T21:19:04Z")

</div>

@CJW So I looked at your challenge. At first, I was like, “Oh, Hangman? That can’t be too difficult, right?” After an hour and a half, I was like, “Well, crap…” I can’t even figure out where to start with it! I can’t even figure out where all the codes lead you and what the heck is even going on with all those commands and stuff! That is much more difficult than I would have ever thought it could be.

[Next page](https://forum.choiceofgames.com/t/debugging-challenges/1509.md?page=2)
