-
-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make @GDScript scope cleaner #1590
Comments
For Color8/ColorN, see the second paragraph of this comment.
|
My criteria is the following: if functions are not essential to facilitate the process of quick prototyping and doesn't cater to most use cases, then those kind of functions can be removed.
Yeah, because you'd still be able to look for "json" and stumble upon There are other classes like
I guess makes sense... But retaining
There's no absolute need for this to be at global scope, but last time I used this is to setup deterministic sequence of random test data for stress testing and to find out what kind of seed is needed to fail the test. But if you look at how people use this feature in C++, I think it's still preferable to use TEST_CASE("[Stress][CommandQueue] Stress test command queue") {
const char *COMMAND_QUEUE_SETTING = "memory/limits/command_queue/multithreading_queue_size_kb";
ProjectSettings::get_singleton()->set_setting(COMMAND_QUEUE_SETTING, 1);
SharedThreadState sts;
sts.init_threads();
RandomNumberGenerator rng;
rng.set_seed(1837267); So, likely the same can be said for GDScript tests to achieve locality and reproducibility of testing.
Surprise, For the rest, I guess makes sense, because
I'm not sure either, I'd prefer these functions to be moved to
Retain, because I've already written some docs for this: godotengine/godot#42439. 😄
I've never used those myself, but perhaps those are frequently used functions when you do need to deal with audio, I presume most people have not yet reached that point to care about this. |
I don't understand why tool
extends EditorScript
var a = 123
var b = "abc"
func _run():
print(var2str(self))
print(var2str(inst2dict(self)))
The only difference is that it works slightly better with inner classes. |
Yeah it does work better with inner classes: extends Node2D
class CustomNode extends Node:
var abc = "abc"
func _ready():
test_serialize_inst2dict_dict2inst()
test_serialize_var2str_str2var() # This fails.
func test_serialize_var2str_str2var():
var n = CustomNode.new()
print(n)
var inst_str = var2str(n)
print(inst_str)
n.free()
var inst = str2var(inst_str)
print(inst)
assert(inst.get_script() != null)
assert(inst.abc == "abc")
func test_serialize_inst2dict_dict2inst():
var n = CustomNode.new()
print(n)
var inst_dict = inst2dict(n)
print(inst_dict)
n.free()
var inst = dict2inst(inst_dict)
print(inst)
assert(inst.get_script() != null)
assert(inst.abc == "abc")
Also prevents serializing built-in properties like I think the There are other enhancements which could further improve existing |
Idea: create a global instance of |
You may be right: godotengine/godot#43128. 😃 |
Agreed.
The rest kind of depends on the outcome of #1774 and/or #1741.
Makes sense I guess. Then there would be a need for better documentation of how to use the
The main issue is that GDScript until now does not support static functions. You can't use I agree that they're bad though and finding a way to improve this would be good. We did talk about renaming
No strong opinion here.
These are like Unless we introduce a |
Now many of the functions are part of core, so they will be used in GDScript as is (to not complicated things further). Those are mostly math and utility functions, very useful for GDScript anyway. Still, some extra functions remain so since I'm working on it I'll take the time to clean those up. I'll comment on this here.
I agree with this. I don't see a reason to keep those since the JSON singleton is available. If need be, we can add more straightforward functions to JSON, when you don't need to validate for instance.
Those are now in core. I bvelieve There is a discussion to move all this to a
Those are now in core too, and can be used by other languages. May also be removed from the global scope, but it's a bit out of my reach now. Except the
I find
This makes sense as a function still. It's used a lot so the convenience is of great help.
Those are also in core now. I guess they have some use in audio systems (like when making a volume slider). Not sure where else to put though, as the server might not be the best fit.
I believe the most use is to convert instances to JSON, since making that from a dictionary is easier. But since it's not 1:1 I'm not sure if it's the best way to serialize things (it's just the easiest one). |
This actually works last time I checked (Godot 3.2.4): extends Node2D
func _draw():
randomize()
var c = Color.from_hsv(randf(), randf(), randf())
draw_circle(Vector2(100, 100), 64, c) So I guess functions of built-in |
See also my PR godotengine/godot#35505. On the last rebase, I added the
The fact is that in 99% of cases these functions are used only together with these methods of the
In my opinion, it makes sense to add the methods:
|
Now "Make By the way, highlighting and auto-completion do not work for When moving functions from |
Revisiting this now, is there still actions need to be done here? I don't think we need to be so conservative about the the functions in the global scope (whether in The one that catches my eye is
That was a deliberate decision since you replace It would be nice to do a pass of what actually needs to be changed so we can do before beta. |
While I think
Absolutely agree. |
That's something to be considered. Since Strings are UTF-32 in Godot 4.0, it it's really getting a code point so the Looks like an oversight on my part. I removed all functions that were added in Variant, probably missed to see that one moved as well. |
Since we are now moving towards leaving
The following functions remain in
|
It's too late to clean up members of Several of the things in this proposal have been completed, so I'm closing this as completed. For any remaining issues, a new proposal could be opened which would target Godot 5.0 (which will be in a decade or so), with the remaining issues clearly stated in the OP so that we don't have to hunt around for them in this thread. |
I still think there's some merit to the ideas here. We can still deprecate functions in favor of others, and moving from In particular, I do agree that this would be better as new proposals. |
|
See #5615 (comment):
But in any case, this is no longer relevant, after the release of 4.0 we cannot remove these global functions. |
Describe the project you are working on:
A game
Describe the problem or limitation you are having in your project:
I noticed that some of the global functions in GDScript duplicate/overlap with functionality of other built-in classes.
Describe the feature / enhancement and how it helps to overcome the problem or limitation:
My proposal describes each individual case and possible solutions. Perhaps some cases will remain unchanged, but I will be glad if GDScript becomes a little cleaner.
Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:
1. to_json(), validate_json() and parse_json()
There is the
JSON
singleton that does the same.As we can see, the number of lines has not changed, the code has not become more complicated or much longer. Moreover, the
JSON
singleton and theJSONParseResult
class provide several additional capabilities that GDScript functions do not.I propose remove the
@GDScript.to_json()
,@GDScript.validate_json()
and@GDScript.parse_json()
functions.2. randomize(), seed() and rand_seed()
It seems to me that having control over the global RNG seed is a bad idea. The global RNG has to be randomized implicitly, as in many other scripting programming languages. Thus,
@GDScript.rand*()
functions will use a different seed each project run. For deterministic sequences of pseudo-random numbers, use theRandomNumberGenerator
class.If someone uses the
@GDScript.seed()
function - please respond and describe why you need it.I propose remove the
@GDScript.randomize()
,@GDScript.seed()
and@GDScript.rand_seed()
functions, and also make it so that the global RNG is randomized implicitly when the project starts.3. str2var(), bytes2var(), dict2inst() and var2str(), var2bytes(), inst2dict()
In my opinion, these functions are relatively rarely used, they are not GDScript-specific, and therefore there is nothing wrong with moving them into the
Marshalls
singleton, which already contains similar functions:By the way, the
Marshalls
singleton lacks thestring_to_hex()
andhex_to_string()
functions, now this needs to be done through the intermediatePoolByteArray
, which is not very convenient.I propose move
@GDScript.{str2var,bytes2var,dict2inst,var2str,var2bytes,inst2dict}()
functions toMarshalls
singleton with consistent names.4. Color8() and ColorN()
Perhaps these functions should be part of the
Color
class.This is especially true of the
ColorN
function, becauseN
still gives me associations with a number, not a name. Maybe, theColor(from: String)
constructor should recognize not only hex colors, but also named colors (for example,Color('red')
).As for
Color8
, maybe we need a static method calledColor.from_rgb8()
, similar toColor.from_hsv()
?I'm not sure, but I think we should discuss this?
5. load()
See #263 (comment)
@GDScript.load()
andResourceLoader.load()
are the same. However, I think we shouldn't change this, becauseload()
is used quite often and is a pair forpreload()
, which is not present inResourceLoader
.I'm opposed, but I must mention this for the sake of completeness.
6. db2linear() and linear2db()
These are very specific functions, maybe they should be moved to the
AudioServer
singleton?If this enhancement will not be used often, can it be worked around with a few lines of script?:
No, this is part of the GDScript language.
Is there a reason why this should be core and not an add-on in the asset library?:
Yes, this is part of the GDScript language. 😃
The text was updated successfully, but these errors were encountered: