ID:140688
 
Hey, I was wondering how would I go about making my character change direction rather than moving the direction I press. So if I pressed "LEFT" the characters direction would go left but would stay in the same spot.
mob
verb
Train()
TRAIN
var/direction = rand(1,4)
if(direction == 1)
usr << "Up"
if(direction == 2)
usr << "Down"
if(direction == 3)
usr << "Left"
if(direction == 4)
usr << "Right"
sleep(10)
if(direction == 1 && usr.dir == NORTH)
usr << "Great!"
goto TRAIN
else if(direction == 2 && usr.dir == SOUTH)
usr << "Great!"
goto TRAIN
else if(direction == 3 && usr.dir == WEST)
usr << "Great!"
goto TRAIN
else if(direction == 4 && usr.dir == EAST)
usr << "Great!"
goto TRAIN
else
usr << "Lose!"

If I set the code to have usr.Frozen = 1 like so.

mob
verb
Train()
usr.Frozen = 1
TRAIN
var/direction = rand(1,4)
if(direction == 1)
usr << "Up"
if(direction == 2)
usr << "Down"
if(direction == 3)
usr << "Left"
if(direction == 4)
usr << "Right"
sleep(10)
if(direction == 1 && usr.dir == NORTH)
usr << "Great!"
goto TRAIN
else if(direction == 2 && usr.dir == SOUTH)
usr << "Great!"
goto TRAIN
else if(direction == 3 && usr.dir == WEST)
usr << "Great!"
goto TRAIN
else if(direction == 4 && usr.dir == EAST)
usr << "Great!"
goto TRAIN
else
usr << "Lose!"
usr.Frozen = 0

The character doesn't move or change direction.

Problem description:Okay, what is happening here is it checks to see if you are facing the current direction as what is asks for, but if it changes direction the player will move that direction instead of just turning to that direction, I was wondering how to do it so that the charcter isn't moving all over the screen just staying in 1 spot changing directions as you press the buttons.

1)

Ugh, do not use goto. A simple while() loop [for even just
"for()" typed like that] can give you an infinite loop.

And instead of checking the variable 4 times, you can use switch(). More efficient:
for()   // infinite loop, like saying while(1)

switch(rand(X,Z))
if(X)
Do what X does
if(A to C, Y)
OMG!
if(Z)
Yay
else
This is not X, A,B,C,Y, Z

sleep(10)

if(stop) break // Stops the loop
// Repeated do to the infinite loop


Also, most of those if() statements, which gives the same message, would have been reduced by using || - you remember ||, don't you?
if(x==1||x==2)
X is either 1 or 2


As for your problem on hand... look up client/Move().
In response to GhostAnime
A Goto would work just as well but I looked up the move proc I don't know how I would go about making a procedure for it, I could make the procedure but I don't how how to call it with a while loop so I just goto and a few if statements.
In response to BleachNinja
client/Move() is called when a person presses a key. Look at the dir argument.

What you should do is think: how can I use this information to get what I want?

- What you want to do is check if the person is in training mode. If it is, check if the direction they pressed matches the value assigned. If it does, give the good message... or else tell them they have been naughty!

client/Move(check arguments)
if(!training)
return..(Move() arguments here)
// The above says that if the person is not training, do what it regularly does

// The following will happen if training is done.
// Remember, /mob == client.mob; like how you would refer to a /client by doing mob.client
if(Dir pressed == X || (Dir Pressed == Y && Z==A) )
Yay
else
BOO!


Hint: Use both the DM reference and forum search to get what i am trying to portray here




For the whole goto comparison ->
gotoSpot
world << "Hi"
sleep(X)
goto gotoSpot


// In infinite loop form:

while(1)
world << "Hi"
sleep(X)


gotoSpot1
gotoSpot2
gotoSpot3
world << "I hate you"
sleep(10)
if(sorry)
goto gotoSpot2
else
goto gotoSpot3
world << "I don't like you"
sleep(10)
if(love)
goto gotoSpot1
else
goto gotoSpot2
world << "I love you, let's get married!"
sleep(10)
if(runaway)
del src
else
goto gotoSpot1
That looks really ugly, right? Lets see in infinite loop form:
while(1)
for()
while(1)
world << "I hate you"
sleep(10)
if(sorry)
break

world << "I don't like you"
sleep(10)
if(love)
break

world << "I love you, let's get married!"
sleep(10)
if(runaway)
del src
In response to GhostAnime
Thanks for the help, I sort of know how the while code works now, I shall look up more in the reference but, with the arguments, I don't see what would go there. O_o

(Move() arguments here)
In response to BleachNinja
Look in the DM reference, for it tells you what the arguments are.

And if you do not know what arguments are, they are the variables within the parenthesis, such as - for Bump() - it only has one argument: an /atom (which they have called it "Obstacle")