Page 1 of 1

Explanation of DSB base code and game loop, etc?

Posted: Fri Dec 17, 2010 7:14 pm
by Gambit37
I'm trying to get my head around the base code and game loop, but failing.

Sophia, is it possible for you to write an outline of how all this stuff is processed, and in what order? And also provide info on how this can be overriden by code in a dungeon folder -- and also the setup for those? For example, what .lua files call what other .lua files and in what order?

How do I override a base function? Do I just copy it, change it, and stick it in a lua file in my dungeon folder and that function will be used in preference to the base one? Or is there some sort of cloning that needs to be done?

The big problem I'm finding is that I don't have a good "bigger picture" visual of how all this stuff fits together, and thus how best to manipulate it.

Re: Explanation of DSB base code and game loop, etc?

Posted: Fri Dec 17, 2010 7:31 pm
by Mon Ful Ir
Lemme try and help...

In your dungeon folder, create startup.lua. Write this:

Code: Select all

lua_manifest = {
  "example.lua",
  "example2.lua"
}
Everything in example.lua will be loaded, then everything in example2.lua, etc. The files in example.lua can overwrite the base code for that particular dungeon, so you can replace a function in the basecode called sys_example_function with a local variant, also called sys_example_function, if it appears in example.lua.

Re: Explanation of DSB base code and game loop, etc?

Posted: Sat Dec 18, 2010 4:33 am
by Gambit37
Great, thanks, that's useful.

What about the processing order of the base files? Would be useful to know this so I can start to understand the flow a bit better. Sophia?

Re: Explanation of DSB base code and game loop, etc?

Posted: Sat Dec 18, 2010 5:05 am
by Sophia
Gambit37 wrote:What about the processing order of the base files? Would be useful to know this so I can start to understand the flow a bit better. Sophia?
Well, the processing order of the files doesn't really give you that much insight into the program flow, but, to answer your question: First, DSB loads base/global.lua. It then handles the lua_manifest as given there. It then loads base/startup.lua. Lastly, it loads the startup.lua as specified in your dungeon, and handles its lua_manifest.

To get a feel for the program flow, it might be better to think about what kinds of things you'd like to change. Usually, objects have various on_* functions, message handlers, attack methods, and such things, that govern what they do under certain conditions. You can then delve into the code and see what the function's parameters are and what it does. Sometimes it's not clear what file the function you want is in-- LuaEdit can be very valuable here because you can just open a bunch of base code files and search them all quickly. Other interesting files to look at would be system.lua and hooks.lua. They are almost the same thing, only system.lua contains functions invoked by the core engine (the C part) where hooks.lua contains various things done by the base code (the Lua part) that you might want to hook. This actually makes me think of another problem, but I'll post about that in another thread.

Re: Explanation of DSB base code and game loop, etc?

Posted: Sat Dec 18, 2010 11:51 am
by Mon Ful Ir
I actually uninstalled and removed LuaEdit the third time it accidentally dropped my whole dungeon in the recycle bin, and I'm currently editing in notepad again.

Re: Explanation of DSB base code and game loop, etc?

Posted: Sat Dec 18, 2010 9:26 pm
by Joramun
Mon Ful Ir: try "Scite", it's a cool open source text editor, much more powerful than the notepad.

Re: Explanation of DSB base code and game loop, etc?

Posted: Sun Dec 19, 2010 6:22 am
by Bit
You may also think about using the free available MSVC-express-version.
It's not necessary to program something, you can setup a project with several files, and then use a powerful find/replace-in-project function.

Re: Explanation of DSB base code and game loop, etc?

Posted: Mon Dec 20, 2010 2:16 am
by linflas
why using such complicated tools ?

notepad plus plus : free, smart, easy.

Re: Explanation of DSB base code and game loop, etc?

Posted: Mon Dec 20, 2010 2:23 am
by Gambit37
I tried Notepad++ for HTML/CSS work and simply didn't like it. Plus I'm not sure it does code colouring for Lua does it?

Re: Explanation of DSB base code and game loop, etc?

Posted: Mon Dec 20, 2010 10:56 am
by linflas
i use it everyday for html/css/php/perl/lua etc. ! i especially like the incremental search (i re-mapped it to CTRL-F), the string search on several files, and the way you can edit any language syntax highlighting by simple clicks.

Re: Explanation of DSB base code and game loop, etc?

Posted: Mon Dec 20, 2010 2:38 pm
by Bit
Didn't know that one. Got extremely good ratings. Must try - thx!
Now back to topic ;)
(perhaps shift the last posts to the 'interesting tools'-thread I once made)