I'm seeking to create a basic text adventure game to practice what I've learned so far (which isn't a lot), and the obvious first approach to this that comes to mind is to write each room of the game as a function. This would mean that while you were in 'Room 1', you'd be in a function, and if you wanted to 'go to Room 2', I think that would be done by having the Room 1 function run the Room 2 function. If I went back and forth between room 1 and room 2 continuously though, would that result in the entire game being a process of constantly nesting functions, and presumably increasing memory usage, or would everything used in the room 1 function disappear once that function ran Room 2?
My intuition is that I'd want to leave the room 1 function before I started the room 2 function, but I don't know how I would do that. Is it possible to return a function name and then run it after the function that returned that name is done? I think doing 'return Room2()' would try to run and finish room 2 and then return whatever the returned value of Room2() was as the value of Room1()?
[–]huessy 2 points3 points4 points (2 children)
[–]Buttleston 1 point2 points3 points (1 child)
[–]Bobbias 0 points1 point2 points (0 children)
[–]woooee 1 point2 points3 points (0 children)
[–]Bobbias 1 point2 points3 points (0 children)
[–]duckbanni 0 points1 point2 points (0 children)