Carrying custom entities

Started by Diarandor, July 27, 2015, 05:07:47 AM

Previous topic - Next topic
Ok, I think the new script is working now (I have tested it this time), sorry for the problems.

The problem was that I forgot to save/load the "is_independent" property when the entity was saved. It was working for me because for a "specialized" portable entity with the "independent property", I usually start the script with this:

local entity = ...
sol.main.load_file("entities/generic_portable")(entity)

entity.is_independent = true -- I PUT THIS HERE INSTEAD OF THE MAP SCRIPT.
... -- ETC.

so I didn't need to save/load the "entity.is_independent" value. Can you confirm that the new script is working for you?
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

Error: In on_map_changed: [string "scripts/save_between_maps.lua"]:122: attempt to index field 'active_maps' (a nil value)

Maybe I am wrong, but I think you copied the wrong file. I have two repositories, the one for my game, and the one with the simplified scripts to carry custom entities (for other people, including you). The variable "active_maps" of that error does not appear in the simplified script in:
https://github.com/Diarandor/portable_entities/tree/master/scripts
which is the one you have been using before. Can you try the new script?
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

Yeah, you're right. I was using the correct repository all the other times, this last time I just followed the wrong link.

The script works perfectly, but only if the entity.is_independent is set when the entity is created. Putting self.is_independent in the on_custom_created() of the custom entity script doesn't result in an independent entity (it's recreated in the same spot and doesn't persist when left in a new map).

That's very strange, it should work with "self.is_independent = true" inside the on_custom_created() event. Is that event being called? You can check it playing some sound. Maybe the name of the event "on_custom_created" or the variable "is_independent" are not correctly written, can you check them?
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

Sorry, it works. I was still using the wrong model (generic_portable) instead of the new custom entity.

That's good news.

If you want, I will explain what I do to allow pushing custom entities which are buttons using some generic portable entities. (I usually set a property "entity.can_push_buttons=true" in the specialized script.) You will need the script of the button.

Also, we will need to add a custom event to the throw function, to add a collision test to the metal ball when it is falling, and remove the collision test when it has fallen. This will be useful to hurt enemies and destroy other objects if we create the metal ball of Link's awakening.
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

Another suggestion. When the player leaves the level, we should delete the info of the metal ball from the corresponding list with game.independent_entities[metal_ball_id]=nil, so when the player enters the level the ball is created at the initial position again. That behaviour is maybe the best one. We can use the teleporter of the exit of the level to do that.
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

Didn't you mention you were also working on (or wanted to) allowing enemies to lift these custom entities?

Yes, but I haven't done that yet. It can be done if we modify the generic_portable.lua script, but I don't have time this month to work on this. I will try to implement that sometime soon.
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."