Closed NoidoDev closed 8 months ago
the error message is as intended, and does not contradict itself.. it says the type of tex
as passed in on that line is nillable, and it doesn't want that.
What is more curious is that it gets that type. What looks like that is happening is that the promotion by assert
to be non-nil doesn't last outside newtex
, which is kind of understandable.
To improve the code, do assert gl.load_texture(texpath)
, that way what gets assigned to tex
is never ever nil to start with.
Alternatively, let it be nillable and do gl.set_primitive_texture(0, assert tex)
when used. Both are better than the current assert locations which the type checker can't track.
Thanks. I have to learn more about certain concepts and understanding the type checker better, but this here works.
var texpath = "/home/gamerone/Pictures/.../Renamed/" + pop(texlist)
var tex = gl.load_texture(texpath)
def newtex():
texpath = "/home/gamerone/Pictures/.../Renamed/" + pop(texlist)
tex = gl.load_texture(texpath)
return tex
while gl.frame():
if int(seconds_elapsed()) > state:
newtex()
state = int(seconds_elapsed())
gl.clear(color_black)
gl.set_primitive_texture(0, assert tex)
It may seem like an annoyance at first, but I guarantee you the fact that it doesn't allow nil unchecked is an awesome feature :)
I ran into some issues with following code. I hope I didn't just misunderstand something.
gl.set_primitive_texture
(2nd argument) requires typeresource<texture>
, gotresource<texture>?
_ That message contradicts itself and doesn't tell me the problem. Also, I need a way to switch the image.fatal(gl.window("Lobster", 1024, 1024))
var state = 0 let texlist = ["01.jpeg", "03.jpeg", "05.jpeg", "07.jpeg", "09.jpeg", "11.jpeg", "13.jpeg", > var texpath = "/home/gamerone/Pictures/.../Renamed/" + pop(texlist) var tex = gl.load_texture(texpath) assert tex
def newtex(): texpath = "/home/gamerone/Pictures/.../Renamed/" + pop(texlist) tex = gl.load_texture(texpath) assert tex
while gl.frame(): if int(seconds_elapsed()) > state: newtex() state = int(seconds_elapsed())