Note: This is an automatic translation from Russian. It looks good enough, but there may be inaccuracies. We are sorry for the inconvenience.

The article Getting Started already covers the required dependencies if you prefer not to use a ready-made Visual Studio project. Here we note a couple more features that must be taken into account when developing a game, regardless of which version of the TeravQuest library you downloaded.

[Serializable] Attribute

This has already been discussed many times in a series of articles on creating a demo game. All new reference types like classes, structs, enums, etc. must be marked with the [Serializable] attribute. For the mechanism for saving and loading the game, TeravQuest uses binary serialization of objects. The [Serializable] attribute indicates that objects of this class can be serialized.

Delegates and lambdas

This topic is also related to serialization. Due to the peculiarities of the .NET Core 3 platform, it is not possible to use delegates as fields of serializable classes, since they are not serialized in this version of the platform. Therefore, if you write a class that represents any entity of the game and some of its fields are delegates, when you try to save the game, you will get an exception.

For the same reasons, it is not possible to use lambda expressions for action handlers in the game. Consider the following example:

This is the usual addition of an action to a location, as in previous articles. Since the ToForest method contains only one line, you might want to do this:

In this case, after saving and loading the game, you will get an exception when you click on this action.

As you can see, the TeravQuest library itself does use delegates, since when creating actions and when passing the necessary handler to the constructor of the Option class, the corresponding method represents an ActionHandler delegate, the description of which can be found in the API. Otherwise, creating actions would be more cumbersome and would require writing additional classes. However, the TeravQuest library implements reflection-based mechanisms for storing information about delegates and restoring them after loading the game. But it is impossible to recover information about lambdas in this way, since they are, in fact, anonymous functions.

Relative paths in HTML

As you can see, in C# code you can safely use relative paths to game resources. For example the path to the audio file:


However, relative paths are not perceived by the component that is used in game panels to display content. Therefore, if, for example, you want to add an image to a location, the following will not work:

Content += "<img src='\\images\\img.jpg' style='width:100%'>";

To load the picture, you must specify the absolute path to it. For this, you can use, for example, Environment.CurrentDirectory:

Content += $"<img src='{Environment.CurrentDirectory}\\images\\img.jpg' style='width:100%'>";