Bug, while loop Re-setting values?

for some reason , the while loop is resetting the value of the variable state.is it a bug? var state = "dumb path" print("state assigned dumb path outside of loop", state) let v_sync_enable =glfw.swap_interval(1) while not glfw.window_should_close(window): let v1 = glfw.poll_events() let v2 = impl.process_inputs() let clear_context = glfw.make_context_current(window) let color_clear = gl.glClearColor(0.4, 0.4, 0.4, 1) let all_clear=gl.glClear(gl.GL_COLOR_BUFFER_BIT) let v3 = imgui.new_frame() if imgui.begin_main_menu_bar(): if imgui.begin_menu("File", True): let clicked_exit = imgui.menu_item( "Exit", '', False, True) if clickedexit: print("exit") = exit(0) let end_men =imgui.end_menu() let end_menubar=imgui.end_main_menu_bar() let begin = imgui.begin("My Window", True)
# Display the button and check if it's pressed if imgui.button("select d3plot file"): var state = open_file_explorer() print("state passed to var from function-now in main") print(state) print("state printed") print("candidate not viable:Pcalle expects 0 arguments but 2 ",state) if imgui.button("Load 3Dyna Results"): load_data(state) let end = imgui.end() let render=imgui.render() let impl_render = impl.render(imgui.get_draw_data()) let swap_buff = glfw.swap_buffers(window) let imp_shutdown=impl.shutdown() let terminate = glfw.terminate()
16 Replies
Jack Clayton
Jack Clayton•15mo ago
Hey this looks cool but I can't see all the code, glfw is missing for example
Arthur Evans
Arthur Evans•15mo ago
I think the var state inside the loop is creating a new state variable scoped inside the while loop (or possibly inside the if statement?).
ModularBot
ModularBot•15mo ago
Congrats @Arthur Evans, you just advanced to level 1!
roopesh puthalath
roopesh puthalathOP•15mo ago
@Arthur Evans @Jack Clayton Thank you for the attention . here is the entire code
roopesh puthalath
roopesh puthalathOP•15mo ago
it brigs up the GUI and i am trying to get the path of a numerical computation result from the file explorer and pass it to another function - which will load the results to a webbrowser as html
No description
roopesh puthalath
roopesh puthalathOP•15mo ago
i think there could be issues with object to string conversion .
ModularBot
ModularBot•15mo ago
Congrats @roopesh puthalath, you just advanced to level 3!
Arthur Evans
Arthur Evans•15mo ago
selected_file_path is already a PythonObject. So you should be able to just do: return selected_file_path.to_string()
roopesh puthalath
roopesh puthalathOP•15mo ago
@Arthur Evans
No description
roopesh puthalath
roopesh puthalathOP•15mo ago
@Arthur Evans error: cannot implicitly convert 'String' value to 'object' in return value return selected_file_path.to_string()
Arthur Evans
Arthur Evans•15mo ago
def open_file_explorer() -> String:
roopesh puthalath
roopesh puthalathOP•15mo ago
@Arthur Evansits working now . Thanks a ton. now i will start writing what python could not do fast enough, Now i am getting the hang of it. The python interop interacting with mojo .
Arthur Evans
Arthur Evans•15mo ago
Great, glad to hear it!
Jack Clayton
Jack Clayton•15mo ago
This is really awesome @roopesh puthalath I had a play with it on my machine, let me know if you put it up on a git repo I'll share it in next weeks newsletter. Also just a tip you can get rid of that try/except block by changing to fn main() raises:
roopesh puthalath
roopesh puthalathOP•15mo ago
@Jack Clayton Thank you very much . I would greatly appreciate it if we could feature it in an edition the week after next. The additional time will enable me to present a richer Graphical User Interface (GUI) with expanded options. Additionally, I will be able to include certain computational functionalities that I believe will be of significant interest to the computer aided engineering readers.
The idea is also to share is a side-by-side comparison between a Python function and a Mojo function, focusing on their respective performance metrics. My primary aim is to enlighten the Computer Aided Engineering community about the potential and efficiencies of Mojo. I already did some preliminary tests by mimicking some computational loops within a function to firsthand evaluate Mojo's performance , and i am very happy about it. I genuinely believe that Mojo is here for the long haul. Its position might be challenged when AI evolves to the point of autonomously writing optimal assembly language tailored for specific programming scenarios. It's an honor to contribute, even in the smallest measure, to such a legacy.
Jack Clayton
Jack Clayton•15mo ago
Thanks heaps and will do, feel free to reach out when it's ready 🙂
Want results from more Discord servers?
Add your server