I made Pong game with Godot a couple of years ago and now came again to Godot.
This time I started a new game with really nothing more then date in one corner that is incremented each second and ability to pause that increment by pressing Space.
Ive had a hell of problems with aligining and positioning UI elements, in this case Date should be aligned to the top right edge of the screen. Date(Label is contained in a HBoxContainer which should later also have other controls. Finally managed to somehow do it with the help of Layout,. Now it looks ok in IDE but when run there is space to the right of Label which should NOT be there.
The second problem is with pressing Space - pausing. If pressed briefly its mostly not registered by the code, but if you press and hold it longer it behaves as pressed twice.
Here is the code:

func _process(delta):
	TimePassed += delta
	if Input.is_action_pressed("ui_accept"):
		paused = not paused
		if paused:
			$VBoxContainer/Pauza.text = "Paused"
		else:
			$VBoxContainer/Pauza.text = ""
	if (TimePassed >= TimeWait) and not paused:
		TimePassed = 0
		adjust_date()	
func adjust_date():
		var day = 0
		var month = 0
		var year = 0
		var cday = ""
		var cmonth =""
		var cdatum = ""
		var datum = get_node("HBoxContainerDesno/Datum")
		day = datum.text.substr(0,2).to_int()
		month = datum.text.substr(3,2).to_int()
		year = datum.text.substr(6,4).to_int()
		if month in velikiMeseci:
			if day == 31:
				if month == 12:
					month = 0
					year +=1
				month += 1
				day = 0
		elif month == 2:
			if day == 28:
				month += 1
				day = 0
		elif month in maliMeseci:
			if day == 30:
				month += 1
				day = 0
		day += 1	
		cday ="%02d" % day
		cmonth = "%02d" % month 
		cdatum=cday+"."+cmonth+"."+str(year)
		$HBoxContainerDesno/Datum.text=cdatum.strip_edges()

You can also comment on improving code, Id appriciate any input
EDIT: I also lost indentation while copying code here so you can help me with that too πŸ™‚
Ok, I found a post which explains fomating code segment
Z.

  • If you want to paste code on the forum, you have write 3 tildes ~~~ on a line by themselves, directly above and directly below the code. The button is only for inline code, like a single line.

    In terms of the pausing, you should be doing input handling in _input. Use the function like this:

    func _input(event):
        if event.is_action_pressed("pause"):
            # do the pause here

    You should also set your own input mappings but game events and not use the built-in ones. This makes it more clear to what is happeneing.

If you want to paste code on the forum, you have write 3 tildes ~~~ on a line by themselves, directly above and directly below the code. The button is only for inline code, like a single line.

In terms of the pausing, you should be doing input handling in _input. Use the function like this:

func _input(event):
    if event.is_action_pressed("pause"):
        # do the pause here

You should also set your own input mappings but game events and not use the built-in ones. This makes it more clear to what is happeneing.

    cybereality
    Thanks Cybereality, your suggestion about moving input handling to _input did the trick. πŸ™‚

    Any hint why label is disobaying its position?
    Also, how do you quote the post or part of the post?

      ZedMcJack Also, how do you quote the post or part of the post?

      If you select the text, then a little button below the selected text called β€œquote” should appear. Pressing it will copy the text for quoting πŸ™‚

      You can also manually quote text using markdown:

      > text to quote here

        TwistedTwigleg zed-mcjack Also, how do you quote the post or part of the post?

        If you select the text, then a little button below the selected text called β€œquote” should appear. Pressing it will copy the text for quoting πŸ™‚

        Ahh, Id never guess, but it works, thanks πŸ™‚

        If Label is a child of a Control (like any container) then you cannot set its position manually. They really should just disable the position, because it won't work. You have to use the layout options of Control, like the size flags, min size, layout (it's on the top middle above the viewport, you can set center, top right, etc.).