@set card1=0
@set card2=0
@set card3=0
@set card4=0
@set print
[[four card montey]]
[[four card montey]]:
var rnd = Math.ceil(Math.random() * 4);
squiffy.set("rnd",rnd)
@set print=1
[[Draw a card]]
[[Draw a card]]:
if (squiffy.get("rnd")==1){
if (squiffy.get("card1")==0){
squiffy.set("card1",1);
squiffy.set("print",1);
}
else{
squiffy.set("rnd",2);
squiffy.set("print",0);
squiffy.story.go("Draw a card");
}
}
if (squiffy.get("rnd")==2){
if (squiffy.get("card2")==0){
squiffy.set("card2",1);
squiffy.set("print",1);
}
else{
squiffy.set("rnd",3);
squiffy.set("print",0);
squiffy.story.go("Draw a card");
}
}
if (squiffy.get("rnd")==3){
if (squiffy.get("card3")==0){
squiffy.set("card3",1);
squiffy.set("print",1);
}
else{
squiffy.set("rnd",4);
squiffy.set("print",0);
squiffy.story.go("Draw a card");
}
}
if (squiffy.get("rnd")==4){
if (squiffy.get("card4")==0){
squiffy.set("card4",1);
squiffy.set("print",1);
}
else{
squiffy.set("rnd",1);
squiffy.set("print",0);
squiffy.story.go("Draw a card");
}
}
{if print=1:
Your card is {rnd}
[[Draw a card]]
}
[[setup]]:
squiffy.story.go("deal");
@set card1=0
@set card2=0
@set card3=0
@set card4=0
@set cardNum = 1
[[deal]]:
var rnd = Math.ceil(Math.random() * 4);
squiffy.set("rnd",rnd);
if (squiffy.get("rnd")==1){
if (squiffy.get("card1")==0){
squiffy.set("card1",(squiffy.get("cardNum")));
squiffy.set("cardNum",(squiffy.get("cardNum")+1));
}
}
if (squiffy.get("rnd")==2){
if (squiffy.get("card2")==0){
squiffy.set("card2",(squiffy.get("cardNum")));
squiffy.set("cardNum",(squiffy.get("cardNum")+1));
}
}
if (squiffy.get("rnd")==3){
if (squiffy.get("card3")==0){
squiffy.set("card3",(squiffy.get("cardNum")));
squiffy.set("cardNum",(squiffy.get("cardNum")+1));
}
}
if (squiffy.get("rnd")==4){
if (squiffy.get("card4")==0){
squiffy.set("card4",(squiffy.get("cardNum")));
squiffy.set("cardNum",(squiffy.get("cardNum")+1));
}
}
if (squiffy.get("cardNum")>4){
squiffy.story.go("exit");
}
else{
squiffy.story.go("deal");
}
[[exit]]:
In exit
{card1}
{card2}
{card3}
{card4}
[[first section]]:
@set name=3
{varName}
[[second section]]:
This is the second section
[[varName]]:
{if name=1:Ace of spades}
{if name=2:Two of spades}
{if name=3:Three of spades}
I feel compelled to post this here, maybe for future people showing up here via Google? Not sure.
[[setup]]:
var cards = [1, 2, 3, 4].sort(function() { return 0.5 - Math.random(); });
for(var i = 0; i < cards.length; i++) {
squiffy.set("card" + (i + 1), cards[i]);
}
{exit}
[[exit]]:
In exit
{card1}
{card2}
{card3}
{card4}
Please do note though that the random is not unbaised. If you want it to be completely unbiased use a shuffle like this.