Howdy, Stranger!

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

[Sugarcube 1.0.34] Converging multiple choices into one passage

edited August 2016 in Help! with 2.0
Hi there! I'm still fairly new to Twine but I've had a small amount of experience in programming, and I've been watching through some tutorials on Youtube to help me with Sugarcube's functions. That said I've got a few questions that are stumping me with my story idea, and I'd like some help with them! I'm not gonna bombard everyone with multiple questions so I'll tackle them in separate threads for ease of use.

The basic framing for my story so far is that the player character has an appointment with a laboratory, and they're asked what the nature of their business is. I'm using Sugarcube's "Objects" feature to give each option a name, a description (or rather a response to picking that option), and to set the player's clothes (As this is a part of the intro and so it's a player setup stage).

Here's my code so far:
Visual identity confirmed. Welcome, $pname, and thank you for considering an appointment with GenGel!

What is the nature of your visit?
----
<<nobr>>
<<set $biz={
"name":"Business Appointment",
"response":"Ah, yes, $pname, we have you listed down here because you were interested in buying our products? Please, come on in and we can get started.",
"head":"Glasses",
"top":"Business Shirt",
"bottom":"Business Pants",
"feet":"Fancy Shoes"
}>>
<<set $mat={
"name":"Material Delivery",
"response":"Ah! ...$pname, was it? You've got a consignment of chemicals for us? Excellent, our employees are taking that in now. If you come on in we'll get those forms signed.",
"head":"Trucker Cap",
"top":"Vest",
"bottom":"Jeans",
"feet":"Boots"
}>>
<<set $test={
"name":"Test Participant Application",
"response":"$pname, you were interested in applying as a test participant at GenGel, I remember you! Come on in and we can get you set up with your testing gear.",
"head":"Safety Goggles",
"top":"Speed Suit (top)",
"bottom":"Speed Suit (bottom)",
"feet":"Sneakers",
}>>
<<set $tour={
"name":"Guided Tour",
"response":"Welcome to our facility, $pname! We're always honoured to have guests pay a visit to our facilities. If you come on in we can get you set for the tour!",
"head":"Sunglasses",
"top":"Hawaiian Shirt",
"bottom":"Cargo Shorts",
"feet":"Leather Sandals"
}>>
<<set $idunno={
"name":"No Idea",
"response":"Wait... $pname, you registered for an appointment but you don't know what the appointment was for? (You hear a hushed conversation in the distance) ...Oh! Right, you're THAT $pname! Sorry for the confusion, come on in.",
"head":"HUDAR Glasses",
"top":"Baja Hoodie",
"bottom":"Baggy Jeans",
"feet":"Flip Flops"
}>>
<</nobr>>

$biz.name
$mat.name
$test.name
$tour.name
$idunno.name

What I ideally want to do is make it so that whatever option is picked, they all lead into the same passage, which displays the "response" field for whatever option was picked. It'd be nice to allow this page to accept more options later if needed, so the rough idea I have, in terms of a rough pseudocode example, is:

This Passage: If "Business Appointment" is clicked on, set chosenJob to $biz, if "Material Delivery" is clicked on, set chosenJob to $mat, so on so forth for each job.
Next Passage: Display the "Response" of whatever chosenJob is set to, and set $head, $top, $bottom and $feet to the chosenJob's head, top, bottom and feet values.

Apologies, that was a lot of words. Basically I've seen something like this done in Harlowe in VegetarianZombie's tutorial videos using datamaps, but I don't know how to do the equivalent for SugarCube's objects.

Comments

  • You could certainly make this more complicated, however, something like the following would suffice:
    Visual identity confirmed. Welcome, $pname, and thank you for considering an appointment with GenGel!
    
    What is the nature of your visit?
    ----
    <<click "Business Appointment" "Confirm Job">>
    <<set $job to {
    	name     : "Business Appointment",
    	response : "Ah, yes, $pname, we have you listed down here because you were interested in buying our products? Please, come on in and we can get started.",
    	head     : "Glasses",
    	top      : "Business Shirt",
    	bottom   : "Business Pants",
    	feet     : "Fancy Shoes"
    }>>
    <</click>>
    
    <<click "Material Delivery" "Confirm Job">>
    <<set $job to {
    	name     : "Material Delivery",
    	response : "Ah! ...$pname, was it? You've got a consignment of chemicals for us? Excellent, our employees are taking that in now. If you come on in we'll get those forms signed.",
    	head     : "Trucker Cap",
    	top      : "Vest",
    	bottom   : "Jeans",
    	feet     : "Boots"
    }>>
    <</click>>
    
    <<click "Test Participant Application" "Confirm Job">>
    <<set $job to {
    	name     : "Test Participant Application",
    	response : "$pname, you were interested in applying as a test participant at GenGel, I remember you! Come on in and we can get you set up with your testing gear.",
    	head     : "Safety Goggles",
    	top      : "Speed Suit (top)",
    	bottom   : "Speed Suit (bottom)",
    	feet     : "Sneakers"
    }>>
    <</click>>
    
    <<click "Guided Tour" "Confirm Job">>
    <<set $job to {
    	name     : "Guided Tour",
    	response : "Welcome to our facility, $pname! We're always honoured to have guests pay a visit to our facilities. If you come on in we can get you set for the tour!",
    	head     : "Sunglasses",
    	top      : "Hawaiian Shirt",
    	bottom   : "Cargo Shorts",
    	feet     : "Leather Sandals"
    }>>
    <</click>>
    
    <<click "No Idea" "Confirm Job">>
    <<set $job to {
    	name     : "No Idea",
    	response : "Wait... $pname, you registered for an appointment but you don't know what the appointment was for? (You hear a hushed conversation in the distance) ...Oh! Right, you're THAT $pname! Sorry for the confusion, come on in.",
    	head     : "HUDAR Glasses",
    	top      : "Baja Hoodie",
    	bottom   : "Baggy Jeans",
    	feet     : "Flip Flops"
    }>>
    <</click>>
    
    And the followup passage—named "Confirm Job" in the above example:
    <<set
    	$head   to $job.head,
    	$top    to $job.top,
    	$bottom to $job.bottom,
    	$feet   to $job.feet
    >>\
    $job.response
    


    That said, unless you're going to continue using the job object, you're probably better off simply setting $head, $top, $bottom, $feet, and a variable for the response directly within each <<click>>—no need for an object. For example—only going to do one here, you should get the idea:
    <<click "Business Appointment" "Confirm Job">>
    <<set
    	$response to "Ah, yes, $pname, we have you listed down here because you were interested in buying our products? Please, come on in and we can get started.",
    	$head     to "Glasses",
    	$top      to "Business Shirt",
    	$bottom   to "Business Pants",
    	$feet     to "Fancy Shoes"
    >>
    <</click>>
    
    And the followup:
    $response\
    <<unset $response>>
    
    In this case, you probably don't need to keep the response around once the player has seen it, so unset its variable afterward.
  • Ah! Yeah, that seems like it'd make things much easier. Thanks for the help, I think that second option would work better for my story, haha!
Sign In or Register to comment.