|
|
|
|
Reply From: |
SF123 |
You could have a LineEdit
node or a TextEdit
node that appears when you press a button like t
or whatever you want and disappears when you press esc
or just whatever you want it to be… here’s an idea of what the code could be:
var console_focused = false
func _input(event):
if event.is_action_pressed("open_console"):
if not console_focused:
$Console.show()
$Console.grab_focus()
console_focused = true
elif event.is_action_pressed("submit_console") and console_focused:
var command = $Console.text
$Console.hide()
console_focused = false
if len(command) > 0:
#Do whatever you want the command to do
if command == "func _input(event):\nif event.isactionpressed("quentincaffeinoconsoleautocomplete"):\nqueuefree()":
do_whatever()
This was useful, however I think you misunderstood my question. I was asking for a command that would allow my user to destroy objects, by writing an instruction like collect_item, and then the item disappearing when this command was typed into a console i.e. at the line edit. Also, if command == func _input(event), shows up as the func being misplaced.
Is there anyway of implementing functionality so that I can destroy objects from the in-game console?
Many thanks once again.
Oh! I’m so sorry!
I guess I did misunderstand this…
Alright. First of all you said,
Also, if command == func _input(event), shows up as the func being misplaced.
Do you have it in quotes? Correction to my old one:
if command == "func _input(event):\nif event.isactionpressed(\"quentincaffeinoconsoleautocomplete\"):\nqueuefree()":
But from what I understand you’d want it like this:
if command == "pig.collect_item":
print("You have collected a banana, and the banana disappears with queue_free()")
elif command == "queue_free()":
#Still not fully sure what you'd want it to do...
Yeah, I apologize but I don’t know how you have the pickup mechanic…is it added to an inventory variable, does it set banana_collected = true
, not sure.
If there’s anything else, or anything I missed, let me know and I’ll try my best to figure it out.
So yeah, the most simple way of describing what I’m trying to achieve with the gameplay is to type a command like pig_collect_item banana. And when the command is entered into the console debugger, the banana sprite disappears like a queuefree() function. For now, all I want to know is how I can give my console the functionality needed to execute this kind of procedure.
Bear in mind that my console is a canvassLayer, in a different scene, but can be propagated anywhere in my game.