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

Using the loop to assign variables in an array to another specific variable

$
0
0
I want to be able to assign one person to a room. I have these 3 rooms with clickable links:
Room 01 - [[$room01|AssignRooms]]
Room02 - [[$room02|AssignRooms]]
Room03 - [[$room03|AssignRooms]]

where $room01, $room02, and $room03 will be the names of the people assigned to that room once selected (default is initialized to "none" when you begin). AssignRooms is the passage where you get to select the people.

I have the following people variables in an array (note: as the player progresses and meets new people, more names will be added here so it's not static):
<<set $temprooms = ["Lydia", "Desi", "Jereck", "Rawn", "Teleri"]>>


Here's what I have for the AssignRooms passage for room01:

Room #1: $room01

<<for $i to 0; $i lt $temprooms.length; $i++>>
<<link $temprooms[$i]>>
<<set $room01 to $temprooms[$i]>>
<<goto "Rooms">>
<</link>>

<</for>>

The problem is that $room01 literally returns "$room01" as a result and not a name when you go back to the Rooms passage. But all the << link $temprooms[$i] >> links do give the right name while still in the AssignRooms passage.

I tried changing up the code to this:
Room #1: $room01

<<for $i to 0; $i lt $temprooms.length; $i++>>
<<set $room01 to $temprooms[$i]>>
<<link $room01>>
<<goto "Rooms">>
<</link>>
<</for>>

and now no matter who I select, $room01 will always return "Teleri" as the result - always the last name in the array. But the << link >> macro still returns the right name. Is there a way to fix this?

Second question: Once a person is assigned to Room01 for example, I would like their name removed from the array so that they don't get selected for $Room02 or $Room03 anymore. Is that possible?

Thank you! This is for Twine 2 and Sugarcube 2

Viewing all articles
Browse latest Browse all 1844

Trending Articles