ID:2225481
 


Hey guys, I have been using FORUM_ACCOUNT's Keyboard library resource to start mapping my game... My problem is that my Driving Proc works by using a verb that calls it, but I'm unsure of how to call Key_down() as a usr for the Driving proc under the root /obj/Car.

I hope someone can help me out, Here is my code, I commented it in every section.

Code:
//THE KEY_DOWN() PROC WAS PROVIDED BY FORUM_ACCOUNTS KEYBOARD RESOURCE....
//THIS CODING IS FOR THE ON FOOT MOVEMENT CONTROLS WHICH WORKS PERFECTLY.




client

var/OnFoot

// by default the key_down and key_repeat procs handle
// movement, but we want to handle movement differently
// so we override them to make them do nothing.

key_down()
key_repeat()





// ControlsSelect()
// start the movement loop


New()
..()



spawn()
OnFootMovement_loop()
proc

OnFootMovement_loop()
// call the move() proc once per tick
if(OnFoot = 1)

while(1)
sleep(world.tick_lag)
OnFootControls()


client
proc
OnFootControls()

// figure out what direction the client's mob should
// move in based on what keys they're holding.
var/d = 0

if(keys["north"]) d |= NORTH
if(keys["south"]) d |= SOUTH
if(keys["east"]) d |= EAST
if(keys["west"]) d |= WEST

// move them in that direction
step(mob, d, 8)

//AT THIS POINT I WAS GOING TO MAKE A CLIENT PROC FOR DRIVING CONTROLS IN THIS SECTION,
//BUT I COULDN'T GET THE PROC TO WORK, THIS WAS WHAT IT LOOKED LIKE:


client
proc
DrivingControls()

var/obj/Car/d = (new /obj/Car)

if (d.DriversSeat == 1)

if(keys["north"])
d.Direction = "North"
usr << "[d] Direction is North"
else if(keys["south"])
d.Direction = "South"
else if(keys["east"])
d.Direction = East
else if(keys["west"])
d.Direction = West


d.Drive()
else usr <<"Your not in the drivers seat of a car."

obj
Car

proc

Drive()




if (DriversSeat == 1)
if(Direction == North)
Drive_North()

if(Direction == East)
Drive_East()

if(Direction == South)
Drive_South()

if(Direction == West)
Drive_West()


else usr << "You're not in the drivers seat."

Drive_North()
set src in view(1)
step(src, NORTH, 20)


Drive_East()
set src in view(1)
step(src, EAST, 20)

Drive_South()
set src in view(1)
step(src, SOUTH, 20)

Drive_West()
set src in view(1)
step(src, WEST, 20)


//THE PROCS Drive_North(), Drive_East(), etc WORK PERFECTLY WHEN I CALL THEM AS VERBS, BUT THEY
//DON'T WORK WITH THE KEYBOARD WHEN I LINK THEM TO THE KEYS...

//IF I LINK THEM LIKE THIS:

obj/Car
key_down(k)

if (k == ["north"])
step(src, NORTH, 20)

//I THINK key_down() WORKS, BUT IT'S WAITING FOR THE OBJ/CAR TO PRESS THE KEYS DOWN.
//WHEN I RUN KEY_DOWN LIKE THIS:

client
key_down(k)

proc
Drive()
if (k == ["north"])
step(src, NORTH, 20)

// I CANT USE KEY_DOWN INSIDE ANOTHER PROC

//IF I CALL KEY_DOWN AS A MOB, THE KEY_DOWN FUNCTION WILL WORK PERFECTLY, I JUST DON'T KNOW HOW TO
// DEFINE IT SO AS A MOB I CALL THE /OBJ/CAR/PROC/DRIVE() TO DRIVE THE CAR I'M IN....

//THE KEY_DOWN FUNCTION WHEN IT WORKS PROPERLY LOOKS LIKE THIS:

var
Constants/Constants = new()

Constants
var
const

KEY_UP = "north"
KEY_DOWN = "south"
KEY_RIGHT = "east"
KEY_LEFT = "west"

KEY_SELECT = "space"
KEY_CANCEL = "escape"

KEY_CHAT = "return"
KEY_EMOTE = "e

mob
key_down(l)

..()

if (l == Constants.KEY_CHAT)
var/M = input("Chat", "Chat Window")
Say(M)

//I HOPE SOMEONE CAN HELP ME FIGURE OUT HOW TO MAP THE CONTROLS FOR MY CAR TO MY KEYBOARD....
//THANKS IN ADVANCE.


Problem description: I don't know how to map out the keys for Driving Controls.



You need to have some kind of focus on either client/key_down() or the mob/key_down() and call focus.key_down()/key_up(). By default make the focus the mob itself so it handles its own key input, but when you want the mob to drive, make the focus the car.