0 votes
by (160 points)
edited by

I made a passage that's acting as a hub for the particular day. It has $day1 variable which ticks down the hours remaining, and several setter links that lead to randomised passages which are also set in this passage.

It was working before in a more complicated format. All I have done is remove the <<timed>> from each link. I must be missing an error which is causing all of them to break, but I cannot see what.

To rule out an error with the passage, I have tried it in a new passage which also didn't work.

I'm very much a casual user and clearly have no coding skills. I'm sure this is a mess -- it's just that it is a mess that was working until suddenly it wasn't! Enlightenment would be very much appreciated. :)

<span style="font-size:50px;">Day 1</span>
@@.typed; 
Hours remaining: <<print $day1>> @@ 
<<nobr>><<if $day1 == 0>><<goto [[day1end]]>><</if>><</nobr>>

//[[Raid a tomb (3hrs)|$ptombraider][$day1 -= 3]]//
//[[Sneak into town for supplies (2hrs)|$ptown][$day1 -= 2]]//
//[[Explore the caves (1hr)|$pcave][$day1 -= 1]]//
//[[Practice the craft (6hrs)|$pnecro][$day1 -= 6]]//
//[[Create life|monster craft]]//
<<nobr>>
<<set $ptombraider to either(
    'tombraider1',
    'tombraider2',
    'tombraider3'
)>>
<<set $ptown to either(
    'town1',
    'town2',
    'town3'
)>>
<<set $pcave to either(
    'cave1',
    'cave2',
    'cave3'
)>>
<<set $pnecro to either(
    'necro1',
    'necro2',
    'necro3'
)>>
<</nobr>>
<<audio "dungeon" fadein play>>

UPDATE: Okay so I'm now finding that it won't work when I first enter the passage, but if I leave the passage (via the only working link [[create life]] and then return to it it works as intended. Is it just taking too long to load the links or something?

1 Answer

+1 vote
by (159k points)
edited by
 
Best answer

You should always initialise (assign the default value to) a variable before you later make a reference to that same variable.

/% BAD %/
Some references to variables...
[[Link Text|$targetPassage]]
Name: $name

Sometime later initialising the previous referenced variable to some value...
<<set $targetPassage to "Home">>
<<set $name to "Some name">>


/% GOOD %/
Initialising some variables...
<<set $targetPassage to "Home">>
<<set $name to "Some name">>

Sometime later referencing the previously initialised variables.
[[Link Text|$targetPassage]]
Name: $name

In your example the variables being used to supple the names of the Target Passage of each of your links aren't assign their initial value until after the links have been created.

Try structuring your example like so:

<span style="font-size:50px;">Day 1</span>
@@.typed; 
Hours remaining: <<print $day1>> @@ 
<<silently>>
	<<if $day1 == 0>><<goto [[day1end]]>><</if>>

	<<set $ptombraider to either(
    	'tombraider1',
    	'tombraider2',
    	'tombraider3'
	)>>
	<<set $ptown to either(
    	'town1',
    	'town2',
    	'town3'
	)>>
	<<set $pcave to either(
    	'cave1',
    	'cave2',
    	'cave3'
	)>>
	<<set $pnecro to either(
    	'necro1',
    	'necro2',
    	'necro3'
	)>>
<</silently>>\
//[[Raid a tomb (3hrs)|$ptombraider][$day1 -= 3]]//
//[[Sneak into town for supplies (2hrs)|$ptown][$day1 -= 2]]//
//[[Explore the caves (1hr)|$pcave][$day1 -= 1]]//
//[[Practice the craft (6hrs)|$pnecro][$day1 -= 6]]//
//[[Create life|monster craft]]//

<<audio "dungeon" fadein play>>

... you will also notice that I replaced the <<nobr>> macro usage, which just removes any unwanted line-breaks, with the <<silently>> macro which suppresses all visual output.

by (160 points)
Thank you! This has absolutely solved the problem. I feel a little ridiculous that I didn't initialize them in an earlier passage or something, which is what I've done with everything else. This doesn't come very naturally to me yet.

Also many thanks for reminding me of the <<silently>> macro, which I'd completely forgotten about.

Very much appreciated!
...