最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

gdscript - Did the time function change in the new Godot update? - Stack Overflow

programmeradmin0浏览0评论

This part of my code dosen't work:

 func _process(delta):
    # Send request every second
    var current_time = OS.get_ticks_seconds()  # Get time in seconds
    if current_time - last_request_time >= 1.0:  # 1 second
        last_request_time = current_time
        _send_request() 

and gives error: Static function "get_ticks_seconds()" not found in base "GDScriptNativeClass". I think its because they changed the function. I want to call send request every second

This part of my code dosen't work:

 func _process(delta):
    # Send request every second
    var current_time = OS.get_ticks_seconds()  # Get time in seconds
    if current_time - last_request_time >= 1.0:  # 1 second
        last_request_time = current_time
        _send_request() 

and gives error: Static function "get_ticks_seconds()" not found in base "GDScriptNativeClass". I think its because they changed the function. I want to call send request every second

Share Improve this question asked Feb 2 at 10:33 DODO_Hacker10DODO_Hacker10 112 bronze badges 2
  • 1 Are you 100% sure get_ticks_seconds ever existed? When googling it, the only hit is this very question. I see get_ticks_msec and get_ticks_usec though. – Ted Lyngmo Commented Feb 2 at 10:44
  • 1 Welcome to our timeline, it seems you crossed over from a timeline where get_ticks_seconds existed. Presumably in your timeline this proposal was implemented: Add Time.get_ticks_second() method. These discrepancies between timelines can cause disconfort, but you get use it. – Theraot Commented Feb 3 at 15:22
Add a comment  | 

1 Answer 1

Reset to default 3

Godot 4+ changed os.time_ticks_usec and os.get_ticks_msec to time.get_ticks_usec or time.get_ticks_msec. A few others may have gotten changed, so it'll be good to check in the Time documents and check some tutorials. In the documentation for OS it says this:

Note: In Godot 4, OS functions related to window management, clipboard, and TTS were moved to the DisplayServer singleton (and the Window class). Functions related to time were removed and are only available in the Time class.

I also found reference to Time replacing OS in this reddit post. I haven't found any reference to seconds as a whole, but it should be easy enough to adjust if you need it to check for every second in theory.

func _process(delta):
    # Send request every second
    var current_time = Time.get_ticks_msec()  # Get time in milliseconds
    if current_time - last_request_time >= 1000:  # 1 second
        last_request_time = current_time
        _send_request() 
发布评论

评论列表(0)

  1. 暂无评论