Need help setting variables in a certain order

trevers18
Not exactly sure if the title is exactly what this problem is, but it's as close as I can describe it. I want to have three different outcomes to a situation depending on what the player does, and in order to so, I need to know the order that the player chooses the three passages. Here's the scenario:

Cheryl and Mike are stuck in a car that has crashed off the side of the road. Cheryl is the only one conscious at the moment. She has to wake up Mike in order to get him out of the car, but she also has to get all of their supplies out of the back seat. When she wakes Mike up, she realizes that he has a head injury and is bleeding profusely and needs to patch him up. How many supplies they get is determined by the order of Cheryl's actions. She has two turns before the car is blocked by the falling snow and can no longer be accessed.


The outcomes are:

Cheryl wakes up Mike --> chooses to get everything outside = gets all supplies but Mike loses a lot of blood
Cheryl gets everything outside --> wakes up Mike = get almost everything and Mike doesn't lose a lot of blood
Cheryl wakes up Mike --> fixes Mike's head injury = get very few supplies but Mike loses almost no blood


Here's the problem. I can't figure out how to set the variables to determine the order that she chooses. Here's what needs to happen:

If Cheryl wakes up Mike first --> set variable "first" to "wake up"
if Cheryl gets the supplies out first --> set variable "first" to "get everything"

if Cheryl patches up Mike second --> set variable "second" to "patch up" (only available if she chooses to wake him up first)
if Cheryl wakes up Mike second --> set variable "second" to "wake up"
if Cheryl gets everything out second --> set variable "second" to "get everything"


I've tried tons of different methods but there's nothing that can get what I need. I need to be able to check that the variable "first" isn't already set to the other option and then set the chosen option to "first", and in that same check, I need to have the chosen option set to "second" if "first" is already set with the other option. I can't figure out the code for this and it's driving me crazy. :evil: Any assistance would be appreciated.

TM123
I just learned this myself, there probably is a better way to do it.

@title Testing
[[initialize the variables]]:
squiffy.set("varFIRST", "DID NOTHING")
squiffy.set("varSECOND", "DID NOTHING")
squiffy.set("varBLOODLOSS", "EMPTY")
squiffy.set("varSUPPLIES", "EMPTY")
Here is some text. Click to [[starthere]].
[[starthere]]:
Should she [Wake Mike](one) or [get supplies?](two) or [[move on to next section]](four)

[one]:
var varFIRST = squiffy.get("varFIRST");
var varSECOND = squiffy.get("varSECOND");
if (varFIRST=="DID NOTHING") {squiffy.set("varFIRST", "woke up Mike")} else {squiffy.set("varSECOND", "woke up Mike")};
She wakes Mike. Should she [patch his head](three) now?

[two]:
var varFIRST = squiffy.get("varFIRST");
var varSECOND = squiffy.get("varSECOND");
if (varFIRST=="DID NOTHING") {squiffy.set("varFIRST", "got the supplies")} else {if (varSECOND=="DID NOTHING") {squiffy.set("varSECOND", "got the supplies")}};

[three]:
var varSECOND = squiffy.get("varSECOND");
if (varSECOND=="DID NOTHING") {squiffy.set("varSECOND", "Patched up Mike")};

[[four]]:
var varFIRST = squiffy.get("varFIRST");
var varSECOND = squiffy.get("varSECOND");
if (varSECOND=="got the supplies") {squiffy.set("varBLOODLOSS", "lots of"); squiffy.set("varSUPPLIES", "all")} else {if (varSECOND=="woke up Mike") {squiffy.set("varBLOODLOSS", "some"); squiffy.set("varSUPPLIES", "some")} else {squiffy.set("varBLOODLOSS", "a little"); squiffy.set("varSUPPLIES", "few")}};
"Well," she says, "First I {varFIRST} then I {varSECOND}" Mike has lost {varBLOODLOSS} blood and she got {varSUPPLIES} of the supplies.

TM123
Here's another method. It uses one variable, varORDER, which gets each step concatenated to it in the order they are done.
The "switch" thing checks if varORDER matches each "case" and then sets the variables varBLOODLOSS and varSUPPLIES, and also changes varORDER to a new string.
The "default" is done if there is no match. The "varORDER.indexOf("Get")==-1" checks to see if "Get" is NOT in the string varORDER.
You could check if the word "Get" IS in the string like so: varORDER.indexOf("Get")>0



@title Testing
[[initialize the variables]]:
squiffy.set("varORDER", "")
Here is some text. Click to [[starthere]].
[[starthere]]:
Should she [Wake Mike](one) or [get supplies?](two) or [[move on to next section]](four)

[one]:
var varORDER = squiffy.get("varORDER");
squiffy.set("varORDER", varORDER + "Wake_");
She wakes Mike. Should she [patch his head](three) now?

[two]:
var varORDER = squiffy.get("varORDER");
squiffy.set("varORDER", varORDER + "Get_");
She gets the supplies.

[three]:
var varORDER = squiffy.get("varORDER");
squiffy.set("varORDER", varORDER + "Patch_");
She patches up his head.

[[four]]:
var varORDER = squiffy.get("varORDER");

switch (varORDER) {

case "Wake_Patch_Get_":
squiffy.set("varORDER", "woke up Mike and then I patched his head");
squiffy.set("varBLOODLOSS", "a little");
squiffy.set("varSUPPLIES", "few");
break;

case "Get_Wake_Patch_":
squiffy.set("varORDER", "got the supplies and then I woke up Mike");
squiffy.set("varBLOODLOSS", "some");
squiffy.set("varSUPPLIES", "some");
break;

case "Wake_Get_Patch_":
squiffy.set("varORDER", "woke up Mike and then I got the supplies");
squiffy.set("varBLOODLOSS", "lots of");
squiffy.set("varSUPPLIES", "all");
break;

default:
if (varORDER.indexOf("Get")==-1) {squiffy.set("varSUPPLIES", "none")} else {squiffy.set("varSUPPLIES", "some")};
if (varORDER.indexOf("Patch")==-1) {squiffy.set("varBLOODLOSS", "all of his")} else {squiffy.set("varBLOODLOSS", "some")};
squiffy.set("varORDER", "panicked and didn't think things through");
}

"Well," she says, "First I {varORDER}." Mike has lost {varBLOODLOSS} blood and she got {varSUPPLIES} of the supplies.

trevers18
That worked out great! Thanks to both of you!

Biep
This works:
Do [a] or [b] or [c].

[]:
@inc step

[a]:
squiffy.set("a", squiffy.get("step"))
You did a.

[b]:
squiffy.set("b", squiffy.get("step"))
You did b.

[c]:
squiffy.set("c", squiffy.get("step"))
You did c.

[@2]:
squiffy.story.go("ready");

[[ready]]:
So a={a} b={b} and c={c}.
Which is short, but setting the variables is still convoluted.

I had hoped "@set a=step" would work, but that sets a to the string "step". "@set a={step}" doesn't work either, nor does "@set a=[step]" together with a passage
[step]:
{step}

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

Support

Forums