a custom moving command
Tiffany Pratt
31 Jul 2016, 00:53ok so in my game. im adding a quick movement command where people can type the location they want to go to,
this command will mainly be used for vehicle movement.
like this: drive to [LocationName] is there a way to make a custom type thing so when you type a location in the command you go to that room....?
hegemonkhan
31 Jul 2016, 01:45in the GUI~Editor:
Objects -> Commands -> add -> (set it up, see below)
to do the 'player.parent = object' Script seen code below, in the GUI~Editor:
(run as script) -> add new script -> 'variables' section/category -> 'set a variable or attribute' Script -> (see below, for example)
set variable player.parent = [EXPRESSION] object
in code, here's an example of it:
<command name="goto_command">
<pattern>drive to #object#</pattern>
<script>
player.parent = object
</script>
</command>
however, you really need to put some checks/conditions on this, as you don't want to be able to go to any Object that you type-in for the input.
an example of putting some conditions/checks on it:
<object name="room1">
<attr name="type_of_object" type="string">room</attr>
</object>
<object name="room2">
<attr name="type_of_object" type="string">room</attr>
</object>
<object name="tree1">
<attr name="type_of_object" type="string">non_room</attr>
</object>
<object name="dog1">
<attr name="type_of_object" type="string">non_room</attr>
</object>
<command name="goto_command">
<pattern>drive to #object#</pattern>
<script>
if (object.type_of_object = "room") {
player.parent = object
msg ("You suddenly find your self transported to the location you desired.")
} else {
msg ("You can't go to that, silly! Error: Wrong input, please type in the name of a 'Room Object', if you try again")
}
</script>
</command>
results/outputs:
- input: drive to room1 ---> (you're moved to 'room1') and 'You suddenly find your self transported to the location you desired.'
- input: drive to room2 ---> (you're moved to 'room2') and 'You suddenly find your self transported to the location you desired.'
- input: drive to tree1 ---> 'You can't go to that, silly! Error: Wrong input, please type in the name of a 'Room Object', if you try again'
- input: drive to dog1 ---> 'You can't go to that, silly! Error: Wrong input, please type in the name of a 'Room Object', if you try again'
Marzipan
31 Jul 2016, 02:18Tiffany, custom commands and IF THEN stuff are pretty simple things to learn that you'll come back to again and again for situations like this, and countless others. I'd recommend checking out the tutorial and playing around with them until you have them down, they really are absolutely vital.
The Pixie
05 Aug 2016, 22:29It is certainly useful to go though the tutorial, but this is going into areas not covered so will not directly help. HK's solution will not work, because #object#
will only match things in the present room or player inventory, and the destination room will not be that. Instead you need to match the text yourself.
Creat a new command, and for the pattern, paste in this:
drive to #text#
Click the "Code view" button, and paste this in (lines that start // are comments, and hopefully will help you understand what is going on, but this is not straightforward, so do not worry if it does not):
handled = false
// check each object in the game world
foreach (obj, AllObjects()) {
flag = false
// does the text match the name or alias (if it has one)?
if (obj.name = text) {
flag = true
}
if (HasString(obj, "alias")) {
if (obj.alias = text) {
flag = true
}
}
if (flag) {
// We have a match so deal with it
handled = true
if (ListCount(ScopeExitsForRoom(obj)) = 0) {
// If the thing has no exits, assume it is not a room
msg ("That's not the sort of thing you can drive to.")
}
else if (obj = game.pov.parent) {
// Are we already there?
msg ("You're already there.")
}
else {
// Success! Give the message first, then Quest will
// handle room descriptions when the move is done
msg ("You jump in your car and drive off...")
player.parent = obj
}
}
}
if (not handled) {
// Failed to find a match, so report the error
msg ("I have no idea what \"" + text + "\" means.")
}
XanMag
06 Aug 2016, 01:59I would do this one of two ways.
- Create a command called "drive".
- Print a message "where would you like to go?"
- Print a message with numbered options. 1. Blah, 2. Blah blah, etc.
- Use a get input/switch script and move player to desired room.
OR
- Create a global command for each location the player can travel to.
- Run an If script to check if the player is in the proper room to drive from. Then move player to desired location.
You can always add if statements to check for conditions that need met for each location.
If you choose this method, let me know. I'll help.
Good luck!
hegemonkhan
06 Aug 2016, 02:35oops, thank you Pixie for pointing out my faulty code, I keep forgetting that when working directly with Objects (using #object#), it only searches/checks for Objects in the room that the Player is in, argh! As, I, myself, usually just use #text# and 'foreach(AllObjects)'check-convert it into an Object instead of using #object#, so that's why I'm unaware-forgetful about the issue with using Objects directly (using the #object#).
my apologies Tiffany, for the faulty code in my previous post.