ID:777458
 
(See the best response by Forum_account.)
Code:
obj 
key_down(k)
..()
if(k == "g")
set src in oview(1)
usr << "You get [src]"


Problem description:
the key_down proc is defined elsewhere in the code. it compiles without any errors but the "g" key does not work. if i moved the above code into the mob section, the code would work but it would add the player to the inventory and not the players content. what am i doing wrong?
Can I See You Key down Proc ?
Kalster wrote:
Code:
> obj
> key_down(k)
> ..()
> if(k == "g")
> set src in oview(1)
> usr << "You get [src]"
>

Problem description:
the key_down proc is defined elsewhere in the code. it compiles without any errors but the "g" key does not work.

This is because you have key_down() under the /obj tree, where it does not belong.

if i moved the above code into the mob section, the code would work but it would add the player to the inventory and not the players content. what am i doing wrong?

This is because key_down() is a procedure, or proc, not a verb. Do not ever use usr in procs unless nothing else will work, which is extremely rare if not nonexistent. It still registers in most cases, but don't do it. src is referencing the mob as well.

What you are doing here is assuming that key_down() is a verb, which behave different from procs. You need to study up on how procs work.

Search through oview(1) and grab an /obj, then get it.

Did my reply help you? Please click the "[X] Votes" box to vote up my response to help others!

here is the key_down
    // These verbs are called for all key press, release, and repeat events.
client
verb
KeyDown(k as text)
set hidden = 1
set instant = 1

// if input is locked, we do nothing.
if(input_lock) return

if(!use_numpad)
if(k == "northeast")
k = "page up"
else if(k == "southeast")
k = "page down"
else if(k == "northwest")
k = "home"
else if(k == "southwest")
k = "end"

keys[k] = 1

if(focus)
if(hascall(focus, "key_down"))
focus.key_down(k, src)
else
CRASH("'[focus]' does not have a key_down proc.")


where can i put this code in the obj tree to get this to work. if i put it in obj/proc, i will get an error that the proc was defined already.
I just told you that you cannot put it in the /obj tree. You need to put it in the /mob tree.
ok, i must have misread your first reply because i never seen that you said that it can't go into the obj tree. anyways, thank you for your posts
Correction: Put it under the /client tree.
the code does not work when put in the client tree
Strange. It looks like you are using Forum_account's Keyboard library, and the key_down() procs and others are defined under /client.
As Forum_account said in the other topic, key_down/up are called for client.focus. You can set the focus to anything, including the obj, but that is irrelevant. In Forum_account's Pixel Movement and consequently ARPGF, client.focus is usually the player's mob, if control hasn't been given to a HUD.
In response to Kaiochao
Best response
To pick up items near the player, you'd do something like this:

mob
key_down(k)
..()

if(k == "g")
for(var/item/item in oview(1, src))
get_item(item)


Kaiochao wrote:
As Forum_account said in the other topic, key_down/up are called for client.focus. You can set the focus to anything, including the obj, but that is irrelevant. In Forum_account's Pixel Movement and consequently ARPGF, client.focus is usually the player's mob, if control hasn't been given to a HUD.

That's correct.

Albro1 wrote:
This is because key_down() is a procedure, or proc, not a verb. Do not ever use usr in procs unless nothing else will work, which is extremely rare if not nonexistent. It still registers in most cases, but don't do it. src is referencing the mob as well.

The key_down() proc is called directly from a verb that's triggered by a macro. usr should be safe to use, but the procs also have a second parameter which is the client who pressed the key.

Strange. It looks like you are using Forum_account's Keyboard library, and the key_down() procs and others are defined under /client.

The key_up/down/repeat procs are defined for /client and /datum. When you press a key, client.focus.key_down() is called. This lets you set the focus to different objects and have each object determine how keyboard events are handled. You don't have to do things like this:

client
var
at_login_screen = 0
at_character_creation = 0

North()
if(at_login_screen)
// do something
else if(at_character_creation)
// do something else
else
..()

You can just do this:

LoginScreen
key_down(k)
// do something

CharacterCreation
key_down(k)
// do something else

client
key_down(k)
..()

That way you don't have a single proc that figures out what to do with input. Adding another menu doesn't impact the input handling code you've already written.
thank you. i fully understand now :)