Can someone check my time code?

Twine Version: 2.8.0

I decided to rewrite my code to make it easier to understand and I ran into some errors while rewriting. I think the following code is complete, but I’m getting errors
regarding the if statements while I was testing the widget. Could someone go over my code and let me know where the errors are?

/* Changes the time of day (use <<widget "add-time">> to pass 1 unit of time) */
<<widget "add-time-new">>

// Adds one unit of time
<<set $gameTime += 1>>

/* If $gameTime would be "Midnight", automatically put the player to bed */
<<if $gameTime == 6>>

/* Replaces whatever content the player would see and sends them to bed */
<<done>>
<<replace "#content">>
It's getting late. You decide to go to bed. 
<br><br><<button "Okay.">>

/* Modifies date and time variables */
<<set $gameMonthDay += 1>>
<<set $gameDay += 1>>
<<set $gameTime = $playerAlarm>>

<</done>>
<</if>>

/* Rolls over day to "Sunday" if the day ends during "Saturday" */
<<if $gameDay = 6>>

/* Modifies date accordingly */
<<set $gameDay = 0>>
<</if>>

/* Checks if the month is a month with 31 days */
<<if $gameMonth == 0, $gameMonth == or 2, $gameMonth == or 4, $gameMonth == or 6, $gameMonth == or 7, $gameMonth == or 9, $gameMonth == or 11>>

/* Changes month when going to bed on the 31st day */
<<if $gameMonthDay == 32>>
<<set $gameMonth += 1>>
<<set $gameMonthDay = 1>>

/* Checks if the month is "December" */
<<if $gameMonth == 11>>

/* Rolls over to "January" and increases the year */
<<set $gameYear += 1>>
<<set $gameMonth = 0>>

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

/* Checks if the month is a month with 30 days */
<<if $gameMonth == 1, $gameMonth == or 3, $gameMonth == or 5, $gameMonth == or 8, $gameMonth == or 10>

/* Changes month when going to bed on the 30th day */
<<if $gameMonthDay == 31>>
<<set $gameMonth += 1>>
<<set $gameMonthDay = 1>>

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

/* Checks if the month is "Feburary" */
<<if $gameMonth == 1>>

/* Checks if it's not leap year and going to bed on the 28th day */
<<if $gameMonthDay == 29 and $gameYear % 4 != 0>>

/* Changes values */
<<set $gameMonth += 1>>
<<set $gameMonthDay = 1>>

<</if>>

/* Checks if it is leap year and you are going to bed on the 29th day */
<<if $gameMonthDay = 30 and $gameYear % 4 = 0>>

/* Changes values */
<<set $gameMonth += 1>>
<<set $gameMonthDay = 1>>

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

/* Checks if it is the first day of the month */
<<if $gameMonthDay == 1>>

/* Checks if the month is "March" and changes the season to "Spring" if it is */
<<if $gameMonth == 2>>
<<set $gameSeason = 0>>
<</if>>

/* Checks if the month is "June" and changes the season to "Summer" if it is */
<<if $gameMonth == 5>>
<<set $gameSeason = 1>>
<</if>>

/* Checks if the month is "September" and changes the season to "Autumn" if it is */
<<if $gameMonth == 8>>
<<set $gameSeason = 2>>
<</if>>

/* Checks if the month is "December" and changes the season to "Winter" if it is */
<<if $gameMonth == 11>>
<<set $gameSeason = 3>>
<</if>>
<</if>>

<</widget>>

All help is greatly appreciated :slight_smile:

I would advise you to get VSCode and the Twee 3 Language Tool extension, because it is a great way of finding errors like missing closing tag for macros (which seems to be the biggest issue here):

  • <<replace>> doesn’t have a closing tag
  • <<button>> doesn’t have a closing tag
  • if you are using a nobr tag for the Widget passage, comments formatted with // may break the code. Using /* */ is recommended.
  • $gameMonth == or 2, $gameMonth == or 4, : this won’t work, because <<if>> can’t use comma between conditions.
  • $gameMonth == or 8, $gameMonth == or 10>: you’re missing a >

Another tip: indent your code too :wink: It will help you a lot when you have to organise code

<<macro1>>
    <<macro2>>
<</macro1>>
1 Like

I tried seeing if there was something like that on VS Code, but couldn’t find it. Still relatively new to coding so I completely forgot about downloading extensions. Thanks for that.

That’s good to know, thanks.

So in this case, it should just be $gameMonth == 2 or $gameMonth == 4? (I didn’t realize I put the comparison operator before the or).

Yeah, in the original widget I had to manipulate time, I had my lines indented, but found that I had so many tested if statements that I lost half my screen due to indents, but using VS Code would probably fix that issue for me.

I’ll get started with implementing these fixes. I’ll post again if I have any further questions.

Yup. And you can find the list of accepted terms on the documentation :wink:

It’s also here

1 Like

Hmm. I fixed all the issues you mentioned, and now I’m no longer getting an error in my test passage when I try to pass the time. However, nothing seems to occur when I try to hit my pass time button.

Edit: Below is the code I’m currently using.

/* Changes the time of day (use <<widget "add-time">> to pass 1 unit of time) */
<<widget "add-time-new">>

/* Adds one unit of time */
<<set $gameTime += 1>>

/* If $gameTime would be "Midnight", automatically put the player to bed */
<<if $gameTime == 6>>

/* Replaces whatever content the player would see and sends them to bed */
<<done>>
<<replace "#content">>
It's getting late. You decide to go to bed. 
<br><br><<button "Okay.">><</button>>
<</replace>>
<</done>>

/* Modifies date and time variables */
<<set $gameMonthDay += 1>>
<<set $gameDay += 1>>
<<set $gameTime = $playerAlarm>>

<</if>>

/* Rolls over day to "Sunday" if the day ends during "Saturday" */
<<if $gameDay == 6>>

/* Modifies date accordingly */
<<set $gameDay = 0>>
<</if>>

/* Checks if the month is a month with 31 days */
<<if $gameMonth == 0 or $gameMonth == 2 or $gameMonth == 4 or $gameMonth == 6 or $gameMonth == 7 or $gameMonth == 9 or $gameMonth == 11>>

/* Changes month when going to bed on the 31st day */
<<if $gameMonthDay == 32>>
<<set $gameMonth += 1>>
<<set $gameMonthDay = 1>>

/* Checks if the month is "December" */
<<if $gameMonth == 11>>

/* Rolls over to "January" and increases the year */
<<set $gameYear += 1>>
<<set $gameMonth = 0>>

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

/* Checks if the month is a month with 30 days */
<<if $gameMonth == 1, $gameMonth == 3 or $gameMonth == 5 or $gameMonth == 8 or $gameMonth == 10>>

/* Changes month when going to bed on the 30th day */
<<if $gameMonthDay == 31>>
<<set $gameMonth += 1>>
<<set $gameMonthDay = 1>>

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

/* Checks if the month is "Feburary" */
<<if $gameMonth == 1>>

/* Checks if it's not leap year and going to bed on the 28th day */
<<if $gameMonthDay == 29 and $gameYear % 4 != 0>>

/* Changes values */
<<set $gameMonth += 1>>
<<set $gameMonthDay = 1>>

<</if>>

/* Checks if it is leap year and you are going to bed on the 29th day */
<<if $gameMonthDay = 30 and $gameYear % 4 = 0>>

/* Changes values */
<<set $gameMonth += 1>>
<<set $gameMonthDay = 1>>

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

/* Checks if it is the first day of the month */
<<if $gameMonthDay == 1>>

/* Checks if the month is "March" and changes the season to "Spring" if it is */
<<if $gameMonth == 2>>
<<set $gameSeason = 0>>
<</if>>

/* Checks if the month is "June" and changes the season to "Summer" if it is */
<<if $gameMonth == 5>>
<<set $gameSeason = 1>>
<</if>>

/* Checks if the month is "September" and changes the season to "Autumn" if it is */
<<if $gameMonth == 8>>
<<set $gameSeason = 2>>
<</if>>

/* Checks if the month is "December" and changes the season to "Winter" if it is */
<<if $gameMonth == 11>>
<<set $gameSeason = 3>>
<</if>>
<</if>>

<</widget>>

You still have issues:

<<if $gameMonth == 1, $gameMonth == 3 or $gameMonth == 5 or $gameMonth == 8 or $gameMonth == 10>>
<<if $gameMonthDay = 30 and $gameYear % 4 = 0>>
1 Like

Ah. There we go. That fixed all the issues. Thanks :slight_smile: