teleportation

Robert GAC
11 Nov 2016, 04:05

I am trying to do a game where the player can teleport to a given room. I use move object player and get this sort of thing :

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.

A lot more of it though, and then although my player is in the selected room, but my multilayer map is all screwed up and out of synch. I assume these are map errors, so is there any way of 'teleporting' players in a multi layer map?


hegemonkhan
11 Nov 2016, 04:40

the map/grid can't handle movement between rooms, unless it's adjacent room movement (using Exits), so you'll have to clear/toggle off the map/grid, teleport/warp, and then toggle it back on and/or re-initialize/build it. Also, the map/grid can't handle vertical layers (moving 'up' and 'down'), and needs to thus be rebuilt each time too. Jay has some random map generation libraries (see the libraries and code samples forum board), which might get into how to re-build your map/grid when not using Exits or moving vertically (up/down).


the 'MoveObject (NAME_OF_MOVING_OBJECT, NAME_OF_DESTINATION_OBJECT)' Script/Function should work fine. I am presuming that the 'dictionary' part of the error message is how it is internally handled (unless you've tried to use Dictionary Attributes) and thus is probably just some stupid/small typo or syntax or whatever mistake, causing it to not work.


location actually is determined by 'containment', which is determined by the built-in 'parent' Object Attribute:

player.parent = room_99
player.parent = room_66
player.parent = room_24

is the same as:

MoveObject (player, room_99)
MoveObject (player, room_66)
MoveObject (player, room_24)

and as 'creation' tag block:

<object name="room">
</object>

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

// is the same as:

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

see if you can figure out how to fix up your moving issue (make sure that the Objects actually do exist, that you don't have their names encased in double quotes within the 'MoveObject(...)' Script/Function and any other possible issues... if not, then we'll probably need to see your entire game code, to find where/what the issue/error is, and how to fix it up for you.


the concept of: Containment / Parent-Child heirarchy:

(think of your folder layers on your computer)

c:\\ // drive
-> Programs // folder
->-> Quest // folder

HK
-> pants
->-> wallet
->->-> $1

// ----------------------

<object name="grandfather">
  <object name="father">
    <object name="son">
      <object name="grandson">
      </object>
    </object>
  </object>
</object>

grandfather
-> father
->-> son
->->-> grandson

'grandfather' is the root (main) parent
'grandfather' is the direct parent of 'father'
'grandfather' is the indirect parent of 'son' and 'grandson'

'father'is the direct child of 'grandfather'
'father' is the direct parent of 'son'
'father' is the indirect parent of 'grandson'

'son' is the indirect child of 'grandfather'
'son' is the direct child of 'father'
'son' is the direct parent of 'grandson'

'grandson' is the indirect child of 'grandfather' and 'father'
'grandson' is the direct child of 'son'

grandfather.parent = null
father.parent = grandfather
son.parent = father
grandson.parent = son

// --------------

grandfather.parent = null
father.parent = grandfather
son.parent = father
grandson.parent = father

grandfather
-> father
->-> son
->-> grandson

// ---------

grandfather.parent = null
father.parent = grandfather
son.parent = grandson
grandson.parent = father

grandfather
-> father
->-> grandson
->->-> son

// -----------

grandfather.parent = null
father.parent = son
son.parent = grandfather
grandson.parent = father

grandfather
-> son
->-> father
->->-> grandson

// ----------

grandfather.parent = grandson
father.parent = son
son.parent = null
grandson.parent = father

son
-> father
->-> grandson
->->-> grandfather

// hopefully you get the idea/concept now...

this is quite a bit of a step up, as List/Dictionary Attributes are more difficult to understand and use especially if you don't know any coding/programming, but you can take a look at it and study if if you can understand/read it (this uses the same "teleportation/warp/goto" effect that you want though a little more complex/advanced usage of it--- no Exits being used):

http://textadventures.co.uk/forum/samples/topic/5138/explore-and-travel-code-sample-by-hk (see my 'travel_command' Command and my 'travel_function' Function, which are my 'warp/teleportation/goto' effect code)

(and also to warn, this is old code, back when I was learning to use lists and dictionaries myself, so the code is a bit poorly/badly done)


OurJud
11 Nov 2016, 16:27

I don't use maps and it is yours that are clearly causing the problem, but teleporting a player should really be as simple as activating a 'move player' script when the link/command is entered.


Robert GAC
11 Nov 2016, 21:08

Thanks Hedgemokhan
You write "the map/grid can't handle movement between rooms, unless it's adjacent room movement (using Exits), so you'll have to clear/toggle off the map/grid, teleport/warp, and then toggle it back on and/or re-initialize/build it. Also, the map/grid can't handle vertical layers (moving 'up' and 'down'), and needs to thus be rebuilt each time too."

pretty much as I feared. Then you write "the 'MoveObject (NAME_OF_MOVING_OBJECT, NAME_OF_DESTINATION_OBJECT)' Script/Function should work fine. I am presuming that the 'dictionary' part of the error message is how it is internally handled (unless you've tried to use Dictionary Attributes) and thus is probably just some stupid/small typo or syntax or whatever mistake, causing it to not work."

I think you are right and the dictionary part is an error generated by the internal handling of the map when it can't handle movement in my multilayer map.

I think I understand the parent attribute of objects, as I use it frequently to relocate the diverse objects that the player needs in one central location when I test the game.

I can't give up my map, which really IS my game - its rather large and complex, a magic castle in five layers, playable at present in a recent test version here: http://textadventures.co.uk/games/view/jzm1sjpb4usx6s1faz1xpg/bestiary

I thought I'd solved my problem with change player object. By having separate player objects for every intended teleportation (these take you to the places where the objects that you need are hidden after which you find your own way back) I was able to seemingly move the player with no map problems at all (the new player was already in the correct location. However these new players lack the inventory and stats of my first player - is there any way I could transfer these things from one player to another? If not it seems I'm seriously stuffed.


Robert GAC
11 Nov 2016, 21:39

Actually, I read in the change player tutorial: " For status attributes which apply across the entire game (perhaps “score” for example), you should set these on the “game” object itself, so they will apply all the time regardless of which object is the current POV." It doesn't matter if the inventory can't be transferred as I'm prepared to make the player empty her inventory or lose its contents every time she teleports. However health should be a global variable, like score, so is it possible to set up health in game, not player? if so, how?

I've only used the editor so far, so if this needs raw code I'm going to need help with it.


hegemonkhan
12 Nov 2016, 12:06

Try this: toggling the gridmap off/on (if we're lucky, it'll regenerate the map/grid when it's toggled back on) for your teleporting issue messing up the grid/map:

'gridmap' is a built-in Boolean Attribute contained within the 'game' Game Object // http://docs.textadventures.co.uk/quest/elements/game.html (scroll down to 'gridmap'

also, there's these Attributes/Scripts/Functions, but I don't understand this map/grid stuff... I'm guessing these are for just drawing/adding/whatever a specific room to your map/grid (as they're Attributes/Scripts of Objects --- unless the gridmap is an Object as well... hmm, meh):

http://docs.textadventures.co.uk/quest/elements/object.html (scroll down to the 'grid_xxx' Scripts/Functions)

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

set variable game.gridmap = [EXPRESSION] false // to toggle it off, hopefully clearing the map/grid
set variable game.gridmap = [EXPRESSION] true // to toggle it on and hopefully re-generate the map/grid


otherwise... we may need to look into the underlying code for a 'map/grid populate/initialization' Function... or however it's done... I'm not sure if the 'grid_render' is what we need (it might just be for adding/drawing a specific room to the grid/map)


hegemonkhan
12 Nov 2016, 12:21

quest has no built-in/pre-built way of sharing/transfering Attributes nor Objects amongst your Player Objects. We can code to do the needed sharing/transfering... (it's not that complex)

you can use the 'game.pov' Object Attribute, which will apply/reference to whomever is your currently controlled (aka: 'pov') Player Object

you can use the 'game.statusattributes' to display Attributes

http://docs.textadventures.co.uk/quest/tutorial/changing_the_player_object.html


try toggling the map/grid off/on, and if that doesn't work (let me know), then I'll help you with handling all this stuff with using multiple Player Objects. Let's not create a more complex design (using multiple Player Objects) for dealing with the map/grid issue until we're sure that we can't more easily deal with the map/grid issue.


hegemonkhan
12 Nov 2016, 12:50

P.S.

if interested, you can take a look here to learn/understand at least some of quest's coding and/or about Attributes and the 'if' Script usage better:

http://textadventures.co.uk/forum/samples/topic/5559/attributes-and-if-script-guide-by-hk

and here's a step by step guide on creating a demo game of Attributes and 'statusattributes' (which is only the displayment of Attributes):

http://textadventures.co.uk/forum/quest/topic/5387/i-really-need-help#37375


ask if you got any questions or need help or explanation of anything