How to make player travel alternate versions of the same rooms with an item?

I'm making a game that requires the player to use an item to freely switch between two versions of the same rooms. I'm having trouble with how to code it to do it for the room the player is currently in rather than sending them back to the start room. Any code anyone knows of to help, cause I maybe over thinking it.


I've a game in the works, similar idea...
Try this idea...
(Player has a spoon, without the spoon he see room 1 description, with it, he sees room1a...)
Could do this in the "on room enter" code block, or room description.
(On enter)
(not real code...)
if player.spoon=true
msg(This room description)
else
msg(The non-spoon description)

almost the same for room description block
(if player.spoon=true:This is what you see while holding the spoon)
(if player.spoon=false:This is what the room looks like otherwise)

The other way to do it would be to have a second room "room 1a" that is the alternate room description.
But, this will increase the number of rooms (not a real problem), but, when you drop something which room would it be in???
One idea could be move objects from room 1 (not spoon view) to room 1a (spoon view), then move them back after the player leaves the room.


If the player uses the spoon, then the room changes, just call ShowRoomDescription () to get the new description of the room.
Or, move the player to room 1a.
(or back)


(filler for getting my edited post, updated/posted)


the first trick: you got to store/save the previous room, so you can restore/load (go back to) the previous room

the second (big) trick: you also need to store/save the current room as well, so you can transfer from the current room address to the previous room address, which maintains/upkeeps/stores/saves the correct previous room, so you can go back to it

location is actually determined by the built-in 'parent' Object reference/pointer Attribute: https://docs.textadventures.co.uk/quest/attributes/parent.html

(IMPORTANT: there may be an issue with over-writing the 'changedparent' Script Attribute, as I can't remember if this will wipe out the built-in features of the 'parent' functionality... if so... we'd need to copy and paste those built-in features/code into our over-written 'changedparent' Script Attribute, otherwise, there's other means around this issue as well, such as setting up your own Attributes, so you're not messing with the 'parent' Object reference/pointer Attribute and its built-in features, and/or doing it manually/individually and/or globally/game-wide when you change locations... I can't find the "on entering room every time"... don't know if this got removed or I just can't find it in the doc, meh)

current location: player.parent

player.parent = room // 'player' Player Object is within the 'room' Room Object
player.parent = room2 // 'player' Player Object is now within the 'room2' Room Object

there's also the built-in helper Function 'MoveObject (MOVING_OBJECT, DESTINATION_OBJECT)' that does the same thing (its built-in code, does/uses the 'parent' Object reference/pointer Attribute)

MoveObject (player, room)
MoveObject (player, room2)

the 'changed' Script Attribute is a special Script Attribute, which is activated whenever its specified Attribute's Value changes

here's an example below:

<object name="room">

  <inherit name="editor_room" />

</object>

<object name="room2">

  <inherit name="editor_room" />

</object>

<object name="room3">

  <inherit name="editor_room" />

</object>

<object name="room4">

  <inherit name="editor_room" />

</object>

<object name="room5">

  <inherit name="editor_room" />

</object>

<object name="alternate_room">

  <inherit name="editor_room" />

</object>

<object name="player">

  <inherit name="editor_object" />
  <inherit name="editor_player" />

  <attr name="parent" type="object">room</attr>

  <attr name="previous_location" type="object">room</attr>
  <attr name="current_location" type="object">room</attr>

  <attr name="changedparent" type="script">
    
    player.previous_location = player.current_location // this code line has to be done first while you still have the 'player.current_location' value/address, before you replace the 'player.current_location' value/address with the new current location that you're now at, in the next code line below:

    player.current_location = player.parent

  </attr>

</object>

<object name="warp_stone">

  <attr name="parent" type="object">room</attr>

  <inherit name="editor_object" />

  <attr name="take" type="boolean">true</attr>
  <attr name="drop" type="boolean">true</attr>

  <attr name="mark_location" type="object">room</attr>

  <attr name="mark" type="script">

    warp_stone.mark_location = player.parent

    msg ("You set the 'mark' location as: " + GetDisplayAlias (player.parent))

  </attr>

  <attr name="recall" type="script">

    player.parent = warp_stone.mark_location

    msg ("You warp to your 'marked' location: " + GetDisplayAlias (player.parent))

  </attr>

  <attr name="previous" type="script">

    player.parent = player.previous_location

    msg ("You warp back to your previous location: " + GetDisplayAlias (player.parent))

  </attr>

  <attr name="alternate" type="script">

    player.parent = alternate_room

    msg ("You warp to an alternate dimension of " + GetDisplayAlias (room) + ", known as: " + GetDisplayAlias (alternate_room))

  </attr>

  <attr name="peek" type="script">

    msg ("Your set marked location currently is: " + GetDisplayAlias (warp_stone.mark_location))

  </attr>

  <displayverbs type="stringlist">

    <value>take</value>
    <value>drop</value>

    <value>mark</value>
    <value>recall</value>
    <value>previous</value>
    <value>alternate</value>
    <value>peek</value>

  </displayverbs>

  <inventoryverbs type="stringlist">

    <value>take</value>
    <value>drop</value>

    <value>mark</value>
    <value>recall</value>
    <value>previous</value>
    <value>alternate</value>
    <value>peek</value>

  </inventoryverbs>

</object>

<verb>

  <property>mark</property>
  <pattern>mark</pattern>

  <defaultexpression>You can't set the mark location to here!</defaultexpression>

</verb>

<verb>

  <property>recall</property>
  <pattern>recall</pattern>

  <defaultexpression>You can't set the recall location to here!</defaultexpression>

</verb>

<verb>

  <property>previous</property>
  <pattern>previous</pattern>

  <defaultexpression>You can't set the previous location to here!</defaultexpression>

</verb>

<verb>

  <property>alternate</property>
  <pattern>alternate</pattern>

  <defaultexpression>You can't set the alternate location to here!</defaultexpression>

</verb>

<verb>

  <property>peek</property>
  <pattern>peek</pattern>

  <defaultexpression>You can't see-view-display your currently set marked location</defaultexpression>

</verb>

demonstration of how having the two Object reference/pointer Attributes work:

original/starting/initial location of the 'player' Player Object): room

initial setting of the old location: player.previous_location = room
initial setting of the old location: room

initial setting of the current location: player.current_location = room
initial setting of the current location: room

old location: player.previous_location = room
old location: room

current location: player.current_location = room
current location: room

you move to room2:

old location: player.previous_location = player.current_location
old location: room

current location: player.current_location = player.parent
current location: room2

you move to room3:

old location: player.previous_location = player.current_location
old location: room2

current location: player.current_location = player.parent
current location: room3

you move to room4:

old location: player.previous_location = player.current_location
old location: room3

current location: player.current_location = player.parent
current location: room4

you move to room5:

old location: player.previous_location = player.current_location
old location: room4

current location: player.current_location = player.parent
current location: room5

you move to room:

old location: player.previous_location = player.current_location
old location: room5

current location: player.current_location = player.parent
current location: room

you move to room3:

old location: player.previous_location = player.current_location
old location: room

current location: player.current_location = player.parent
current location: room3

you move to room5:

old location: player.previous_location = player.current_location
old location: room3

current location: player.current_location = player.parent
current location: room5

you move to room2:

old location: player.previous_location = player.current_location
old location: room5

current location: player.current_location = player.parent
current location: room2

you move to room4:

old location: player.previous_location = player.current_location
old location: room2

current location: player.current_location = player.parent
current location: room4


you can do some cool stuff with the built-in 'parent' (or any) Object reference/pointer Attribute(s)

for example, having a 'npc' (and/or a team/party of characters) follow the 'player' (your main character):

npc.parent = player.parent
// npc location = player location

// example:

player.parent = room
npc.parent = player.parent
// npc.parent = room

player.parent = room2
npc.parent = player.parent
// npc.parent = room2

player.parent = room99
npc.parent = player.parent
// npc.parent = room99

(just quick/brief code... not fully finished... not showing how to add/remove followers/team-members from your lists)

<object name="player">

  <attr name="changedparent" type="script">

    foreach (follower_object_variable, player.follower_objectlist) {
      follower_object_variable.parent = player.parent
    }

    foreach (team_member_object_variable, player.team_objectlist) {
      team_member_object_variable.parent = player.parent
    }

  </attr>

  <follower_objectlist type="objectlist">

    <value>npc</value>

  </follower_objectlist>

  <team_objectlist type="objectlist">

    <value>team_member_1</value>
    <value>team_member_2</value>
    <value>team_member_3</value>
    <value>team_member_4</value>
    <value>team_member_5</value>

  </team_objectlist>

</object>

<object name="npc">
</object>

<object name="team_member_1">
</object>

<object name="team_member_2">
</object>

<object name="team_member_3">
</object>

<object name="team_member_4">
</object>

<object name="team_member_5">
</object>

Time to pull out my teleport code.

player.parent = player.oldroom
MoveObject (player, Teleport Room)

And to go back you just do this!

player.oldroom = player.parent

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums