Scripting many levels

Blitz3D Forums/Blitz3D Programming/Scripting many levels

Grovesy(Posted 2005) [#1]
Hi all,

I'm just wondering how people go about coding the different game levels!

For example setting up triggers, level objectives etc for each level. I guess one way would be to have some sort of scripting language, but this sounds pretty complicated! isn't it?

One idea I had was to just hard code the events of each level. But this would result in a hugh select statement, which will be very inefficant. One way to reduce this inefficancy it to have nested select statements, to allow grouping of levels.

What do you guys think and what do you guys do?

Cheers


jfk EO-11110(Posted 2005) [#2]
You need a level config file. Your game is then absolutely non-hardcoded (as non-hardcoded as possible!), softcoded sotosay. Whatever content it loads, it's taking the file paths, positions, rotations, scaling etc. from the levelconfig file.

This way you can have multiple levels with the same EXE. Just make sure the EXE is also capab le of UNLOADING all content of a level properly, so you can load the next level right away.

Now how is that config file created? I wouldn't write it manually, instead (depending on the kind of game you want to create) you need to build your special Editor that lets you load and organise things for a level and finally save all your actions in the level config file.

In my case I have a FPS game engine. The Level Editor allows to walk around in the main level mesh. From time to time I drop some things, furniture etc. (hence "dropper"). IT works this way: whenever I feel like this place needs say a chair, I hit the right mouse, choose "chair.3ds" fromthe file requestor and zac there it is, a chair. To make this even faster I can use CTRL-C and CTRL-V to copy paste charis, tables, doors and so on.

Every object in my data structure has its position coordinates, Rotation, scaling, color, texture, FX etc. etc. etc. Virtually everything that i would probably need to set the properties of some content.

One additional property is ne so called Action String. It's a string for every object that allows to use some special directives like weapon, key, ammo, medi, bonus, exit etc.

It is then up to the engine to take special actions when the user clicks or shoots those objects with a special action string.

While this method still limits a level to use only a number of possible actions (in re- and interactions), it gives the player the feeling of an individual level.

Just make sure you won't make the same mistake like many publishers: the same goal in every level. That's boring after 3 levels.


Grovesy(Posted 2005) [#3]
Cheers jfk, I did already pretty much understand that part, and infact will probably use the ALE to build my levels and drop my meshes in (as ALE will make a text file containing all the information about the object). but what about triggers and action scripts?

I see you touched on the subject brifely. For example in one level i might want a set of actions like:

Spawn 100 enemies from location x,y,z;
When all ememies are dead spawn 10 enemy vehicles at x,y,z;
When all vehicles are dead, create explosion at x,y,z;
Wait 10 seconds;
Display text "Level complete";

How would one start to implement something like this?

Thanks again


Koriolis(Posted 2005) [#4]
You're looking for a scripting engine. One easy solution (the best solution I'd say, but I'm pretty biased :) )is to use BVM. Check my sig.


cash(Posted 2005) [#5]
I have been using blitz for a while now and also puchased the csp engine (very good)

how do
you read from a text file into Blitz..
Well what I mean is

player=loadanimmesh("the first line from a text file")
ammo=loadmesh("the fourth line from a text file")

what would the syntax be ?


jfk EO-11110(Posted 2005) [#6]
Thanks cash!


That would be something like

re=readfile("players.dta")
player_file$=readline(re)
player_name$=readline(re)
player_party$=readline(re)
closefile re

if filetype(player_file$)=1 ; file exists?
 player(count)=loadanimmesh(player_file$)
 name$(count)=player_name$
 party$(count)=player_party$
 count=count+1
endif


Assuming there is a file named "players.dta" with the following content:

myplayer.b3d
Freddy
Soviet

The file can be created with notepad, or any other tool.

Using ReadLine is very straight forward. You won't have to worry about String delimiters etc. simply use 1 line=1parameter. You can also use numeric values that way, they will be converted from strings to float or int automaticly. This method also allows to open the file in a text editor and alter/check things manually.

Reading things from a file is simple, but you should not put the player and the ammo in an unsorted list. Instead your File(s) need a structure that can be recognized by the engine. There are several methods, one is the fixed LEnght parameter blocks method (that's what I use most times):

There is a number of objects in a list and each block has a fixed number of lines, eg:

mesh path
position x
y
z
pitch
yaw
roll
scalex
scaley
scalez
entityFX
ENtityAlpha


Basicly you should sit down and write your list of parameters you plan to use. It may be a good idea to "wrap" every possible property, simply parse the command reference to see all possible entity Properties. You best add a dozen or so of "reserved" lines to the block structure, for future updates.

Although this method may seem uneconomical, you will only waste a couple of kilobytes after all, it's a straight forward method. simply read all bocks of a file until EOF is reached.

An other method will use variable names and values. This way the blocks may have an individual lenght. But it also complicates things.

FILEPATH
ammobox.3ds
X-LOCATION
312.5
and so on...
END_OF_OBJECT
FILEPATH
crate.b3d
X_LOCATION
...

You see you need to store only the required parameters, Undefined properties may use default values (like EntityFX or EntityAlpha etc.)

So the level items can be positioned easily this way, but I would suggest to use a diffrent, special structure for an entity like Player 1, or AI Bots or Multiplayer Chars etc. Maybe you should even use a seperate File for the player info.


Paolo(Posted 2005) [#7]
JFK,
in your engine, when you throw things into the scene (chairs and so),
how do you handle lightmapping for the whole room and pathfinding for enemies avoiding the furniture?
Thanks!.


Chad(Posted 2005) [#8]
Hey JFK, the CSP engine is available to purchase?? Since when and where do I get it at?


lo-tekk(Posted 2005) [#9]
Hi Grovesy,
i have set up an userlib for Lua scripting language. With this
is absolutely easy to get any values from a file, you don't even have to care about filehandles or amount of lines.
Such a lua file would look like so:
--- screen.ini
screen = { width=800, height=600, depth=16, mode=2 }

Then you call the values from within the file:
Include "BlitzLua.bb"

Function InitGraph3D (state%)
	; Here is the calling code
	LUA_callScript(state, "screen.ini")
	
	scrW = LUA_getKeyInt(state, "screen", "width")
	scrH = LUA_getKeyInt(state, "screen", "height")
	scrD = LUA_getKeyInt(state, "screen", "depth")
	scrM = LUA_getKeyInt(state, "screen", "mode")

	Graphics3D scrW, scrH, scrD, scrM
	SetBuffer BackBuffer()
End Function

luaState = LUA_Init ()
InitGraph3D (luaState)

cube = CreateCube()
light  = CreateLight()
cam  = CreateCamera()

PositionEntity cam,0,0,-10

While Not KeyHit(1)


	TurnEntity cube,0,1,0
	
UpdateWorld
RenderWorld
Flip

Wend

lua_close(luaState)
ClearWorld
End


Get it from www.moonworx.de it's free.

----------------------------------
www.moonworx.de