User selects multiple from a list

I'm trying to create a game where the player can select multiple classes each year to add to their course load. Is that possible in Squiffy? Is there any way to list out a bunch of courses and have the player select multiple and then add them to a course list?

Yep, using JS.

You could also do it using passages- depends on how tough you want to make this. You could do something like this.

[[Pick a class]]:

It's time to pick your classes!



[[Head to class]](end)

You are now signed up for math. It's pretty tough.

Maybe you could learn crazy languages here!


Head to class!

Of course, more code could be added to the passages to remember what you have.

It's been a while, but thought I would add something...

If you are using passages, then you'll want to add in a [@3] or something too if you want to limit how many options they can choose.

For example:

[[Pick classes]]:
	set('classes', [])
Hello student!

Choose three classes to enrol in:


	set('classes', get('classes').concat('English'))
You have enrolled in English. It will probably involve poetry and classic literature at least. Which might be enough to make up for the essays.

	set('classes', get('classes').concat('Maths'))
You have enrolled in Mathematics. The only field that everyone on the planet uses in daily life.

	set('classes', get('classes').concat('Physics'))
You have enrolled in Physics. Maybe you'll get to cause things to crash into each other.

	set('classes', get('classes').concat('Chemistry'))
You have enrolled in Chemisty. With any luck there'll be explosions.

	set('classes', get('classes').concat('Computing'))
You have enrolled in Computing. Programming in lots of different languages is fun!


Your classes have been chosen.  
You are enrolled in {classes}.

You can test the code out in the editor or scratchpad.

I added in some Javascript to remember chosen classes, but you could use the "normal" Squiffy attributes of @set enrolledPhysics and {if enrolledPhysics:You are enrolled in Physics} instead if you don't want to have to deal with crazy javascript stuff.
The only javascript you need is the line in the [@3] passage that sends them to the next section.

So, main points:

  • You don't need to use Javascript except for the squiffy.story.go('section') line.
  • You can use [@3], [@4], etc. to limit the number of options chosen to whatever number you feel like.


Your writing impresses me deeply, and I hope you will have more good articles in the future to give readers a new perspective on life.
run 3

This topic is now closed. Topics are closed after 60 days of inactivity.