Includng all folder files

Blitz3D Forums/Blitz3D Programming/Includng all folder files

EpicElrod(Posted 2015) [#1]
I am making a game, and I want the players to easily be able to mod the game by simply placing the files into the "Mods" folder. Is there a way to use the Include function to include everything in this folder?


RemiD(Posted 2015) [#2]
It depends what you mean by "mod".
You may have noticed that in some games, some mods are not compatible.
This is because some mods do minor changes to the game (for example change some properties (name, attack, defense, magic power, gold value) of some objects.) but some mods do major changes to the game (for example change the controls, the possible actions interactions with the world, the characters, the environments, the objects, the ai)
Knowing this, what do you want to be able to mod in your game ?


Yasha(Posted 2015) [#3]
Include is not a function. It is a compile-time statement. It doesn't even exist at runtime, let alone have the ability to change what it does.

This means that if you want your players to be able to mod the game using Included files, they will actually need to completely recompile it from source. Now this isn't necessarily a problem, especially since Blitz3D is now free (so redistributing stuff that relies on the compiler is OK - you can even redistribute the compiler itself), but it isn't what people generally assume you mean by "mod", which normally implies tweaking some additional files and often not even needing to relaunch the program or level.


The second strange thing about what you're asking is - Blitz3D is quite a static language. You write code that pulls in known commands from other parts of the program. How would the host program use this folder if it doesn't know anything about its contents? It wouldn't know what to refer to in order to actually make use of what the player defined there.

The closest I can suggest in this respect would be that you have one "known" include file in the mods folder, e.g. "mod-main.bb", and this file is required to provide definitions for a fixed set of functions, e.g. SetupGame, RunGame, etc. But the static nature of Blitz3D means that if you do this, you have to put the default definitions of those functions in view in the mods folder too. Blitz3D doesn't have a mechanism for speculatively choosing between pieces of code, so for your users can only add something where it's already expected, and that means it has to exist and be replaced. This... could end up being a big mess.


The more widely used solution for modding is to have the mods run in a separate piece of code somehow. They could be compiled to DLLs and loaded at runtime by your program via CallDLL, or they could be interpreted by a scripting engine you build into your program, but either way they don't actually form part of the main game binary. This allows hotswapping without needing to recompile, and allows you to choose between extension options without needing to expose the guts of your game proper.

Try searching the forums for "scripting" to see examples of the more conventional ways people have handled this in the past. There are some good existing solutions out there.


EpicElrod(Posted 2015) [#4]
I think you misunderstand... Making "Include" files are relatively easy. The game would include everything in the folder. Seince the inclusion is before anything else in the code, it overrides the main code.


Dan(Posted 2015) [#5]
With Modding the game you mean that people change the look of the game ?
That they add their Graphics and Sounds or That the Game loads their version
of the graphics ?
Or maybe that they add their versions of the Level maps ?


EpicElrod(Posted 2015) [#6]
I mean like make mods... You know, levels, gamemodes and items.


Dan(Posted 2015) [#7]
and your program is given as source code or binary only ?


RemiD(Posted 2015) [#8]
If the gameplay is fixed (possible actions interactions) and you only want to modify or to add maps, armors, weapons, items, characters, one way would be to have one directory for each kind ("maps/" "armors/" "weapons/" "items/" "characters/") and in your code, scan each directory and show what it is possible to select.
A similar approach was used in quake 3, there was one directory for characters, one directory for maps, and it was possible to choose a custom character or a custom map.


Yasha(Posted 2015) [#9]
Seince the inclusion is before anything else in the code, it overrides the main code.


Blitz3D program structure doesn't allow for this. Everything has to have exactly one definition in the program (with one exception: you can override builtin engine commands like "DrawImage"). You can't supply definitions earlier and have them take precedence over definitions later, as the compiler won't know which ones to use. The language simply doesn't have the notion of optional code content or multiple implementations.

Other languages like Python may provide the feature, but Blitz3D simply wasn't set up for it. Hence the separation of categories between "scripting" and "main program" that doesn't need to exist in those languages.


Also RemiD's point is a good one. For the vast majority of low-key modding, you don't need to change operational code at all. You only need to change data parameters, which mean either media or config files. Levels and items shouldn't require coding or scripting at all, because they aren't usually a part of the program anyway.


RemiD(Posted 2015) [#10]
In Morrowind, (if i remember correctly) it was possible to add some scripts but they did not change the gameplay (possible actions interactions), the scripts where only here to change the properties of some existing entity in the world or to check for events and update the world depending on that. (add/remove some entity, change the properties/ai/behavior of some entity)


EpicElrod(Posted 2015) [#11]
Basicly, The folder layout would be: "The Flesh" (Game) with subfolders of "Assets" and "Mods" "Assets" would have all your stuff. Imge, texture model etc. folders, whereas "Mods" would have pictures of baby giraffes. No, not really. It would obviously hold mods. Then I would say, "Include everything in that folder"


Yasha(Posted 2015) [#12]
"Include everything in that folder"


What is the actual effect (both mechanism and result) you are expecting to achieve with this?

As repeatedly said above, Include doesn't work at runtime. Include also doesn't work with variables. The definitions in Blitz3D source files need to be completely static; you cannot add more definitions and expect them to override one another or magically add functionality on their own. Include doesn't work this way, and neither does B3D program structure.


Zethrax(Posted 2015) [#13]
For mods/addons you've basically got two options. One is to use a scripting language. The other is to use DLL plugins.

For scripting look for Blitz Virtual Machine or another scripting language that works with Blitz3D. Check the toolbox and code archives sections of this website.

For DLL plugins you'll probably want to look at using the CallDLL function. The userlibs system that's more commonly used to inteface with DLLs is a compile time system (like the Include command) so it can't be altered once the code is compiled. And obviously you'll need a language such as C++, Purebasic, etc that can compile a DLL file. Blitz3D can't be used to make DLL files.

Sounds like you're trying to run a marathon before you've learned to walk though. I'd avoid all this comlex stuff for your first projects and just focus on small, simple, achievable projects.


RemiD(Posted 2015) [#14]
To scan directories, list files, you need to learn about the functions related to directory and file :
http://www.blitzbasic.com/b3ddocs/command_list_2d_cat.php?show=File
http://www.blitzbasic.com/b3ddocs/command_list_2d_cat.php?show=File/Stream


Rroff(Posted 2015) [#15]
@Zethrax yeah a command line system that is central to the whole game with the ability to utilise calldll is the optimal solution for B3D and exactly what I did - there is also a tiny C compiler someone made I forget the details that can run inside a B3D program and compile in memory, etc. which could be a useful way as well - people could just create "scripts" using standard C.


Dan(Posted 2015) [#16]
@EpicElrod, it is possibile to Load everything from a folder, if your game logic is programmed to use it.

for example.

You have a game whith following directory system


So from the in game menu, the user would choose a mod to use, and
then the game would simply load the same data from the mods folder.

But for more specific answer, it would be nice to know which type of game
are you writing.