0 votes
by (870 points)
retagged by

I've tried looking around, so apologies in advance if this has been answered and/or if it's an obvious answer. I'm pretty new to twine.

I'm trying to add romance elements to my story, including making a family with an npc. I followed along with the following threads (gregorian date and timeaccess pregnancy progressionhow to trigger birthing) and had everything working as it should, no problem. I even made minor edits to account for randomized multiples

:: StoryInit

<<if $fertility gte 75>>
<<set $multipleChance = {
	quadruplets: 0.1,
	triplets: 0.2,
	twins: 0.4,
	singleton: 0.6
}>>
<<elseif $fertility gte 50>>
<<set $multipleChance = {
	quadruplets: 0.05,
	triplets: 0.15,
	twins: 0.3,
	singleton: 0.5
}>>
<<else>>
<<set $multipleChance = {
	quadruplets: 0,
	triplets: 0.1,
	twins: 0.2,
	singleton: 0.4
}>>
<</if>>


<<if $random <= $multipleChance.quadruples>>
	<<set $multiples to "quadruplets">>
<<elseif $random <= ($multipleChance.quadruplets + $multipleChance.triplets)>>
	<<set $multiples to "triplets">>
<<elseif $random <= ($multipleChance.quadruplets + $multipleChance.triplets + $multipleChance.twins)>>
	<<set $multiples to "twins">>
<<else>>
	<<set $multiples to "singleton">>
<</if>>

:: conception act

<<if ndef $birth and visitedTags("pregnancy") is 3>>
  <<if $emotion is "happy" or $emotion is "content">>
	action!
	<<set $pregnant to true>>
	<<set $conception to clone($gameDate)>>\
	<<set $birth to clone($gameDate)>>
	
	
	  <<if $multiples is "singleton">>
	  <<set $birth.setDate($birth.getDate() + 266 + random(-21, 14))>>
	  <<elseif $multiples is "twins">>
	  <<set $birth.setDate($birth.getDate() + 266 + random(-28, 7))>>
	  <<elseif $multiples is "triplets">>
	  <<set $birth.setDate($birth.getDate() + 266 + random(-35, 0))>>
	  <<elseif $multiples is "quadruplets">>
	  <<set $birth.setDate($birth.getDate() + 266 + random(-42, -7))>>
	  <</if>>


	<<silently>>
	gameDate: $gameDate
	birth: $birth
	<<set _pregnant to setup.isPregnant()>>
	<<set _due to setup.estimatedDueDate()>>
	<<set _weeks to setup.weeksPregnant()>>


\conception: <<= $conception>>
birth: <<= $birth>>
\fetus count: <<= $multiples>>	
<</silently>>

  <</if>>
  <<else>>
<</if>>

My issue comes when the character has done everything necessary to conceive a second child.

<<if def $birth and $birth lte $gameDate>>
	Whatever to describe what happens in the hospital
	<<unset $birth>>
	<<set $kids to $kids + 1>>
	<<set $Status to "Happy">>
<</if>>

<<if def $birth and $birth lte $gameDate>>\
	It's time for the birthing event!\
    <<unset $birth>>
	<<if $health gte 50 and $multiples is "singleton">>
	<<set $kids to $kids += 1>>
	<<elseif $health gte 50 and $multiples is "twins">>
	<<set $kids to $kids += 2>>
	<<elseif $health gte 50 and $multiples is "triplets">>
	<<set $kids to $kids += 3>>
	<<elseif $health gte 50 and $multiples is "quadruplets">>
	<<set $kids to $kids += 4>>
	<</if>>
	Congratulations!\
	<<if $health lt 50>>
	<<set $kids to $kids += 0>>
	The baby didn't make it.
	<</if>>
	<<set $Status to "Happy">>
<</if>>

(how to trigger birthing)

Unsetting the birth variable doesn't seem to do anything? When I cycle through the passages to simulate the character's second pregnancy, the due date doesn't change. Considering it is based on a cloned conception date that has a randomized threshold, I don't think I'm just randomly getting the same due date. Plus, the due date is 9+ months behind the current game date. I've put some passages between the first labor and second conception attempt and have even used the "add days" widget in case the game had to have a day change in between, but nothing I do seems to alter the variables the way I need them to. I have no idea what to do to make it change.

Any help is super appreciated! c: thanks in advance.

1 Answer

0 votes
by (159k points)
selected by
 
Best answer

It is easy to prove if the <<unset>> macro works or not, and the following TWEE notation does just that.

:: Start
<<set $variable to "value">>
<<if def $variable>>The variable is defined.<</if>>

<<unset $variable>>
<<if def $variable>>The variable is STILL defined.<<else>>There is no variable!<</if>>

[[Next|Second]]

:: Second
<<if def $variable>>The variable is STILL defined.<<else>>There is no variable!<</if>>

Which produces the following output when the Start passage is viewed.

The variable is defined.

There is no variable!

... and the following output after the Next link is selected to view the Second passage.

There is no variable!


It is strange to see <<if>> related macros at the start of the StoryInit special passage, without some form of randomness being used prior to them. Generally I would assign default values to each of my story variables, to make sure that they all do have a default value, before I conditionally overwrite those defaults.

<<set age to 20>>
<<set $health to 10>>
<<set $magic to 10>>

<<if random(1, 6) gte 5>>
  <<set age to 25>>
  <<set $health to 15>>
<</if>>


Your conception act passage is trying to output text within a <<silently>> macro, and that macro supresses all visual output. This passage (as shown) also only initialises the $birth story variable if:
a. It doesn't already exist.
b. if exactly three passages with the pregnancy tag have been previously seen. (this is likely only true once)
c. the current value of the $emotion story variable is either "happy" or "content"
 

by (870 points)
edited by
Edit no. 2: Okay, never mind! :DD I figured out the issue. Unset wasn't the problem, your suggested test worked. I removed the "exactly three passages with pregnancy tag have been previously seen" condition and it started generating new due dates.

Thank you so much for your help, I wouldn't have realized that otherwise.
...