I’m making a debug tool in which I can print out values on a gui every frame, and I want to be able to input any type of value—much like how println/print works.
After looking at the reference page, I noticed how it said that the datatype of the argument(s) is called “what”, and I don’t know exactly what this means. Below it states that the “what” refers to various other datatypes (i.e. Object, String, float, char, boolean, etc.), but I was curious as to how exactly println does this.
What I originally thought is that it does something like this, by overloading the function:
But I then realized that this is impossibly the way that it’s programmed, because not only can you input user-defined objects (which would not work using this method), but you can also input various different datatypes like such:
println("text", 1.0, 'a', false, [...]);
Is it possible to replicate a system that can accept arguments like these so that I could implement this into my debugging tool?
It is possible to design a function to accept user-defined objects with the typical overloading just by using the general datatype Object. The reference describes the arguments for a list of variables as an Object . I think this just means it is defined as a varying length list of variables, like in @Chrisir example just the data type is of type Object.
The real challenge is how the function should figure out what is the appropriate way to display the user-defined types. The println function doesn’t really display the value of the complex data types given to it
Nice! I really like this idea for debugging, building a general-purpose println for complex data types. I just wonder if there would be any way to display all the variables in any class, sort of like printArray. I don’t know if its possible to access these variables without knowing the names, but it would be really helpful not to have to write new code in the printing function for each data type.