0 votes
by (950 points)

This is the pregnancy system that I created ...adding some randomness... not every time would cause a pregnancy like that... been testing it and it works well. The tag is currently "Pregnancy" and is in the bed passage. There is also the code from below. The randomness is currently 3 ... for testing the code... so every third visit right now is causing a pregnancy... I will raise that up or look for something even more random :D

<<if visitedTags("Pregnancy") % 3 is 0>>
 <<if $Status is "Happy">>
 ...and ACTION!
 <<set $Status to "Pregnant">>
 <<run $birth.setMonth($birth.getMonth() + 9)>>
 <</if>>
<</if>>

Question:
After this now is propperly creating the pregnancy at a random fashion, how would I possibly trigger the Hospital when the birth date that was set in that above code, is over?

Meaning, above code set a date from the moment the pregnancy was caused... that date is 9 month in the future and for 9 month in the future the birth needs to happen. I was thinking about it and got headache... 

So I need a code that is triggering the hospital when the pregnancy birth date is actually reached. XD

Can you guys help me once again? ;)

*waves*

Mr. Peppermint

 

 

 

3 Answers

+1 vote
by (8.9k points)
selected by
 
Best answer
<<if $gameDate gte $birth>>
Hospital
<<else>>
Normal content
<</if>>

Corrected thanks to Greyelf

by (159k points)

@Charlie: You're missing the dollar sign symbol from the birth story variable name.

<<if $gameDate gte $birth>>
Hospital
<<else>>
Normal content
<</if>>

 

by (8.9k points)

blush thanks greyelf

0 votes
by (159k points)

note: If your example is based on the code I supplied in your Does anyone have an idea to create a countdown using the gregorian widget java calendar question then you have left out the (set:) macro that creates the $birth date based on the current $gameDate.
eg. Your example should look like the following.

<<if visitedTags("Pregnancy") % 3 is 0>>
	<<if $Status is "Happy">>
		...and ACTION!
		<<set $Status to "Pregnant">>
		<<set $birth to clone($gameDate)>>
		<<run $birth.setMonth($birth.getMonth() + 9)>>
	<</if>>
<</if>>

 

Because the triggering of the "Go to Hospital" event is based on the $birth Date value becoming less than the current $gameDate Date value then you will need to do that check every time you modify the current value of the $gameDate Date in your story.

How you do that depends greatly on how you've structured the logic of your game, which we don't know.

eg. Do you have a set of common functionality that controls the forward motion of time for things like travelling around your locations and the sleeping cycle? Is the usage of the code that handles the changing of time limited to a small number of Passage or spread over many Passages.

by (950 points)

Actually, I put that line:

<<set $birth to clone($gameDate)

inside StoryInit. Works perfectly like that... i especially put a line in StoryCaption that printed me the $birth to see if the value ends up to be correct (just for testing). The date of birth is set to 9 month in the future correctly ...of course, it shows the gamedate if you aren't pregnant but that's okay it was just for testing so I could see if the date changes as it should. Later on that info will not be shown in game. :)

Thank you to CHARLIE and GREYELF again for helping me out about the triggering for the Hospital :)

*waves*

Mr. Peppermint

by (950 points)
But it does raise one question... does it track the entire event throughout the game or will I need to put a remember macro so it remembers which settings the status had?
by (159k points)

You shouldn't initialise the $birth variable inside StoryInit because that makes it initially equal to the date/time that the player started playing the game, and not initially equal to the date/time that the conception actually occurred.

See my new answer to this question for greater detail.

by (950 points)
Aaaah.... okay I didn't know that. Now that makes sense, thank you, I will change that. Thank you for pointing that out :)

*waves*

Mr. Peppermint
+1 vote
by (159k points)
edited by

There are three different states that the intended pregnancy needs to exist in:

1. The Person isn't pregnant yet.

You can use the fact that the $birth variable doesn't exist (is undefined) to track this state, this sort of check is also needed to make sure the conception activity doesn't occur while the person is already pregnant. eg. She can't get pregnant if she is currently pregnant.

You can use the ndef operator listed in the TwineScript conditional operator section of the <<if>> macro to determine if a variable has been initialised/assigned a value yet.

<<if ndef $birth>>The person is not pregnant!<</if>>

You should check the state of the $birth variable at the time of conception so that the person doesn't get impregnated again while they are currently pregnant. The following is a modified version of your conception example, if only allow the impregnation of someone whose not currently pregnant, and it correctly set the $birth variable to be equal to the Date/Time of the conception plus 9 months.

<<if ndef $birth and visitedTags("Pregnancy") % 3 is 0>>
	<<if $Status is "Happy">>
		...and ACTION!
		<<set $Status to "Pregnant">>
		<<set $birth to clone($gameDate)>>
		<<run $birth.setMonth($birth.getMonth() + 9)>>
	<</if>>
<</if>>


2. The Person is currently pregnant.

You can use the existence of the $birth variable (is defined) to determine if person is currently pregnant, this is done by using the def operator listed in the TwineScript conditional operator section of the <<if>> macro to determine.

<<if def $birth>>The person is pregnant!<</if>>

You would use this check combine with comparing the $birth variable's value to that of the current value of the $gameDate variable to determine if it is time for the person to give birth. You need to use the <<unset>> macro during the birthing event to stop that event from occurring multiple times for a singe pregnancy, you may also want to update whatever variable you are using to track then number of kids the person has.

<<if def $birth and $birth lte $gameDate>>\
	It's time for the birthing event!\
	<<unset $birth>>\
	<<set $kids to $kids + 1>>\
	<<set $Status to "Happy">>
<</if>>

note: The above check needs to occur whenever game time moves forward, which is everytime you cause the value of $gameDate to change within the story.

3. The Person has (just) given birth, so there for can become pregnant again.

Because you have used the <<unset>> macro to un-define the $birth variable during the birthing event the code in point 1 will new correctly indicate that the person is not currently pregnant, and there for the conception code may be used again to get them pregnant again.

by (950 points)
Perfect <3

I adore your knowledge of these things... I learn every day and maybe at some point I some time know a few things to help others that started up like me with about no knowledge at all about this but it's a lot fun to learn and discover and I spend hours and hours of googling what I am looking for before asking here :)

Thank you the kids stuff would have been a possible question of mine...

I am happy you are guiding me with it :) But it would also mean the status must be returned to "Happy" so unset as well, right? Because the trigger for an eventual pregnancy is the status... *thinks*

On a side note, I bet this is a question that others might also find helpful :)

*waves*

Mr. Peppermint
by (159k points)

But it would also mean the status must be returned to "Happy" 

You are correct that the $status variable should be changed from "Pregnant" to some other value at the same point that the $birth variable is unset during the birthing event. Only you know whether that new value should be "Happy", "Tired", "Angry", "Depressed", "Homicidal", or some other status. *smile*

I have updated the second example of point 2 to reflect the status change.

by (950 points)

I assume that I need to paste that birth codes into all passages where she be roaming about so it keeps track when the hospital event is going to happen no matter where she is...

If I was to devide it like this will that work...

Put into Living Room/Kitchen/Bathroom/Corridor/Street this code:

<<if def $birth and $birth lte $gameDate>>
You need to go to the [[hospital|Hospital]]
<</if>>

and then inside the HOSPITAL PASSAGE i put this:

<<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>>

Just wondering...

*scratches head*

Mr. Peppermint

by (159k points)

You could paste the first example in your previous post into all of those Passages you listed (as well as any other passages that advances the game date/time), or you could add it to the PassageFooter special passage which automatically added it's contents to the bottom of each Passage displayed.

...