Quantcast
Channel: Help! with 2.0 - Twine Forum
Viewing all articles
Browse latest Browse all 1844

Having trouble checking the tags of a passage against a list of tags

$
0
0
I'm using Twine 2 and Sugarcube 2.7.0, and I'm trying to write a widget that will produce a link to a new passage if and only if none of that passage's tags appear on a list of forbidden tags, so that the player will only be offered links to areas they're allowed to access. Currently what I have is:
<<set $forbiddenAreas = ["heated", "water"]>>
<<widget permCheck>><<set _areatags to tags($args[1])>><<print _areatags>>
<<if $forbiddenAreas.contains(_areatags)>><<else>>
<<print "[[" + $args[0] + "|" + $args[1] + "]]">><<endif>><</widget>>
in my StoryInit passage, which has a widget tag to make sure the widget is accessible, and
<<print $forbiddenAreas>>
<<print tags("test area - hot")>>
<<print tags("test area - water")>>
<<print tags("test area - hot water")>>

<<permCheck "Superheated Test Area" "test area - hot">>
<<permCheck "Underwater Test Area" "test area - water">>
<<permCheck "Double Test Area" "test area - hot water">>
as my test page. However, even though the debug print statement in my widget shows the area tags being found correctly, they don't seem to be getting recognised by the $forbiddenAreas.contains() statement. What I get is:
heated, water
heated
water
heated, water

heatedSuperheated Test Area
waterUnderwater Test Area
heated, waterDouble Test Area
with working links to the new areas. I've tested Array.contains() with string literals rather than variable substitution, and that works, so I suspect it's something along the lines of getting a reference where I need a value or a value where I need a reference, but I can't figure out where I've gone wrong.

Viewing all articles
Browse latest Browse all 1844

Trending Articles