Explanation of DSB base code and game loop, etc?

This forum is for the Lua scriptable clone of DM/CSB called Dungeon Strikes Back by Sophia. Use DSB to build your own highly customised games.

Moderator: Sophia

Forum rules
Please read the Forum rules and policies before posting. You may Image to help finance the hosting costs of this forum.
Post Reply
User avatar
Gambit37
Should eat more pies
Posts: 13773
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Explanation of DSB base code and game loop, etc?

Post 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.
Mon Ful Ir
Adept
Posts: 221
Joined: Sat Jan 07, 2006 1:54 am
Location: Britain

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

Post 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.
User avatar
Gambit37
Should eat more pies
Posts: 13773
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

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

Post 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?
User avatar
Sophia
Concise and Honest
Posts: 4307
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

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

Post 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.
Mon Ful Ir
Adept
Posts: 221
Joined: Sat Jan 07, 2006 1:54 am
Location: Britain

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

Post 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.
User avatar
Joramun
Mon Master
Posts: 927
Joined: Thu May 25, 2006 7:05 pm
Location: The Universe

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

Post by Joramun »

Mon Ful Ir: try "Scite", it's a cool open source text editor, much more powerful than the notepad.
What Is Your Quest ?
User avatar
Bit
Arch Master
Posts: 1064
Joined: Mon Mar 03, 2008 10:53 am
Location: Nuts trees

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

Post 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.
User avatar
linflas
My other avatar is gay
Posts: 2445
Joined: Tue Nov 04, 2003 9:58 pm
Location: Lille, France
Contact:

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

Post by linflas »

why using such complicated tools ?

notepad plus plus : free, smart, easy.
"The only way out is another way in." Try Sukumvit's Labyrinth II
User avatar
Gambit37
Should eat more pies
Posts: 13773
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

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

Post 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?
User avatar
linflas
My other avatar is gay
Posts: 2445
Joined: Tue Nov 04, 2003 9:58 pm
Location: Lille, France
Contact:

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

Post 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.
"The only way out is another way in." Try Sukumvit's Labyrinth II
User avatar
Bit
Arch Master
Posts: 1064
Joined: Mon Mar 03, 2008 10:53 am
Location: Nuts trees

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

Post 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)
Post Reply