Skip to content
This repository has been archived by the owner on Jun 7, 2018. It is now read-only.

Allow custom entities to have a custom model path. #523

Closed
ekureina opened this issue May 24, 2014 · 4 comments
Closed

Allow custom entities to have a custom model path. #523

ekureina opened this issue May 24, 2014 · 4 comments

Comments

@ekureina
Copy link
Contributor

As of now, entities have no way to declare where the model is. This poses a problem for ekureina/libsolarus-mudora#1 and the library support that is enabled in lib.lua (in that repository). How does the game load an entity by model? That might be a barrier to this.

@christopho
Copy link
Collaborator

I'm not sure I understand the probem. If a custom entity wants to use external code, just import the external code and call it. For example, assume that there is some external code for an arrow (for the bow) in a separate lib. You can call the lib from a map script with something like:

local some_lib = require("some_lib")
some_lib.make_arrow(my_custom_entity)

where my_custom_entity is a custom entity previously created (possibly from the editor).

If you want the entity to be usable on several maps more easily, you can create the following custom entity model script in data/entities/arrow.lua:

local arrow = ...
local some_lib = require("some_lib")
some_lib.make_arrow(arrow)

And this script will be called for all custom entity that have this model. So models are just a way to avoid repeating code on each map that has the same kind of custom entity. This works exactly like enemies.

For me, the library does not care about whether the user wants a model or not. It takes a custom entity as parameter and initializes with properties and callbacks of an arrow.

For the particular case of arrows, a model is probably not necessary. You will typically create an arrow from only one place (the bow script), never from the editor or from another script. Models are more useful for entities that have to be placed repeatedly on lots of maps with the editor. An example of such entities are the stakes that have to be pushed with the hammer.

In my opinion, the library should not focus only on custom entities. It should also provide common items, common menus, etc.

@ekureina
Copy link
Contributor Author

Does the engine look for the entity in specifically the quest's directory, or also common lua paths, for entities/model_name.lua?

@christopho
Copy link
Collaborator

Only require() looks in common Lua paths. The map, enemies, items and custom entity scripts are loaded in the quest directory or in the savegames directory. Maybe these scripts should be loaded using require() too somehow? I will think about that.

@ekureina
Copy link
Contributor Author

ekureina commented Jun 4, 2014

I have an alternate solution that does not require an engine change.

@ekureina ekureina closed this as completed Jun 4, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants