Closed milen-prg closed 1 year ago
Well, get
has 2 forms, the one with 1 arg (which you're using) only works for nillable types, e.g. references, which will return nil
if the item can't be retrieved.
But you're using int
, which means you need to use the 2 argument version and specify a sentinel value, e.g. 0
or -1
, to indicate no element found: d.get("p2", 0)
returns 8
as expected, d.get("p3", 0)
will return 0
.
That said, the error is pretty bad, I will look into if that can be improved. It should ideally never even allow int?
.
I think, I understand. So the one argument get() function will work only with string values (I did not succeed to make another nillable type as string?): `
let c = dictionary<string, string>{size: 5}
c.add("p1", "eeeeeee") print(c.get("p1")) `
For class/struct values must use 2 argument get() with default value?
P. S. I have some C and Python background, but no experience with 3D programming and start to learn the LOBSTER as it has amazing specifications. But, may be, because I have no experience with multimedia (especially opengl, shaders, etc.), for me it is difficult to easy learn some functions operations. Because, the Lobster is for "beginner enthusiasts in game programming", may be It will be fare more useful to have some super simple and short explanations and function examples for some not trivial functions (can be as comment in the source). For example, I yet have problem to understand:
I recommend reading the language reference and the rest of the docs on what types there are to get more clarity on how this works.
It generally is hard to write docs and provide samples for every level of background, as every person misses something different. If I had "easier" rendering functions, then they'd likely be super limiting, or a different set of people would be confused about them.
And we do have some very easy functions, if you restrict yourself to drawing colored 2D lines, rectangles etc.. no shaders needed. Even text and textures can be done with no shaders. I suggest you either stick to that, or invest the the time learn more.
In the end I can't cater to everyone, and more general rendering in Lobster does require understanding of OpenGL/GPU basics.
`
import dictionary
let d = dictionary<string, int>{size: 5}
d.add("p1", 4) d.add("p2", 8)
print(d) print(d.get("p2")) // row 10 in the source
`
The error is in the row: print(d.get("p2"))
I expected that it will print 8, but:
dictionary.lobster(56): error:
return
requires typeint?
, gotbool
in p4.lobster(10): get(this:dictionary<string, int>, key:string)->int?