Bug on My Code, Help Me.
BlitzMax Forums/BlitzMax Programming/Bug on My Code, Help Me.
| ||
' Crear Sol. Function CreateSun:TLuz( padre:Int = 0) Return New TLuz.InitSun( padre:Int = 0 ) End Function Type TLuz Field luz:Int Field padre:Int Method InitSun:TLuz( padre:Int = 0) Notify padre:Int ' NOT RETURN 0, RETURN 1 End Method End Type ' Objetos. Local sol:TLuz = Null sol:TLuz = CreateSun() ' Not Number, Void. I like the number 1, when I did not pass any value to the CreateSun () parameter, Any suggestions? |
| ||
Ok, no problem. Return New TLuz.InitSun( padre:Int = 0 )Bad. Return New TLuz.InitSun( padre:Int )Ok. |
| ||
What Return New TLuz.InitSun( padre:Int = 0 ) really does is: Return New TLuz.InitSun( trueOrFalse ) it evaluates "padre = 0" - so if padre was > 0 it returned True and so on. @ Your sample While it works you should consider having "TSol" as a custom type (extending from "TLuz". So you would then use "new TSol.Init(...)". Why having "sol" as a custom type? This allows for a simple extension - eg. properties like "glow" or "temperature". If your normal "TLuz" does not need that (normally all stars share the same properties - some are just not used or negative or very low on one star and active on another). But this could also be handled with "components" (there are threads about this on this forum). So eg. you could add a "gravity" component (or better a "rotation"-component which handles calculation of gravity). But for now just think of "TSol" as something to optimize memory usage. Everything only a "sol" can co but no other "luz", could get stored in this custom type "TSol". Else you end up having a "god type" (knowing and storing everything). Think of the type "THuman". Now you want to save: - body size - eyecolor - hair length ... and then you need to save: - penis size - breast cup size ohh... you want to save them for all human beings? Nope, you create "TMan extends THuman" and "TWoman extends THuman". Each of them gets the "only man" or "only woman" properties you need to save ... When talking about "components" you would add a "genderspecifics"-component which could be split into "malespecifics" and "femalespecifics" - each of them having their "GetPenisSize()" or "GetBreastCup()" methods - or even more dynamically you have a "GetInt("penissize")" method, which returns a value for males and "-1" for females (as the femalespecifics-component is not handling the request to "penissize"). Sorry if someone felt offended by reading "penissize" - if so: grow up! bye Ron |
| ||
This is my new approach to what I learned from you. I can understand about humans. In the case of an Animal class, quadrants or bipeds can appear, within the quadrants, we have cats and cats. And all these are can share methods, such as eating, but the difference is how they are implemented since a chicken eats a different tiger. |