Return to previous room

Stinky
Hi all, was searching for a workaround to this without much luck. Say if you had a room named "Constant". Is it possible to have exits into Constant from multiple rooms but some how flag the one you entered Constant from so that when you exit constant you return to the correct location?

Room 1 >> Constant, Constant Exits to Room1

Room 2 >> Constant, Constant Exits to Room2

Room 3 >> Constant, Constant Exits to Room3

And so on....

New to quest, trying to apply my excel knowledge here with pitiful results lol.

jaynabonne
I can think of two ways to do this.

1) Customize the "go" command to store the old room value somewhere (e.g. "player.lastroom"). I did this in a game I was working, as I wanted to know which exit I traversed last so I could have different descriptions based on which way the player had come into the room. This will apply to all movement in the game.

2) For each exit that leads into "constant", check the box that say "Run a script (instead of moving the player automatically)" and then in your script save the current player parent before setting the new one. This will apply only to the exits you modify.

If either of these sounds acceptable, I can provide code later.

Stinky
Thanks Jaynabonne, I think the second would work better for me here as there will probably be some moving around within constant that would alter my player.lastroom.

When I was searching for a solution I ran across this:

http://forum.textadventures.co.uk/viewtopic.php?f=10&t=3063&p=20749&hilit=return+to+previous+room#p20749

And was curious if I should turn the mapping function off if I do this to avoid problems.

Or alternatively say if I wanted to be able to access constant from everywhere (which I'm not dead set on if not possible) could I add a script to save the .parent location of previous room in the "before entering room" section in the scripts tab on the constant room?

Entering constant from the main map will always be from the in exit and exiting constant to the main map will always be from the out exit so I was thinking I may be able to throw an if statement into the script that only recorded the .parent name if entering constant through an "in" exit since there would be moving around within "constant" that would overwrite the saved location upon entering constant from N,S,E,W etc..

Silver
The only way I can think of doing this is to create rooms between the exit rooms and constant which sets the flag which an if script looks for when you return to the exit room. Which is probably using a sledgehammer to crack a nut and wouldn't work at all with the map switched on. Or not without showing your magician's hand.

HegemonKhan
Using Exits is completely optional, you can move (any Object) to anywhere (any Object) that you want to, due to the structure of the quest engine using:

Parent~Child (Containment) Object Heirarchy (Object Oriented Programming):

Objects:

(outermost ~ more parent)
HK
-> pants with pockets
->-> wallet
->->-> $1
(innermost ~ more child)

'HK' is the main (Root) 'parent' of 'pants with pockets', 'wallet', and '$1'
'HK' is the direct parent of 'pants with pockets'
'HK' is the indirect parent of 'wallet' and '$1'
'pants with pockets' is the direct child of 'HK'
'pants with pockets' is the direct parent of 'wallet'
'pants with pockets' is the indirect parent of '$1'
'wallet' is the indirect child of 'HK'
'wallet' is the direct child of 'pants with pockets'
'wallet' is the direct parent of '$1'
'$1' is the indrect child of 'HK' and 'pants with pockets'
'$1' is the direct child of 'wallet'

------

other examples of such heirarchies:

C:
-> programs
->-> quest

universe
-> 'whatever' galaxy cluster
->-> Milkyway Galaxy
->->-> 'our sun' (a star in one of the tendrils of the Milky Galaxy: a star in the outer part of the Milkyway Galaxy)
->->->-> Earth planet (3rd from the sun)
->->->->-> NA (North America continent)
->->->->->-> U.S. (United States country)
->->->->->->-> CA (California state)
->->->->->->->-> HK (hehe)

------

so, instead of using Exits, all we got to do is to set the 'parent' Object Attribute of our (moving) Object to our (destination) Object, for examples:

Object_name.Attribute_name = Value_or_Expression

Attribute Types: Strings, Booleans, Objects, Integers (int), Doubles (Floats ~ Floating Points ~ decimal numbers), Scripts, String Lists, Object Lists, String Dictionaries, Object Dictionaries, Script Dictionaries, and etc

Attribute Type: Object ~ Object (Type) Attribute
(this means that your Value, does NOT have quotes on it, as the quotes would change the value~text from being an Object to being a String)

(moving Object).parent = (destination Object)

moving Object: player

player.parent = (destination Object)

------

as a creation tag:

<object name="xxx">
<attr name="parent" type="object">(Value:destination Object_name)</attr>
</object>

// for Example:

<object name="player">
</object>

<object name="wooden_sword">
<attr name="parent" type="object">player</attr>
</object>

// the above example is the same as this:

<object name="player">
<object name="wooden_sword">
</object>
</object>


-----

player.parent = HK

would move the 'player' to this spot (only the indecting~nesting level matters):

(outermost ~ more parent)
HK
-> player
-> pants with pockets
->-> wallet
->->-> $1
-> // or player can be here, it's the same spot, as its indented~nested at the same level ... hopefully you understand this... as I don't want to show examples of for every spot it can be placed in the following additional examples below, lol
(innermost ~ more child)

-------

player.parent = pants with pockets

(outermost ~ more parent)
HK
-> pants with pockets
->-> player
->-> wallet
->->-> $1
(innermost ~ more child)

-----

player.parent = wallet

(outermost ~ more parent)
HK
-> pants with pockets
->-> wallet
->->-> player
->->-> $1
(innermost ~ more child)

------

player.parent = $1

(outermost ~ more parent)
HK
-> pants with pockets
->-> wallet
->->-> $1
->->->-> player
(innermost ~ more child)

--------

so, you jsut need to save your current room~object location first, example:

'parent_old' would be a custom Object Attribute that we created~added to the 'player' Object (either via the GUI~Editor's 'player' Object's Attribute Tab, or merely as scripting, as seen below)

player.parent_old = room1

then we move to the new room:

player.parent = room2

and if we wanted to go back to the old room, we'd just 'load' that 'parent_old' Object Attribute, via:

player.parent = player.parent_old
(conceptually: player.parent = player.parent_old = room1)

-------

if you want to see movement without Exits, here's an example, my (HK's) 'explore' and 'travel' code:

(it's unrefined, but it's functional, but not sure if it'll work with the current quest version, as it's old code)

(it's probably a bit advanced for you, if you're new to coding, and to quest's coding, as it uses lists, but maybe you can at least follow along ~ understand it in concept at least, and if not, just ask me, and I can, will gladly, help explain it)

<asl version="540">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="Testing Game Stuff">
<gameid>eef801a1-4e6b-4b0a-bdbf-8f3ecfa8389c</gameid>
<version>1.0</version>
<firstpublished>2013</firstpublished>
<turns type="int">0</turns>
<statusattributes type="simplestringdictionary">turns=</statusattributes>
<start type="script">
msg ("Important Note:")
msg ("Type in: help")
</start>
</game>
<object name="homeland">
<inherit name="editor_room" />
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
</object>
</object>
<object name="grassland">
<inherit name="editor_room" />
</object>
<object name="plains">
<inherit name="editor_room" />
</object>
<object name="desert">
<inherit name="editor_room" />
</object>
<object name="tundra">
<inherit name="editor_room" />
</object>
<object name="swampland">
<inherit name="editor_room" />
</object>
<object name="mountains">
<inherit name="editor_room" />
</object>
<object name="forest">
<inherit name="editor_room" />
</object>
<object name="wasteland">
<inherit name="editor_room" />
</object>
<object name="coastland">
<inherit name="editor_room" />
</object>
<object name="hills">
<inherit name="editor_room" />
</object>
<command name="help_command">
<pattern>help</pattern>
<script>
help_function
</script>
</command>
<command name="explore_command">
<pattern>explore</pattern>
<script>
explore_function
</script>
</command>
<command name="travel_command">
<pattern>travel</pattern>
<script>
travel_function
</script>
</command>
<object name="data_object">
<inherit name="editor_object" />
<travel_string_list type="simplestringlist">homeland</travel_string_list>
<homeland_events_string_list type="simplestringlist">grassland_discovery;plains_discovery;desert_discovery;tundra_discovery;swampland_discovery;forest_discovery;mountains_discovery;hills_discovery;wasteland_discovery;coastland_discovery</homeland_events_string_list>
<homeland_events_script_dictionary type="scriptdictionary">
<item key="grassland_discovery">
list add (data_object.travel_string_list, "grassland")
msg ("You've discovered the grassland! Now, you can travel to the grassland and explore it!")
</item>
<item key="plains_discovery">
list add (data_object.travel_string_list, "plains")
msg ("You've discovered the plains! Now, you can travel to the plains and explore it!")
</item>
<item key="desert_discovery">
list add (data_object.travel_string_list, "desert")
msg ("You've discovered the desert! Now, you can travel to the desert and explore it!")
</item>
<item key="tundra_discovery">
list add (data_object.travel_string_list, "tundra")
msg ("You've discovered the tundra! Now, you can travel to the tundra and explore it!")
</item>
<item key="swampland_discovery">
list add (data_object.travel_string_list, "swampland")
msg ("You've discovered the swampland! Now, you can travel to the swampland and explore it!")
</item>
<item key="forest_discovery">
list add (data_object.travel_string_list, "forest")
msg ("You've discovered the forest! Now, you can travel to the forest and explore it!")
</item>
<item key="mountains_discovery">
list add (data_object.travel_string_list, "mountains")
msg ("You've discovered the mountains! Now, you can travel to the mountains and explore it!")
</item>
<item key="hills_discovery">
list add (data_object.travel_string_list, "hills")
msg ("You've discovered the hills! Now, you can travel to the hills and explore it!")
</item>
<item key="wasteland_discovery">
list add (data_object.travel_string_list, "wasteland")
msg ("You've discovered the wasteland! Now, you can travel to the wasteland and explore it!")
</item>
<item key="coastland_discovery">
list add (data_object.travel_string_list, "coastland")
msg ("You've discovered the coastland! Now, you can travel to the coastland and explore it!")
</item>
</homeland_events_script_dictionary>
</object>
<turnscript name="global_turnscript">
<enabled />
<script>
game.turns = game.turns + 1
</script>
</turnscript>
<function name="help_function">
msg ("Type 'explore' to explore your area.")
msg ("Type 'travel' to travel to different areas.")
</function>
<function name="explore_function"><![CDATA[
switch (game.pov.parent) {
case (homeland) {
result_1 = ListCount (data_object.homeland_events_string_list) - 1
if (result_1 >= 0) {
result_2 = StringListItem (data_object.homeland_events_string_list,GetRandomInt(0,result_1))
invoke (ScriptDictionaryItem (data_object.homeland_events_script_dictionary,result_2))
on ready {
foreach (item_x, split ("grassland_discovery;plains_discovery;desert_discovery;tundra_discovery;swampland_discovery;forest_discovery;mountains_discovery;hills_discovery;wasteland_discovery;coastland_discovery",";")) {
if (result_2 = item_x) {
list remove (data_object.homeland_events_string_list, result_2)
}
}
}
} else {
msg ("There seemingly is nothing left to explore in this area.")
}
}
}
]]></function>
<function name="travel_function">
show menu ("Where do you wish to travel?",data_object.travel_string_list,false) {
if (not game.pov.parent = GetObject (result)) {
game.pov.parent = GetObject (result)
} else {
msg ("You are already at this area.")
ask ("Try again?") {
if (result=true) {
travel_function
} else {
msg ("You realize that you need to discover a new area to travel to first, before you can travel to that place.")
}
}
}
}
</function>
</asl>

Stinky
You guys are awesome, I'll toy around with this for a while

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

Support

Forums