Teleporting the player

BenM
Gentlemen:

Still struggling with the learning phase. I've created a house with several rooms on the 1st floor (Main Hall, Living Room, Study), an Upper Hallway and a Master Bedroom. Outside (basically on the 1st floor) there is a flowered path and a gravel path. I've tested the exits and there is no problem getting from one room to another and back.

On the flowered path I've set a flower. You can either pick or take the flower, in which case it becomes part of the player's inventory. Both those verbs work as planned.

I created another verb: "grab," for which I've written a simple script. If the player enters "grab flower," the thing disintegrates and the player is "teleported" to another location. Herein lies the question. If, in the script, I teleport the player to any other 1st floor location (i.e. Main Hall, Living Room, Study or Gravel Path) there's no problem. However, if I script it so that the player is teleported to a 2nd-floor room (upper hallway or master bedroom) I get the following message when I play the game.


> grab flower
You grad the flower in your fist, but it disintergrates and disappears in a puff of smoke. Oops, something feels strange. Suddenly you're no longer on the flower path.
Error running script: Error evaluating expression 'DictionaryItem(coordinates, coordinate)': The given key was not present in the dictionary.
Error running script: Error evaluating expression 'DictionaryItem(coordinates, coordinate)': The given key was not present in the dictionary.
Error running script: Error evaluating expression 'DictionaryItem(coordinates, coordinate)': The given key was not present in the dictionary.

You are in a masterbedroom.
You can go west.

NOTE THAT THE PLAYER IS, IN FACT, TELEPORTED TO THE NEW LOCATION. BUT THERE ARE ALL THOSE ERROR MESSAGES IN THE OUTPUT.

Any idea why this might be happening?

Thanks,

-- Ben

Here's the code:

<!--Saved by Quest 5.6.5621.18142-->
<asl version="550">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="Tutorial # 2">
<gameid>37ae8ab6-cc21-4a77-b9f7-1ab1c94618e7</gameid>
<version>1.0</version>
<firstpublished>2015</firstpublished>
<gridmap />
</game>
<object name="main hall">
<inherit name="editor_room" />
<attr name="grid_label">Main Hall</attr>
<attr name="grid_width" type="int">2</attr>
<attr name="grid_length" type="int">2</attr>
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
</object>
<exit alias="west" to="livingroom">
<inherit name="westdirection" />
</exit>
<exit alias="up" to="upperhall">
<inherit name="updirection" />
</exit>
</object>
<object name="livingroom">
<inherit name="editor_room" />
<attr name="grid_label">Living Rm</attr>
<attr name="grid_width" type="int">2</attr>
<attr name="grid_length" type="int">2</attr>
<exit alias="east" to="main hall">
<inherit name="eastdirection" />
</exit>
<exit alias="west" to="study">
<inherit name="westdirection" />
</exit>
</object>
<object name="study">
<inherit name="editor_room" />
<attr name="grid_label">Study</attr>
<attr name="grid_width" type="int">2</attr>
<attr name="grid_length" type="int">2</attr>
<exit alias="east" to="livingroom">
<inherit name="eastdirection" />
</exit>
<exit alias="north" to="flowered path">
<inherit name="northdirection" />
</exit>
<object name="desk">
<inherit name="editor_object" />
<inherit name="container_open" />
<look>An old roll-top desk</look>
<feature_container />
<open type="boolean">false</open>
<close type="boolean">false</close>
<isopen />
<transparent />
<hidechildren />
<listchildren />
<object name="drawer">
<inherit name="editor_object" />
<inherit name="container_open" />
<feature_container />
<hidechildren />
<listchildren />
<isopen type="boolean">false</isopen>
<transparent type="boolean">false</transparent>
<object name="knife">
<inherit name="editor_object" />
<look>A lethal-looking weapon if ever you saw one.</look>
<feature_usegive />
<take />
<ondrop type="script">
MoveObject (knife, drawer)
msg ("You put it back in the drawer")
</ondrop>
</object>
</object>
</object>
</object>
<object name="flowered path">
<inherit name="editor_room" />
<attr name="grid_width" type="int">2</attr>
<attr name="grid_length" type="int">2</attr>
<attr name="grid_label">Flowered Path</attr>
<descprefix>You are on </descprefix>
<exit alias="south" to="study">
<inherit name="southdirection" />
</exit>
<exit alias="northeast" to="gravelpath">
<inherit name="northeastdirection" />
</exit>
<object name="Flower">
<inherit name="editor_object" />
<take />
<usedefaultprefix />
<prefix type="string"></prefix>
<pick type="script">
MoveObject (Flower, player)
msg ("Gently you pluck the flower from its stem and place it in your buttonhole;")
</pick>
<grab type="script">
msg ("You grad the flower in your fist, but it disintergrates and disappears in a puff of smoke. Oops, something feels strange. Suddenly you're no longer on the flower path.")
MoveObject (player, gravelpath)
MakeObjectInvisible (Flower)
</grab>
</object>
</object>
<object name="gravelpath">
<inherit name="editor_room" />
<attr name="grid_label">Gravel Path</attr>
<attr name="grid_width" type="int">2</attr>
<attr name="grid_length" type="int">2</attr>
<descprefix>You are on</descprefix>
<usedefaultprefix />
<prefix>the</prefix>
<exit alias="southwest" to="flowered path">
<inherit name="southwestdirection" />
</exit>
</object>
<object name="upperhall">
<inherit name="editor_room" />
<attr name="grid_width" type="int">2</attr>
<attr name="grid_length" type="int">2</attr>
<attr name="grid_label">Upper Hallway</attr>
<exit alias="down" to="main hall">
<inherit name="downdirection" />
</exit>
<exit alias="east" to="masterbedroom">
<inherit name="eastdirection" />
</exit>
</object>
<object name="masterbedroom">
<inherit name="editor_room" />
<attr name="grid_width" type="int">2</attr>
<attr name="grid_length" type="int">2</attr>
<attr name="grid_label">Master Bedroom</attr>
<exit alias="west" to="upperhall">
<inherit name="westdirection" />
</exit>
</object>
<verb>
<property>pick</property>
<pattern>pick</pattern>
<defaultexpression>"You can't pick " + object.article + "."</defaultexpression>
</verb>
<verb>
<property>grab</property>
<pattern>grab</pattern>
<defaultexpression>"You can't grab " + object.article + "."</defaultexpression>
</verb>
</asl>

HegemonKhan
Unforutnately, I think it due to using the map~grid feature, as I don't think the map~grid can handle teleportation (non-Exit travel, and also, it can't handle~draw for different vertical levels of rooms), as it's built upon 'room-exit-room' connections (so its quite limited especially in the drawing of the map itself). The map~grid feature isn't 3D, it can't handle 'upstairs' and 'downstairs', it only handles rooms at the same vertical level. If you want the map~grid feature to map different vertical levels, you got to remove the map, and then turn it back on, allowing it to map the current vertical level you're on, doing this over and over again, as you switch vertical levels.

You're going to have to turn off the map~grid as a Script before you do the teleport-travel-moving Script, and then turn back on the map as the final Script.

--------

I've actually never yet worked with the map~grid feature yet, so for actual help, you're going to need someone else, as I can't help you with using the map~grid feature, as I've never used it myself, and it is still a bit too advanced for me too, laughs.

-------

Jay has some really advanced various mapping libraries that you might want to take a look at, read, or use, but they're quite advanced stuff...

look in the 'libraries and code samples' board~forum here... if you still can't find the map~grid threads by jay, I can find them for you.

XanMag
"Gently you pluck the flower from its stem and place it in your buttonhole;"

WHERE exactly did you place the flower?!?

lol

XanMag
So... I got caught up on this... How do you run a random script? I can run a random expression message like this...

n = GetRandomInt (0, ListCount (Teleport Button.teleport) - 1)
msg ("You get a weird feeling in your gut and... " + StringListItem(Teleport Button.teleport, n))


The message to be printed would be called randomly from my teleport attribute. But that obviously is NOT what I want. I tried putting MoveObject(player, XYZ Room) in the string list put, well, that is exactly what printed - a message that said "You get a weird feeling in your gut and... MoveObject(player, XYZ Room)" lol

I was intending on trying to help the OP by making a sample game and testing it out, but I wanted to teleport the player randomly to a room using the MoveObject (player, XYZ Room) script. I'm sure I need to change the attribute type to something like Script Dictionary and draw from a random script but that pulls up a Key and Value box... which I have no clue how to handle.

In short, I want to run a random script, not a simple print message. I'm sure it's an easy fix, but I don't know how to do it. Help!

BenM
Mr. Khan ... the idea of turning off the map grip prior to "teleporting" sounds great. But I have no idea how to do it. Can you give me any instructions? I checked the drop-down script menus, but I didn't see anything that would allow me to turn off/on the map grid.

Mr. XanMag ... check it again. I did say "...in your buttonhole." Although, if I were to actually make a game of this -- an adult game -- your thought might be a good one! Also ... the issue of a random message/string/etc. is, as you may have guessed from my earlier postings, far beyond what I can do at the moment. I think you're at level 5 whereas I'm struggling to get to level 1.

HegemonKhan
@ XanMag:

a "simple" (not really) way to use the 'MoveObject' Script to do your randomization:

create an String~Object List Attribute in your 'game' Game Object, and add all of the rooms that you want to teleport to, into it (or you can leave it without any rooms, and use events~scripts to add rooms to teleport to, as you progress~advance through the game). for example (a bit fancy using scripting instead of the GUI~EDitor 'adding attributes' method ~ as if you had lots of rooms, you want to use scripting to do the work, not your own manual work for each Object, lol):

<game name="xxx">
<start type="script">
game.teleport_all_rooms_list = NewObjectList ()
foreach (object_variable, AllObjects ()) {
if (HasString (object_variable, "type_of_object") and object_variable.type_of_object = "room") {
list add (game.teleport_all_rooms_list, object_variable)
}
}
</start>
</game>

<object name="dungeon_1">
<attr name="type_of_object" type="string">room</attr>
</object>

<object name="table_1">
<attr name="type_of_object" type="string">table</attr>
</object>


then for your 'MoveObject' Script's randomization:

MoveObject (player, ObjectListItem (game.teleport_all_rooms_list, GetRandomInt (0, ListCount (game.teleport_all_rooms_list) - 1))

if this doesn't work, let me know, as I prefer using String Lists, which can be done for this, and thus scripting may have some errors in trying to use 'Objectlist' Attributes, as I'm a bit green with them (hardly ever use them, as I always get confused and do the scripting wrong for them, lol).

-----------

@BenM:

I'll have to look up the scripting~command needed for it in the quest doc site (give me a few moments).

and, a simple way to do randomized local responses in your 'msg' Script:

is to use the 'random' Text Processor Command:

http://docs.textadventures.co.uk/quest/ ... essor.html

{random:text 1:text 2:text 3}
Choose text at random

--

run as script -> add new script -> output -> 'print a message' Script -> (see below, for an example)

print [expression] "{random: Hi: Hello: Howdy: Kunichiwa: Hola}, how are you? My name is {random: HegemonKhan: Hegemon: Hege: Khan: HK}."

the entire message (if you don't use any '+ VARIABLES +' ) must be within the double quotes. And your 'random text processor commands' must be withing the curly brackets.

----

also, take a look at all the other Text Processor Commands too, they're hopefully understandable, and lets to you a lot of cool stuff pretty easily, until you learn to work with the Expressions themselves better, using text+VARIABLES, and the 'if' Scripts well too.

XanMag
For any room you don't want automapped, go to the Scripts tab of the room, go to 'Before entering the room', and click the code view icon (the second from the right, looks like a piece of paper). You'll get a blank input box. Type

CODE: SELECT ALL
this.grid_render = False

I had a similar question long ago. Not sure if George's response here to turning off the map would work for you or not. Maybe use this.grid_render = True on the after entering room script would get rid of your error message? I haven't tried it of course, so it might goof up your map drawing.

HegemonKhan
@BenM:

two scripts, one is for removing~hiding the map~grid, and the other for showing~creating the map grid, so like this:

hide~remove grid~map Script
move player to the new vertical level room Script
show~create grid~map Script

------

I don't think these are it (I've never worked with the map~grid, so this stuff is a bit alien to me, lol), but maybe...

run as script -> add new script -> scripts -> 'call function' Script -> (see below)

Call function: (see links below for what you type in here)
With parameters (add) box: (don't add in any Parameters, leave this box empty)

http://docs.textadventures.co.uk/quest/ ... layer.html
http://docs.textadventures.co.uk/quest/ ... layer.html

otherwise, try these:

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

set variable game.gridmap = [expression] false
set variable game.gridmap = [expression] true

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

here's a link on a bit of the map~grid usage, also:

http://blog.textadventures.co.uk/2012/0 ... quest-5-3/

----------

P.S.

XanMag (via Sgreig ~ George, a moderator, and whom is a good coder, here) 's use of the 'Object_name.grid_render' Boolean Attribute is probably more on target then my flat out guesswork, lol.

Ask any of the moderators, as they understand the map~grid stuff well.

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

Support

Forums