Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sugarcube 2.7.0 plucking random questions from an object database and matching them to answers

Hello all,

I'm working on a sugarcube game where the goal is to provide a "quiz arena." In this arena, I'd like the player to be asked random questions, have to answer them before moving on, and have those answers checked one at a time. To do this, I created an object in my StoryInit passage:
<<set $arenaobjects to {
	Questions : {
		q1 : "What is the first class in session 1?",
		q2 : "How many computer classes are there during session 2?",
		q3 : "How many students are in Reading 4 during session 1?"
	}
	Answers : {
		a1 : "Writing" or "writing",
		a2 : "4" or "four" or "Four",
		a3 : "12" or "twelve" or "Twelve"
	}
}>>

I thought about doing this as two arrays instead of two object properties within $arenaobjects, but I'm not sure if that would be better or worse.

The end result I'm trying to achieve is to have a tile display a random question and a textbox, and then know which answer to expect in that checkbox, based on which question was displayed at random. I've worked the above into the StoryInit tile, but am not sure which direction to go in to print the question and corresponding answer at random.

Comments

  • I'm just going to attach an example Twine 2 project archive with what I'd suggest. The StoryInit special passage has some commentary.
  • Nice. I'll check it out. For some reason, when I open what you've attached, I get a blank tab at the following url:

    https://twinery.org/forum/uploads/Uploader/66/2771d41f65074ee628a5e56ecf7c33.html
  • Right-click and save as.
  • Oh of course...
  • Great setup, thanks! I was able to replicate it in my story. Strangely though, when I run it, I get
    Error: <<set>>: bad evaluation: Cannot read property 'pluck' of undefined
    and
    Error: <<=>>: bad evaluation: Unexpected identifier

    When I simply load your example, however, it runs just fine. There must be something in my StoryInit tile that's creating interference. Any ideas?

    Thanks again.
  • edited August 2016
    Check the names of the variables, yours are likely different that what I used.
  • Ha! You know what it was? The first line of the StoryInit tile was:
    /*Initialize Quiz Bowl/*

    I played things through and not only was I receiving errors on the Quiz Bowl, but my cached sound wasn't coming through and there were other errors as well. I removed that line from the StoryInit tile and everything works perfectly.

    Thanks so much, once again.
  • hausrath wrote: »
    Ha! You know what it was? The first line of the StoryInit tile was:
    /*Initialize Quiz Bowl/*
    That would be because you have two opening block quote sequences there, rather than a properly paired opening and closing set. The correct form would have been:
    /* Initialize Quiz Bowl */
    
    Asterisks go on the inside, slashes on the outside.
  • And while I'm at it, I'll reattach the example Twine 2 project archive to this post—since the forums ate the other one. Right-click and save as to download.
Sign In or Register to comment.