Global 'back' feature?

OurJud
02 Dec 2015, 07:53
I'm using 'back' as a command for players to retrace their steps, but finding it a pain having to add the command to each location.

Is there any way I could add a global 'Back' command? Something along the lines: <if "Back" then 'PreviousLocation'>

I know that's totally bogus code, but you get the idea.

HegemonKhan
02 Dec 2015, 13:28
here's a conceptual example~explanation on how it will work:

----

player is in room (start~beginning of the game):

// player.parent = room

create~add an Attribute to the player to store this:

player.old_room = room

but we also need to create~add another Attribute as well (for~to transition~upgrade~track changing rooms as you play the game):

player.current_room = room

lastly, we need to create~add the 'changedparent' Script to the player to handle this stuff:

(see much further below, the bolded and larger font size section)

-----

player goes to and is now in room2:

// player.parent = room2

and your 2 attributes automatically get changed~shifted~transitioned through the 'changedparent' Attribute that has been added to the player (see much further below, the implementation~setup section in bold and larger font size, lol):

player.old_room = player.current_room
// player.old room = room

player.current_room = player.parent
// player.current_room = room2

and within your 'back' Command:

Pattern: goback // or whatever you want

player.parent = player.old_room // this will move (re-set) the player to be inside of the room that you saved into 'player.old_room', this would currently be: room

----

you go to and are now in room3:

// player.parent = room3

// player.old_room = player.current_room -----> player.old_room = room2
// player.current_room = player.parent -----> player.current_room = room3
// the 'goback' Command's Script of 'player.parent = player.old_room' will now move (reset) the player back to room2

----

you go to and are now in room4:

// player.parent = room4

// player.old_room = player.current_room -----> player.old_room = room3
// player.current_room = player.parent -----> player.current_room = room4
// the 'goback' Command's Script of 'player.parent = player.old_room' will now move (reset) the player back to room3

----

etc etc etc


----------------------------------------------


as for implementing ~ setting this up, though, you'd need to add these 3 Attributes to your 'player' Player Object:


'player' Player Object -> 'Attributes' Tab -> Attributes -> Add -> (see below, repeat as needed)

(Object Name: player)
Attribute Name: old_room // or whatever you want to call it instead
Attribute Type: object
Attribute Value: room // or whatever is your starting room that the player is in at the start~beginning of your game

(Object Name: player)
Attribute Name: current_room // or whatever you want to call it instead
Attribute Type: object
Attribute Value: room // or whatever is your starting room that the player is in at the start~beginning of your game

(Object Name: player)
Attribute Name: changedparent // do NOT rename this, it MUST be: changedparent
Attribute Type: script
Attribute Value: (see below)

player.old_room = player.current_room
player.current_room = player.parent


and for your 'back' Command:


Pattern: goback // or whatever you want
Script: player.parent = player.old_room


----------------------------------------------------------------


P.S.

obviously the 'goback' Command has to be a global Command

------------------------------

p.s.s.

to do this through the GUI~Editor's Scripts (in case you forgot):

run as script -> add new script -> variables -> 'set a variable or attribute' Script -> (see below, for examples)

set variable player.old_room = [EXPRESSION] player.current_room
// this is the same as (in code): player.old_room = player.current_room (see the player's 'changedparent' Script above)

set variable player.current_room = [EXPRESSION] player.parent
// this is the same as (in code): player.current_room = player.parent (see the player's 'changedparent' Script above)

set variable player.parent = [EXPRESSION] player.old_room
// this is the same as (in code): player.parent = player.old_room (see the 'goback' Command's Scripts above)

-------------------------

p.s.s.s.s.

this is quite advanced logic and implementation, so please ask if you got any questions, don't understand something, and~or if need help with anything!

OurJud
02 Dec 2015, 21:58
HegemonKhan wrote:
... so please ask if you got any questions, don't understand something, and~or if need help with anything!

I don't understand any of it, and I'll be able to follow it even less.

Judging by the length of your post, it sounds like quadruple the work, when compared to adding a simple 'back' command rule to each location.

I thought I would just be able to create a global command called 'back' and use some script for it that would send the player back to previous location.

Although thinking about it, this wouldn't work globally, would it, as the game wouldn't know which way to send the player.

i.e

You are in room 1. Room 2 is north.
> n

You are in room 2. Room 3 is north.
> n

You are in room 3. Room 4 is north.
> back

You are in room 2. Room 3 is north.
> back

Now, at this second back, how does the game know if you mean back to Room 1 or back to Room 3 ?

It other words, if you are between rooms, it won't know which way to go when the player types 'back'. For that reason I think my way is the only solution.

Unless anyone has got any better ideas?

Anonynn
03 Dec 2015, 02:57
You could make it a global command --- it's really only two steps. I'm not sure I'll say it with 100% correctness but try...

Verbs actually come from the same family as commands --- except that verbs are for individual objects and commands are for global.

1. So create a Command in your game.object

2. Make it a "Command Pattern" and below that, write back;go back

3. Give it the name previous_room

4. Add this script to the Command...

if (GetBoolean(player.parent, "alreadyprevious")) {
msg ("You've gone back as far as you can go.")
}
else {
if (HasScript(player.parent, "previous_room")) {
do (player.parent, "previous_room")
}
else {
msg ("You can't go back right now.")
}
player.parent.alreadyprevious = true
}

5. Go to your first room, Attributes

6. Create a new attribute, previous_room and make it a script.

From here, I think you need to find some help or make sure I'm helping you correctly. I'm going off a global command that Pixie helped with me. So the steps might be correct but the command script might be completely wrong. The script for returning to a previous room is beyond me as well. BUT if you can set it up correctly, any of the room attributes that carry the "previous_room" attribute should send the player back. Hope this helps!

OurJud
03 Dec 2015, 05:50
Thank you, Neonayon.

I really didn't want to use compass directions for this game, which is why I needed this back feature, but it's too much of a headache so I've reached a compromise. I'm using compass points, without spelling out to the player where they all lead. It's up to them to try the various exits and see where it takes them.

It sounds unplayable, but I hope I can pull it off with the way I describe the locations. At least back isn't a problem now as I can just apply the 'exit in opposite direction' rule when I set up an exit.

The Pixie
03 Dec 2015, 08:50
Having had a think about this, the best way is to use a change script to capture the last room, and a global command. Advanced Quest, but hardly any coding.

Go to the attributes tab of the player. In the lower box, look for an attribute called "changedparent" (it will be in grey; click on "Name" to arrange them alphabetically to find it).

Click on it, so the script appears below, and then click on "Make Editable Copy", and then click on the Code view icon, to the right of that. You should see this:
if (game.pov = this) {
if (IsDefined("oldvalue")) {
OnEnterRoom (oldvalue)
}
else {
OnEnterRoom (null)
}
if (game.gridmap) {
MergePOVCoordinates
}
}

Change it to this (fourth line has been inserted):
if (game.pov = this) {
if (IsDefined("oldvalue")) {
OnEnterRoom (oldvalue)
player.previousroom = oldvalue
}
else {
OnEnterRoom (null)
}
if (game.gridmap) {
MergePOVCoordinates
}
}

Then you need a command. Give it "back" as a pattern. Paste in this code:
if (player.previousroom = null) {
msg ("You have not been anywhere yet, so how can you go back?")
}
else {
msg ("You retrace your steps...")
player.parent = player.previousroom
}

OurJud
03 Dec 2015, 09:18
Thank you, TP :)

jaynabonne
03 Dec 2015, 19:51
Just to echo a thought you had, OJ, I had once considered a "back" feature like that and ran into exactly the conundrum you did: what do multiple "backs" mean? Is it like the "back" button in a web browser, where it has a history and you continue undoing your steps? Or does "back" followed by "back" leave you where you were? Technical issues aside, that sort of confusing ambiguity led me to abandon it. I'm curious to see how it works for you when you give it a go. :)

HegemonKhan
03 Dec 2015, 21:17
I didn't even think of the concept of how far back, nice point Jay!

I guess you could use an Objectlist to store previous rooms... is there any limit on the number of items an Objectlist can store, aside from any hardware limitations? It would actually not take much to convert my code for using an Objectlist storing multiple previous rooms and a code system for this 'back' Command ability.

actually, you'd want to use a Dictionary instead of a list, as this would more easily be crafted for the person to know their choices of rooms to go to.

XanMag
03 Dec 2015, 22:00
This may sound dumb, but can you modify the built-in 'undo' command? Name it 'back; back to' and then do something like 'If expression = #text#, 'then' nothing happens, 'else' 'if' expression = room1, 'else if' expression = room2, 'else if' expression = room3, 'else if' expression = room 4, etc.

Would that work? I'm just talking out of my ass, but that would be my first attempt if I were OJ. It likely won't work for reasons that I do not understand, but... there are my two cents.

george
04 Dec 2015, 02:41
Like Jay mentioned, 'back' as in 'go back' is ambiguous. But, 'back' as in 'out' is not; in other words, define an 'out' to a point that you define as 'out' -- usually the street if you have inside/outside rooms, or a central location if you have only inside rooms. Then make a command 'out' which leads out and set up your exits appropriately. Then if you wish 'back' can be a simple alias to the room you were last in.

OurJud
04 Dec 2015, 02:51
Just for the record, before anyone goes to any more trouble. I have reverted to the traditional compass movement for now, so 'back' is used in the normal way, i.e. retracing the path "n, e, e, s" would be "n, w, w, s" (providing the return exits are added, of course)

HegemonKhan
04 Dec 2015, 03:38
this should work (HK crosses his fingers), just follow my instructions:

(I'm *NOT* doing the code for an Objectlist as it's much more complex being harder for me to give instructions and for you to follow it, so you'll only be able to go back to the immediate previous room with this code, if you really want to be able to select from multiple previous rooms, then let me know, but it'll be harder for me to guide you through it and for you to follow it as it involves the use of List and Dictionary Attributes)

you need to create~add these 3 Attributes:

'player' Player Object -> 'Attributes' Tab -> Attributes -> Add -> (see below, repeat as needed)

(Object Name: player)
Attribute Name: old_room // or whatever you want to call it instead
Attribute Type: object
Attribute Value: room // or whatever is your starting room that the player is in at the start~beginning of your game

(Object Name: player)
Attribute Name: current_room // or whatever you want to call it instead
Attribute Type: object
Attribute Value: room // or whatever is your starting room that the player is in at the start~beginning of your game

(Object Name: player)
Attribute Name: changedparent // do NOT rename this, it MUST be: changedparent
Attribute Type: script
Attribute Value: (see below)

(change my use of 'old_room' if you called it something else, to that something else)
(change my use of 'current_room' if you called it something else, to that something else)

add new script -> variables -> 'set a variable or attribute' Script -> (see below)

set variable player.old_room = [EXPRESSION] player.current_room

add new script -> variables -> 'set a variable or attribute' Script -> (see below)

set variable player.current_room = [EXPRESSION] player.parent


and for your 'back' Command:

Command Name: whatever you want to call it
Command Pattern: back // or: goback, or: whatever you want
Command Script: (see below)

(change my use of 'old_room' if you called it something else, to that something else)

add new script -> variables -> 'set a variable or attribute' Script -> (see below)

set variable player.parent = [EXPRESSION] player.old_room

---------

even if you don't understand how it works, it should (HK crosses his fingers that there's no errors or logic oversights on his part) work for you! :D

it'll work for any type of situation, for examples:

your travel: room -> room1 -> room2
the back command moves you back to 'room1'

your travel: room -> room99 -> room5
the back command moves you back to 'room99'

and if you were to use the back command again now being in room99 from the above example, you'd go back to 'room5'

and if you were to use the back command again now being in room5 from the above example, you'd go back to 'room99'

etc etc etc

----------------

P.S.

hopefully, you understand that if you're using a different name for your Player Object than the default name of 'player', then you got to change my use of 'player' in all of the code lines above to the name that you're using for it.

OurJud
04 Dec 2015, 18:40
HegemonKhan wrote:this should work (HK crosses his fingers), just follow my instructions:

Thanks, HK, but I'm guessing you didn't read my last post where I say I've scrapped the idea of using 'back' ?

HegemonKhan
04 Dec 2015, 20:00
it's there, if you (or if anyone else) ever want to come back and use it, hehe