Monkey FAQ

Monkey Forums/Monkey Programming/Monkey FAQ

skid(Posted 2013) [#1]
I have started a Monkey FAQ project here:

https://github.com/blitz-research/monkey/wiki/Monkey-FAQ

If anyone would like to help, feel free to post any suggested entry titles.


slenkar(Posted 2013) [#2]
list of the preprocessor directives?

like use_gles2_enabled


Amon(Posted 2013) [#3]
1:) When upgrading to a new version of Monkey ensure to delete the build folder within your games directory to avoid compilation errors and warnings.

2:) Do not load any assets within OnUpdate(). This will cause errors during compilation. OnCreate() is the method where all loading and initialization of variables should be made.


Beaker(Posted 2013) [#4]
Amon - number 2 isn't correct. You can (and sometimes must) load assets during OnUpdate, and there is nothing wrong with initialization of variables during OnUpdate either.


Gerry Quinn(Posted 2013) [#5]
Perhaps instead explain that the simplest approach is to load all assets during OnCreate() so they know that when OnUpdate() and OnRender() get called, everything is there.

You can mention that when they move on to larger projects, they may have to load assets midgame, but then they have to make sure they are available before they are rendered.


GfK(Posted 2013) [#6]
Amon - number 2 isn't correct. You can (and sometimes must) load assets during OnUpdate, and there is nothing wrong with initialization of variables during OnUpdate either.
That's illogical, captain. Wouldn't they get reloaded every update?

OnCreate() should be where you create stuff. OnUpdate() should be where you update stuff. I'm not saying you're wrong, cos I'm 99.9% sure you aren't. It just doesn't make sense why you would "in some cases" *have* to load stuff during OnUpdate().


Beaker(Posted 2013) [#7]
If you have more than one level (or a menu) you won't be loading all your graphics in OnCreate(), so you will essentially be loading some graphics in OnUpdate() even if you use a Class/Module or function to do so. If that makes sense.


EdzUp(Posted 2013) [#8]

That's illogical, captain. Wouldn't they get reloaded every update?

OnCreate() should be where you create stuff. OnUpdate() should be where you update stuff. I'm not saying you're wrong, cos I'm 99.9% sure you aren't. It just doesn't make sense why you would "in some cases" *have* to load stuff during OnUpdate().


I normally find especially when coding Hellwing its not practical to have everything loaded into the game my solution to this is simply:
If MyImage=Null
   MyImage = LoadImage( "Myfile.png" )
else
   DrawImage MyImage, WhereIWantX, WhereIWantY
endif


Basically this means its loaded when required but not drawn if its null, when i move out of the area required by the image a simple deletion of the image and resetting it to null is all thats required.

On devices like iOS devices you cannot guarantee that your app will have loads of ram available so loading of everything in OnCreate isnt practical, as an example when writing iSmashem Galactic I foolishly thought I could load everything in and on startup the game just crashed to the icon screen. To cut a long story short it turns out I had a grand total of 7Mb of ram (yes seven megabytes) to play with for the ENTIRE game on my 2nd gen ipod touch. So I had to load everything in when required and release it when it was not needed this meant the game runs perfectly and keeps playing indefinitely :)

For what its worth you CANNOT guarantee that you will have the entire system resources at your disposal even on Android devices, some people leave things like email clients open, chat system, facebuck (erm facebook) all of them take some resources and leave less and less for your game to run in by freeing the resources when they arent used will mean that your game/app will use the smallest footprint it can at all times.


MikeHart(Posted 2013) [#9]
Also if you want to display a loading bar, then you need to load stuff during OnUpdate, because only then you can render something related to the loading process. Also if your app crashes in iOS because it took to long to initialize, then you know you HAVE to load some stuff during OnUpdate.


benmc(Posted 2013) [#10]
Re: Loading assets in OnUpdate.

I always load my assets in OnUpdate. You have to set a flag or 2 in order to avoid re-loading, but if I put everything in OnCreate, on many platforms, this creates a big loading problem.

I also do this for Android to avoid slow loading on new screens.

I will load a few assets, draw them behind other assets, and repeat a few times. For some reason, on Android, the first time you show an image from a sprite sheet it's slow, so if you do this in-game, it kills the action and I have to get it done in OnUpdate loading process.

EDIT: Plus everything MikeHart said :)


skid(Posted 2013) [#11]
https://github.com/blitz-research/monkey/wiki/Mojo-App

suggestions 4 improvement welcome

Does anyone know if code embedded in github wikis can have syntax highlight?

Embedding iframes into pages would be nice also.

[edit]

sussed codehighlighting

still no luck embedding images, nice 404 message but




skid(Posted 2013) [#12]
I have added a snapshot of the latest directives here:

https://github.com/blitz-research/monkey/wiki/Monkey-Directives