Hi everyone,

Back when I was using Game Maker Studio I watched a video by Seth Coster, programmer of Crashlands, and he said he runs his entire game from one main script.

I've been thinking about this lately, just running the entire game from the Home Scene script and just doing calls and commands to all the children beneath it, including all collision responses, etc.

I can't seem to come up with any seriously negative consequences for this choice. Can anyone weigh in with their thoughts and pose some potential problems that I might oversee with this choice?

Thanks and I'm looking forward to the discussion! (Happy New Year, too!)

You can do it, but it's not very good design. Having different objects have their own scripts is more flexible. For example, if you have enemies in the game, it's easier to have each enemy have its own script, so they can easily be reused (varying amount of enemies, different enemy types in different levels, etc.). It also helps with code reuse, if you want to reuse a particular script in another project. Also, for testing, it is easier to test a smaller script and ensure it's free of bugs, when you have a huge script it is more likely that something can break and you'll have to debug a lot of code, versus a smaller script, that once working you won't have to test again. So, yes, smaller scripts are better all around.

One advantage of attaching scripts to appropriate nodes is that it enforces, or at least strongly encourages, modularity.

Ah, indeed, very thoughtful responses.

Yeah, so it seems that technically there are no obstructions to running from one script, however doing so sacrifices flexibility, modularity, and ease of debugging.

Thanks for the clarity!

Object Oriented programming is much more powerful, much more organized. Having all the code in one script would create 'spaghetti code'.

I guess I am doing something in between. In my project I don’t switch scenes. I have one main root scene that is always loaded, called ‘Global’. Its three main children are Scripts (just simple nodes, with different scripts for different aspects of the game that need to always be present), Entities (Spacial), World (Spacial) and Interface (Control).

The World has a chunk system that loads terrain as the player moves. Every entity (haven’t added any yet, besides the player) will get loaded and unloaded, each one as a different scene. That way it’s still object oriented, but everything is under a single scene the whole time.

The Global script has onready vars that reference to important nodes (like player, camera, etc), so I can pick them them up from any script in the game. That way, if I change the location of a node in the tree, I only have to change one variable and not one for all the scripts that call it.

Not sure if this is a good design, but I think it works for my project.

Did he maybe mean something similar, or did he literally wrote the whole game in one single long script?

The most successful people tend to ignore the "rules" and create their own path. But that requires really knowing what you're doing.

Learning the rules is so you'd know what to do. Once you know what you are doing you can break the rules in ways that lead to success, rather than failure.

Indeed. All around, indeed. Thanks for weighing in everyone!

2 years later