Where does the mojo process occur?
Monkey Forums/Monkey Beginners/Where does the mojo process occur?
| ||
I tried running this program and got unexpected results. I'm new to these forums, so I don't know if the (code) and (/code) tags work like they do on the Blitz Basic website.Import mojo Function Main:Int() Local thegame:Game = New Game thegame = Null If thegame = Null Print "Mojo is gone." Else Print "Mojo is still there." EndIf Return 0 End Function Class Game Extends App Method OnCreate() SetUpdateRate(60) End Method Method OnUpdate() Print "Mojo is working somewhere." End Method Method OnRender() End Method End Class Running this program will print that Mojo is gone, but it is still running in the background because it keeps printing "Mojo is working somewhere" even though it has been dereferenced. I assume that creating a new instance of Game turns the code over to the OS and Monkey has no control over it from there, but I'm not sure if this is correct. Can anyone shed some light on this? |
| ||
Excellent! The (code) and (/code) tags do work. That helps a lot. |
| ||
look at the generated code and you will get an idea of whats going on. basically when an instance is created the super new(from the App) is executed and is what's controlling the processes(looping). |
| ||
So I take it that there is no way to stop an instance of Mojo once it's running, other than to close the program? The reason why I ask is because I am trying to set up a framework for a larger project, and I am trying to decide on the best way to handle multiple levels. It looks like I will need to set up all of my code inside the one instance of Mojo and have the program run specific sections of code based on what level the user is currently playing. This is a little different than what I am used to, but it will work nonetheless. Thanks for the response! |
| ||
i was also surprised that Main is "useless", because it run out. I thought first that it is executed at app end |
| ||
Yeah, as I am playing around with the code, it's starting to make more sense. Basically, the Main() is there just to create Mojo, and then it serves no purpose for the rest of the program. I had tried to set up an infinite loop in the main that would execute certain sections of code based on a variable which describes the current level, but it always caused the program to hang. Instead of setting up a loop in the main, I just set up the appropriate code inside the instance of "Game" and it achieves the same effect. This is a better approach than my old techniques because I don't have to reload Mojo every time I change levels. |
| ||
(you can also write commandline tools inside Main() without the need of mojo using the C++_Tool target) |
| ||
Yes, if you want to generate a list of prime numbers or something you can do it just fine in Main(). |