Where can I put stuff?
-
I’m writing out big screen filling maps like this:
[
[0,0,1,2,2,2,1,1],
[0,0,1,2,2,2,1,1],
[0,0,1,2,2,2,1,1],
[0,0,1,2,2,2,1,1],
[0,0,1,2,2,2,1,1],
[0,0,1,2,2,2,1,1],
[0,0,1,2,2,2,1,1],
[0,0,1,2,2,2,1,1]
]And I have a load of structs defined. It’s cluttering up my project. Can I just shove them down the bottom out of the way?
-
Anything global has to be defined before it is used (obviously) but can otherwise be put anywhere in the program. I tend to put my main program at the end so it doesn't matter where the global stuff is. Use bookmarks to navigate
-
I put my main program loop at the very start all my functions below then globals then data and I call my main loop on the last line. This was a great tip from minatsu (i think) but I can't find the post.
-
@xevdev You have your main loop as a function and then your last line is just
mainloop()
(or whatever)?
-
I think this might be the post (by sahara-min): https://fuzearena.com/forum/topic/645/any-way-to-hide-this-mess-of-initialisation-code/6
I've used that pattern in my games as well, I think it's a good way to go.
-
Just to elaborate a little on what @pianofire said above earlier, which is that globals need to be defined before being used in order to actually be globals.
Beyond that, Fuze is an interpreted language and as such the engine will rattle through your program when it's run and create a list of everything it finds, meaning outside of globals stuff can be wherever you wish. BUT... while this is very typical of interpreted languages such as Basic it is certainly not as typical as your get into more complex languages. Languages such as C will complain if you have not declared anything before it is used.
To that end, I'd highly recommend getting in the habit of having Globals, then Functions, then your main loop (or a call to your main loop if it's a function). And also try to get into the mindset of making sure functions are ordered by when they are called so if function A calls function B, function B is listed before function A. No reason whatsoever apart from developing good habits. And should the ability to export programs from Fuze ever come it might help you later down the line. That is an entirely throw-away comment incidentally, I'm not aware of any such plans.
-
That process of rattling through and creating a list to allow forward referencing, is also known as
hoisting
.Other than that, I've already given my opinion :)
-
I believe I shall get into hoisting. I’ll also have a bit more of a read through of the forum now that I’ve been here a while.
-
@toxibunny yep but for what ever i go
Mainloop() // thanks min this is awesomeBut it's Sahara min and that's who I meant and I think I put it at the end of every program because it is awesome.