How to tp to any room with commands?

So I just started learning how to write commands from a recent mrangel's post.
It triggered a potentially useful idea that I could play around with.
Except that it did not work.

Basically, I right click command and got a command which is not inside any room.
I typed tp #object#
and left it nameless.
Its script is move object player to expression #object#
or Its script is move object player to expression result

The error is I can't see the room.

The only way I could get it to work is
I typed tp room2
and left it nameless.
Its script is move object player to expression room2

Which is not so useful anymore, as I need to write out 100 commands
for 100 rooms, no way, I am doing that.


The # in the pattern tells the interpreter that the thing between them is a variable name. So the variable name you use in the script would be object.

So the command setup wiuld be:

  • Pattern: teleport #object# (command pattern)
  • Scope: world
  • Script: MoveObject (game.pov, object)

Thanks a lot.

For my future reference and simplified to my weak english:
mrangel's answer is completely correct.
Pattern: teleport #object# (command pattern)
Scope: world
Script: MoveObject (game.pov, object)

There are four categories to deal with commands, and the name is indeed not required for simple coding.
The first category is the command pattern, by typing #object#, it means to tell the computer that the variable in the script is an object.

Error running script: Unhandled command variable 'objec' - command variable names must begin with 'object', 'exit' or 'text'
This error test shows that in this script or even most scripts that the command variable can only be #object#, #exit#, #text#.

For tping the whole map, the scope have to be world even though the computer stated "leave it blank for everywhere".

The script is simply MoveObject (game.pov, object) or MoveObject (player, object)
Player is exactly the same as game.pov, just that game.pov will never change while player can change to another character/object which is probably why game.pov is used.

One of the most important bit is to remove ## from #object#, because ## represents all possible objects. After the commands finds all possible #object# from player's typing, it will select the objects with same name from player's typing, if there is another room with the same name, the player will be asked to choose one of them, so generally, this is not important information but I say it for potential future conflicts.

The important information is that in the actual script, it has to be written as object and not #object#, because you are controlling the object directly and not from a list of possible objects.

But there is one issue which I have just resolved, it is possible to tp into undead or zombies or whatever, which is not what we wanted.
There is a fail and pass example.
Fail example:
if (object.isroom = true) {
MoveObject (player, object)
}
else {
msg ("You can only tp to a room.")

Although the fail example looks very logical, the computer cannot understands it because you need to set undead.isroom = false first, which is difficult because my rpg games can potentially have 100 enemies, so I will need to set enemy.isroom 100 times.
But if you do not care about errors, this code still works when tping, it just gives an ignorable error when tping to an undead instead of msg "You can only tp to a room."

So the pass example:
if (GetBoolean(object, "isroom")) {
MoveObject (player, object)
}
else {
msg ("You can only tp to a room.")
}

So, somehow this works, but I do not understand flags or why the computer prefers boolean.
But since it works, who cares :P

After further investigation, the following also work.
if (HasAttribute(object, "isroom")) {
MoveObject (player, object)
}
else {
msg ("You can only tp to a room.")
}

For future reference, the fail case 1 shows this:
Error running script: Error compiling expression 'object.isroom = true': CompareElement: Operation 'Equal' is not defined for types 'Object' and 'Boolean'

Possibly this means the computer do not like to combine = and boolean together.


The reason you get "Operation 'Equal' is not defined for types 'Object' and 'Boolean'" is because the = comparison only works for objects that have the same type.

If an object doesn't have an isroom flag, trying to access that variable will give you the special value null, which basically means "no such attribute".

The type of null is "object". The type of true is "boolean". So = can't compare them.

The GetBoolean function makes this easier - it treats non-boolean values as false.

Scope is a bit more flexible than it used to be. Its values used to be "inventory" (objects the player is holding), "notheld" (objects in the same room as the player), or "all" (the default; all objects the player can see). Now, you can also make it the name of a room or an objectlist attribute; or "world" to include objects the player can't see.

If you want to make choosing rooms easier, you could add this line to your start script:

game.pov.teleport_destinations = AllRooms()

and then you can set a command's scope to teleport_destinations. That means that if the player types the start of a room name, the list of options to choose from will only include rooms. You can add and remove items from the list too..

Hope that makes sense.


Yes, it have been a great help.
I can make harry portal now :3

I guess if(= true)-else loop gives null on else, which is not seen or displayed, creating a deep rabbit hole mystery.
Null is more like an object attribute while true is more like a boolean which is probably why I could not understand flags, but now I know that when writing a script for a flag, it is probably best to avoid if(=true)-else loop, and use scripts like if (GetBoolean) else, if (HasAttribute) else.

I do not like the different values of scopes, but it is probably designed for a more realistic and logical game unlike mine. So, being only able to target inventory scope makes more sense if you are trying to eat something, you cannot possibly eat a hamburger from 100 rooms away.

That teleport_destinations script is very useful, it means even without typing fully the target name, the game will automatically ask you a list of options that fits best. It is useful as it can be used as a shortcut typing or to let player understand what he typed wrong.

The tp idea that I have stems from ragnarok online so it goes a bit further than just tping like a harry portal rpg game.
There can be 4 different ways to tp.

  1. Player tps itself to a target location, which is what we have been talking.
    This is not just useful in an adventure, this is also useful for admins trying to shortcut their way to test and fix some bugs.

  2. Player tps itself randomly in a map, this can be done by naming your dungeon room with all the same names but with a number behind like it, raptorjungle1 to raptorjungle20. When the player random tp, make random number script to generate 1 to 20 and add it the main tp script as discussed above, viola, this is done.

  3. Player rotates tp itself to a significant location, so lets say you have a large map like 100 rooms, but actually your game is about fishing only and there are 4 fishing spots. It is possible to create a rotatetp script, set game.fishingspot = 0, whenever the player press the button, the script is triggered and +1 to game.fishingspot. After the addition, tp the player to 1 of the 4 fishing spot which is equals to your game.fishingspot. At game.fishingspot =5, simply reset it to game.fishingspot=1.

  4. Player can tp to an area that he had setups a destination before like the portal 1 and 2 video game. This is simply done by giving the player a portal a and portal b objects, when the player clicks on either, use a script to teleport the player to the other portal object by using moveto portal.parent.


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

Support

Forums