So I'm using the Tumbleweed template and there's one thing that's bugging me. If I use this code on an object or hotspot, the player will walk to the coordinates but he won't always be facing the object. Verb.MovePlayer only uses 2 variables. So how can I get the player to turn let's say to the left and face the hotspot using the code bellow?
function oMCup_AnyClick()
{
if (Verbs.MovePlayer(91, 106)){
//Look at
if (Verbs.UsedAction(eGA_LookAt)) {
player.Say("It's a metal cup.");
}
//Else
else Verbs.Unhandled();
}
}
Oh my god, nevermind. I'm so stupid. As soon as I typed the question I figured it out.
function oMCup_AnyClick()
{
if (Verbs.MovePlayer(91, 106)){
player.FaceDirection(eDirectionRight);
//Look at
if (Verbs.UsedAction(eGA_LookAt)) {
player.Say("It's a metal cup.");
}
//Else
else Verbs.Unhandled();
}
}
Glad you got it figured out!
I think this would be a good occasion to take a look at your code indentation. If you indent your code consistently and correctly, good things happen! So, this should look more like:
function oMCup_AnyClick()
{
if (Verbs.MovePlayer(91, 106)) {
player.FaceDirection(eDirectionRight);
//Look at
if (Verbs.UsedAction(eGA_LookAt)) {
player.Say("It's a metal cup.");
}
//Else
else Verbs.Unhandled();
}
}
Or, in the style I personally prefer:
Spoiler
function oMCup_AnyClick()
{
if (Verbs.MovePlayer(91, 106))
{
player.FaceDirection(eDirectionRight);
if (Verbs.UsedAction(eGA_LookAt)) // Look At
player.Say("It's a metal cup.");
else // Else
Verbs.Unhandled();
}
}
This makes it easier to read and understand because whenever you see a curly bracket, you can quickly tell how much of the code is inside of it (part of the code-block): just keep going down until you come to a line (which should be a curly bracket) that isn't indented in from the start block. You know the function ends when you reach an end-curly bracket at the start of the line, you know the
if(Verbs.MovePlayer…) block ends on the curly bracket right above (since it lines up with the start of the "if"), and similarly with the
if(Verbs.UsedAction…) and
else "blocks" (which here are only single lines, meaning we can skip the curly brackets). And putting the
else case on its own line (in my preferred style) makes it more visually apparent that there is a fork in the code here, with two different things that can happen.
This way, it becomes obvious at a glance, for example, that there is nothing in the function that isn't inside the
if(Verbs.MovePlayer…) condition, and that the
else goes with the second
if, not the first.