Describe the project you are working on:
Tomb Raider game, atm . .
Describe the problem or limitation you are having in your project:
When I want to make a simple timer node, that is true for instance, every second, then false for the rest of the time, so use with IF condition statements, the current timer doesn't really work, that well . . I have to create a signal, and it seems weird, basically the signal ' runs ' on every frame it's true, ie. every 1 second, and then is silent, at other times . . Many nodes have attached methods, like AnimationPlayer has play(string), playbackwards(string), so on . . I was wondering if we couldn't have a method under Timer nodes, that was TRUE when it fired, and false at all other time . . So, it print . .
TRUE
FALSE
FALSE
So on . .
Describe the feature / enhancement and how it helps to overcome the problem or limitation:
I find Timer nodes very unintuitive for beginners, maybe there could be added some sort of more easily managed BOOL value, that worked like above, atm I have to make some weird code, seems pretty obvious it should be built-in, for beginners working with signals is somewhat later, would be nice if there was a method, under the Timer node, or function, that just did that, like you'd expect a timer, to work, not sure . . .
Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:
Just add a boolean to timers, as a property, or variable that output true on timer run-out, for instance, every 1 second, and false on all others, I think this could be built-in, as most beginners would find that easier to work with, and having that, wouldn't really bloat the engine . . I'm still confused by signals, and ' how ' to connect it, to logic, in bigger scripts, to for instance something in _physicsprocess, anyway, it's a suggestion, for beginners, and making a more user-friendly timer node, thank you . .
If this enhancement will not be used often, can it be worked around with a few lines of script?:
It can worked around, had to make another node, attach a script, send the signal there, and make some weird IF timer true, set boolean TRUE, and set wait_1_frame, then set to FALSE, repeat . . I just find it strange, it's not the other way around, you get a boolean that's TRUE every second, for 1 second timer, then false, that works really well with IF conditions, for instance, and it's simpler to make elegant code, or such . . .
Is there a reason why this should be core and not an add-on in the asset library?:
I think, if it was a method under the Timer node, like a ' variable ', with that property, it'd be much easier, for beginners, in general . . .
For running something every two frames, use a _physics_process(_delta) that simply returns if _delta is not a multiple of 16.6666x2
@Zireael07 if Engine.get_idle_frames() % 2 == 0: is likely a better way to do it. This way, you avoid issues with floating-point accuracy and varying framerates.
No, I want it to print TRUE every second, but all the frames in between, to print FALSE . .
Like
1.0 TRUE
1.1 FALSE
1.2 FALSE
1.3 FALSE
1.4 FALSE
1.5 FALSE
1.6 FALSE
1.7 FALSE
1.8 FALSE
1.9 FALSE
2.0 TRUE
2.1 FALSE
2.2 FALSE
But, for every once second, at 60 FPS, so 59 false, between every true . . Thx . . . . Hope this makes sense, it's difficult to plug the Timer into a condition IF statement, because it's sort of TRUE every timer-run out, but then it's void, or ' doesn't run ', like it doesn't make a FALSE when not hitting the timer, just nothing, when it's a signal . . Would be nice, if there was method under Timer, that had a bool output, that worked like above, for easier work, with IF statements, WHILE, so on . . :O :O . . .
Print true on timer timeout, otherwise print false?
Like, for a 1 second repeat timer, it prints TRUE on every second, for 60 FPS . .
After that, 59 false prints, each frame, then is TRUE, again . . Turning the signal, which is just ' empty ', or blank when it's not TRUE or, ' run ', to a bool, instead, that can be connected to an IF script box . . Just maybe make a function, like AnimationPlayer has play() when you drag it in, make when one moves Timer into visual script, there's a Timerbool, which outputs boolean, or so . .
It would make timers more easy to use, for beginners . . So, I can make an IF statement, IF Timerbool is TRUE, spawn enemy, IF FALSE, do not spawn . . So, the timer can be used as a signal, but also a bool, I feel this method is missing, from timers, right now, Thanks . . It wouldn't have to be a new node, just a ' function ', one can use, when moving a timer, into visual script, or so . . :) :) . .
Also, if I want an enemy to only scan for player every 1 second, it would be easy to just connect and IF detect_player AND IF timerbool is TRUE, do stuff, such as, set player_detected, to TRUE . .
I use visual script, and I don't know what written code does, atm . . Thx . . .
timer.connect(self, "set", ["my_boolean", true])
And then at the end of _physics_process()
my_boolean = false
I did make something similar, by attaching a spatial to the timer, adding a script to that, and setting up some IF statements, that made a bool, that worked as above, but I'm not sure why it's not an in-built function, since it's a common use case, at least for me, for instance to make a spawn player IF condition, booleans are much easier, than signals, I think . . . :O :O . . .
Wanted to ask if it was possible, since it makes a lot of sense, to a beginner . . Thank you . . .
I'm not sure why it's not an in-built function, since it's a common use case
This is a bad idea. Usually you either use signals only or do
var timer = 0.0
func _process(delta):
timer += delta
if timer >= 1:
timer = 0
do stuff
You propose a mixed approach, which results in 2 nodes processing (the timer and the logic node). It's redundant.
There's no need for a special node for this, you can easily do with scripting (as many examples were provided here).
Also you probably can just connect a function to the Timer's timeout signal and use that function to run your spawn logic. It's much cleaner code in general.
Most helpful comment
timer.connect(self, "set", ["my_boolean", true])And then at the end of
_physics_process()my_boolean = false