All Questions


posted to: The Grid

clamp function

Am I correct in assuming that the clamp function we build here overrides the built-in clamp function?  That's kind of cool if so. 

  • Nathan Lovato replied

    It does and doesn't at the same time. It does allow us to name a method "clamp()" that will be called instead of GDScript's clamp. But it doesn't exactly override it, as far as I know.

    Clamp in GDScript isn't attached to any class, but our clamp is a method on the grid class.

    While it gets called in priority inside, from another script that instantiates Grid, we'd have to call Grid.clamp() explicitly.

    This is due to the code lookup order in Godot. When calling a function, it first looks for a function in your script, then in the extended built-in classes, and then for other static functions, if I recall correctly. At least, it starts with functions inside your script.