Move player to...

wdele
23 May 2013, 15:29
Hello,

I would like to make a command 'goto' and when the player types in the name of a room, the player moves to that room.

But how?

Thanks,
William

Liam315
23 May 2013, 15:46
The go to command is built in by default. You just need to make sure set the alias of your exit to whatever the name of the room is.

wdele
23 May 2013, 15:50
And what's the command exactly? If I try goto [object] or go to [object] Quest responds that it doesn't understand my command?

jaynabonne
23 May 2013, 17:13
This one is a little tricky, since you want to goto something that is not visible where you are. So using the standard command with #exit# will not work. I think you would need to create your own "goto" command (or whatever you'd like to call it), with a pattern like "goto #text#", and then find the object based on the text passed as a room alias (as opposed to the internal room name). Or, if you don't want them to jump to just *any* room but only specific ones, you could have a static list of "goto-able" rooms, with the target rooms based on the input key (sounds a bit like an "object dictionary" ;) ).

One question: is this something the player will use or is this just for you to use for debugging purposes?

wdele
23 May 2013, 17:30
Hey jaynabonne,

This is just for debugging the game.

But, how can I make such a command? I have tried already, but things didn't work out right.

Thanks!

jaynabonne
23 May 2013, 17:36
Add this to your source file. If you're not comfortable with Code View, let me know. :)

  <command name="GotoRoom">
<pattern>goto #text#</pattern>
<script>
player.parent = GetObject(text)
</script>
</command>


Use it with : goto roomname

You have to type the internal name for the room (not the alias).

wdele
23 May 2013, 17:45
Where should I put this code? 'cause I use the online version of Quest

jaynabonne
23 May 2013, 18:17
So then:

1) Add a new command
2) for the command pattern, put

goto #text#

3) for name, put GotoRoom (or whatever you like)
4) For the script, select "Move object". Make it :

Move object (object) (player) to (expression) GetObject(text)

(I hope that makes sense.)

GotoRoom.jpg

wdele
24 May 2013, 06:09
Thanks! That worked for me.

But:

Can I use the alias of a room and,
I get a huge error when I type in the wrong name...

Is there any way to fix this?

Thanks

Pertex
24 May 2013, 06:31
You can do something like this:
goto.jpg


The problem is, that this will work with a normal object like an apple, too (goto apple). I think there is no internal way to identify if the object is an object or a room

Sora574
24 May 2013, 08:20
You could always make it a bit (err... a lot) more advanced.
Just keep in mind that, as Pertex pointed out, there's no way to check if an object is a room right now, so you might get thrown into an object.

In the command, switch the script to code view and paste this into it:
game.resolvedaliasesforobjects = null
objects = NewStringList()
alts = NewObjectDictionary()
foreach (obj, AllObjects()) {
if (obj.alias = null or obj.alias = "") {
if (GetKeywordsMatchStrength (text, obj.name) > 0) {
list add (objects, obj.name)
}
}
else {
if (not obj.alt = null) {
foreach (alt, obj.alt) {
if (GetKeywordsMatchStrength (text, alt) > 0) {
list add (objects, alt)
dictionary add (alts, alt, obj)
firstalt = alt
}
}
}
if (GetKeywordsMatchStrength (text, obj.alias) > 0) {
list add (objects, obj.alias)
dictionary add (alts, obj.alias, obj)
firstalt = obj.alias
}
}
}
game.resolvedaliasesforobjects = alts
if (ListCount(objects) > 0) {
if (ListCount(objects) > 1) {
ShowMenu ("Which object did you mean?", objects, true) {
foreach (alt, game.resolvedaliasesforobjects) {
if (alt = result) {
result = game.resolvedaliasesforobjects[alt]
result = result.name
}
}
MoveObject (game.pov, GetObject(result))
}
}
else {
if (ListCount(alts) = 1) {
object = alts[firstalt]
}
else {
object = objects[0]
object = GetObject(object)
}
MoveObject (game.pov, object)
}
}
else {
msg ("I don't know where that is.")
}

Basically what this does is:
[list=a][*]Checks for every object, then checks for their aliases and anything in their 'alt' list[/*:m]
[*]If the player typed something close to any of the names/aliases/alts, then it adds that object to a list[/*:m]
[*]If there's only one object in the list at the end, the player is sent to that object. If there are multiple objects in the list, a menu is displayed[/*:m][/list:o]

P.S. Also keep in mind that if any objects have the same alias or alt as another object, the search will fail. There's probably a way around that, but I couldn't find it. Sorry!

HegemonKhan
24 May 2013, 11:49
You could add a flag~boolean to check for, to distinguish between a room and a non-room

for example, using rooms and true.

for all of your rooms, just add a boolean "room_type" = true

then in pertex' code, you just need the IF conditional: if (object.room_type=true) {

if you got a lot of rooms, then you'll want to make an object type, and add the boolean to that instead, then make a tab for being able to quickly apply your object type to your room objects (or maybe someone can find where the tab is for selecting the room vs non-room vs room+non-room, and add in the boolean directly as apart of it, for the room type selection).

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

if you need help with doing this, anyone of us can help you with it. I'm just not able to help you right now, as I got to get to school soon, lol.

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

P.S.

awesome(ly useful) code Sora, hehe :D

Pertex
24 May 2013, 12:58
Would it be useful to add a combobox in Quest, where you can set the type of the object , something like 'room', 'item', 'character' or 'exit' ?

psymann
24 May 2013, 14:09
wdele wrote:
I get a huge error when I type in the wrong name...

Is there any way to fix this?


If you're only using the command for debugging - ie it's only going to be used by you, and not by the player in the actual game - then the simplest option might just be to print out a list of your Rooms on a piece of paper, and then just type carefully ;-)

psy

Sora574
24 May 2013, 14:12
Pertex wrote:Would it be useful to add a combobox in Quest, where you can set the type of the object , something like 'room', 'item', 'character' or 'exit' ?

That would be nice in some cases. It would save some time parsing through every object in the game, looking for specific ones. It would probably be something to add to 'Features', though.

george
24 May 2013, 15:27
What about going at it a bit sideways. Like you could run ScopeExitsForRoom on the input. If you get an empty result then it's probably not a room? If the player typo's you could return the input in the error like,

"I can't find a room called the Ktichen."

Sora574
24 May 2013, 16:07
george wrote:What about going at it a bit sideways. Like you could run ScopeExitsForRoom on the input. If you get an empty result then it's probably not a room?

The problem with that is what if the room doesn't have an exit?
Of course, that's usually not a problem, so that might work...

george
25 May 2013, 00:54
I agree it's a hack. The previous suggestion of adding a Room type attribute is better, but it seems like there should be some automatic way to figure it out without having to add it...

Sora574
25 May 2013, 02:47
I wonder if it would be possible to do something like 'if (Inherits(object, type)) {}'

I guess that would be the same as adding a 'room' boolean to the editor_room type though.

Pertex
25 May 2013, 07:14
Sora574 wrote:I wonder if it would be possible to do something like 'if (Inherits(object, type)) {}'

I guess that would be the same as adding a 'room' boolean to the editor_room type though.


Exactly! It would just make it easier in the gui to create such things. And you would get a new function isTypeOf(object,'room') and a collection function getType('room')

Sora574
26 May 2013, 18:02
Yeah, I can see how that would be useful. Can you do it?

wdele
29 May 2013, 06:10
Thanks for the help!

Now one thing is left:

I have a 'what's your name' function in my game and only if the input is 'Dick' or 'Liam' the goto command can be used.
Is this possible?

I have already tried, but I don't seem to find a way to make a feature like this.

Thanks,
William

Pertex
29 May 2013, 06:29
Sure,
I think you are saving the players name in a variable in your 'what's your name' function. So change the If in your command in that way:

If [expression] GetObject(text) <> null and ( variable = "Liam" or variable ="Dick" )

wdele
29 May 2013, 11:21
That doesn't work...

MoveObject (game.pov, GetObject(text) <> null and ( variable = "Liam" or variable ="Dick" ))


Sora574
29 May 2013, 16:08
That's because you're trying to move the player to an object called 'GetObject(text) <> null and ( variable = "Liam" or variable ="Dick" ))'...
That's not the way MoveObject works. You need to add that to your 'if' statement instead.
Pertex wrote:If [expression] GetObject(text) <> null and ( variable = "Liam" or variable ="Dick" )

wdele
29 May 2013, 16:15
But which if?

Pertex
29 May 2013, 19:10
Please post a screenshot of your goto command. We can't help if we do not know your code