Closed Diarandor closed 8 years ago
The behavior of this script is... odd. @Diarandor, would you mind looking and seeing if I did it right?
I can pick up the object fine, but when I drop the object it "sticks" to the hero and follows me around. I can try to pick it up again but it immediately drops to the ground.
I think it may have something to do with the check_on_ground() routine that I see you've moved into a map metatable (which I'd rather not do). I tried to use the old version, since I see that your new one uses features of 1.5 and I was getting errors.
You should not use the new scripts of my repos. The one in Diarandor/portable_entities is too old (it is the one you modified to obtain the script that you got to work), so that one is useless. And the other one in Diarandor/repository is the one I use for the 3 hero system, which contains unnecessary features for your game and may produce incompatibilities and errors; if I understood correctly you have used that repository to update your file, and if that's the case you should revert that change to the version you had where this worked fine. It was not my intention you to be updating your repo with that code...
I was planning to modify my code in Diarandor/repository directly to make it compatible with your game and then make a pull request into your repo, to avoid giving you a headache, since I am the only one that fully understand that code with all the details. I think I can do it before the end of the next month (I can also test it when it is done using a fork of your repo).
Okay, sounds good! Sorry I misunderstood.
Reverted in commit a0b5e54
I did not have much time last months. I think I will wait for the v1.5 release before making these improvements for your scripts. With the new function "entity:get_facing_entity()" we can get rid of one or two of my scripts.
Sounds good!
I have news. I did not find the problem that did not allow to lift again the entities, but that does not matter since I have rewritten part of the code and it works again. The new version uses the new built-in function "entity:get_facing_entity()" of Solarus 1.5, which allows to get rid of both two secondary scripts we were using; in addition, now we have to make the hud interaction icon to work separately using the function "entity:get_facing_entity()" to detect portable entities and show the "lift" icon if necessary (I have not done this in my repo yet). Another good thing is that the new script allows much more customization. When I finish this in my repo I will try to update your repo with the new version.
For the hud part (which is now independent from the generic_portable.lua script) I did the following. This is the check() function I use in my action_icon script:
function action_icon:check()
-- Use this for custom action effects.
local hero = game:get_hero()
local interaction_entity = hero:get_facing_entity()
local interaction_effect = interaction_entity and interaction_entity.action_effect
-- Check if something has changed.
local effect = game:get_command_effect("action")
or game:get_custom_command_effect("action")
or (game:is_paused() and "pause")
or interaction_effect -- Show custom interaction effect.
if effect ~= action_icon.effect_displayed then
action_icon.effect_displayed = effect
action_icon:update_icon_sprite() -- Update icon sprite.
action_icon:rebuild_surface() -- Rebuild surface.
end
-- Schedule the next check.
sol.timer.start(game, 50, function()
action_icon:check()
end)
end
You can do something similar (just copy-paste the code and modify it if necessary). Note that, for any type of entity, if you set:
entity.action_effect = "PUT_STRING_FOR_SOME_EFFECT_HERE"
you can customize what the hud shows, so this is more general for any type of interaction.
You're awesome Diarandor! :) It seems to work perfectly for me!
Another thing I forgot to mention: the new script uses an animation fix of the stopped and walking animations (a direction fix is defined too), so there is no need of having tunic sprites for the "custom carrying". You may find many other uses for these fixing functions when using weapons, etc.
I had already changed your code to avoid duplicate tunic sprites - I see that you noticed and already changed that code :) I definitely think the new code is cleaner though!
There will be new versions of the scripts (I do not know when I will do them). At least for the file save_between_maps.lua. The aim will be to make them independent scripts that can be added to any quest with no need of modifying other scripts; these might be added to the sample quest. For that purpose, I will be using this script that christopho made this week, which allows to add more code to an existing event of some entity as many times as we want: https://github.com/christopho/solarus-alttp-pack/blob/dev/data/scripts/multi_events.lua
Update generic_portable script to a new one with cleaner code and more customization. I can do this in the future, but not yet.
Another important thing:
There is a timer with loop in the script (in the function "entity:start_checking_ground()"), which is used to check/detect the ground to make the entity fall if necessary. I realized that, in the new version of my script, this timer was being created again each time you throw the entity, but the old one is not stopped, and this happens each time you throw the entity increasing the number of timers. I think that this is happening too with your version (although it is older than mine, and slightly different).
Deleting line 195 should solve the problem. It's this line:
entity:start_checking_ground() -- Restart the timer to check ground once per second.
Just check, after deleting the line, that portable entities still can fall on holes/water/lava grounds.