Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - Diarandor

#961
Development / Re: Trying to change key binding
August 24, 2015, 09:54:59 PM
I think that is normal because to set the command binding you need to use game:set_command_keyboard_binding(command, key).
(You are using the getter function and not the setter.) It is not necessary to call the event game:on_character_pressed(key). Try to write somewhere in the game manager

game:set_command_keyboard_binding("attack", "e")

That should probably work, although I haven't tested this code.
#962
Development / Re: How to configure the joypad?
August 22, 2015, 02:24:57 PM
Thanks a lot! It worked. Currently, I am using just:

-- Configure some joypad buttons.
game:set_command_joypad_binding("action", "button 10")
game:set_command_joypad_binding("attack", "button 11")
game:set_command_joypad_binding("item_1", "button 12")
game:set_command_joypad_binding("item_2", "button 13")

Although, as you say, the number of the keys will be different for other joypads. (But maybe this works for all microsoft joypads.)
#963
Development / How to configure the joypad?
August 21, 2015, 11:43:36 PM
Hi! I am using a joypad of microsoft (of the Xbox360). I would like to set a default configuration like this:
A = "attack", B = "action", X = "item_1", Y = "item_2", Start = "pause", Analog-stick = directions.

The start button and the analog stick work by default as I want. What should I do to set the behaviour of the other keys to call the corresponding commands? Is there already some example to do this? (I would like to associate the buttons of the joypad to the commands, avoiding to define a casewise function on_key_pressed(key), if possible.)

I have read the Lua API but I did not find a short way to do it. Also, I don't know which "keys" are the ones associated to the buttons A,B,X,Y. Could you help me?  :-\
#964
I don't understand exactly what you mean by implementing entity:get_position(other). Maybe what you are looking for is the function entity:set_position(x, y, [layer]). You can find it here:
http://www.solarus-games.org/doc/latest/lua_api_entity.html
(Look on the links on the left of the Lua API website, where you can choose other types of objects to see their funcions.)
#965
It's still untested (I hope it works), and maybe useless for most of you. But anyway, here it is. (Put it in the script collision_test_manager.lua)

local game = ...

--[[
This script is used as a workaround to be able to delete only one collision test on a custom entity.
To use it write the following in the game manager:
sol.main.load_file("scripts/collision_test_manager.lua")(game)
--]]

-- Add a collision test to an entity. Assign a name to reference to it, in case we need to stop it later.
function game:add_custom_collision_test(entity, name, collision_test, callback)
  -- Create the list of collision tests if necessary.
  if not entity.custom_collision_tests then entity.custom_collision_tests = {} end
  -- Store the info of the collision test.
  local info = {collision_test = collision_test, callback = callback}
  entity.custom_collision_tests[name] = info
  -- Create the collision test (the engine does it).
  entity:add_collision_test(collision_test, callback)
end

-- Restart custom collision tests.
function game:restart_custom_collision_tests(entity)
  -- Stop all collision tests (done by the engine).
  entity:clear_collision_tests()
  -- Re-create all the collision tests stored on the list.
  for _, info in pairs(entity.custom_collision_tests) do
    entity:add_collision_test(info.collision_test, info.callback)
  end
end

-- Remove a collision test of an entity of a given reference name.
function game:clear_custom_collision_test(entity, name)
  -- Remove info of the collision test from the list.
  entity.custom_collision_tests[name] = nil
  -- Restart collision tests.
  game:restart_custom_collision_tests(entity)
end
#966
I requested for this feature in https://github.com/christopho/solarus/issues/743. Anyway, I got an easy idea that I will try to use to simulate this, as a workaround, using a script. I want to share the idea:

First, we create a function game:add_custom_collision_test(entity, collision_test_type, callback), which adds all the info of the collision test to the list "entity.custom_collision_tests = {}" (storing the variables collision_test_type and callback), and at the same time creates the collision test with the function of the engine. This function would return the "key" of the list where the info of this collision test is stored (so we can recover the info of the collision test with "entity.custom_collision_tests[collision_test]" where collision_test is the "key").

Then, with other function called game:clear_custom_collision_test(entity, collision_test) we would first clear all collision tests, set to nil the info of the collision test (with "entity.custom_collision_tests[collision_test] = nil"), and re-create again all the other collision tests with the info which remains in the list.

Anyway, if this function is implemented someday in the engine, I will delete my script.
#967
I had a similar problem sometimes. But then, one day I realized that when I copy-paste some entities of the map, I was pasting the entities on the "Description" field of the map. ;D ;D ;D

This was in part due that when you change from the tab of one map to another, the focus of the cursor (where you write) goes to this "Description" box, so one could casually paste the "entity" there, which gives an error, and sometimes the quest does not even run. This is surely your problem.

I suggest to change that behavior when changing maps, so that the cursor focus goes the map and not to the description. Maybe we should open an issue in Github.
#968
It should be possible. Check this,
http://www.solarus-games.org/doc/latest/lua_api_map.html#lua_api_map_get_location
where it says "The engine uses this information to implement scrolling between two adjacent maps."
#969
I suppose you have chosen "side of the map" as the destination, in the map editor. If you use this type of destination with maps of different size, you may get problems like this. (In your case, the engine is sending the hero to a point with the same y-coordinate, which is measured from the top of the map, of the new map.)

To do what you want, you can either send the hero to a destination entity (place it where you want the hero to appear and choose it instead of "side of the map" in the editor), or use separator entities in a big map that contains the three rooms.
#970
I have now realized that, if you start a timer inside a collision test, then the collision test cannot be called again until the timer stops. (Or maybe I did something wrong...) Is this intended? Does this mean that we need to wait the callback to finish until we can activate again the collision test?

Edit: I found that was caused by a silly thing of my script...  :D There is no problem with the collision tests.
#971
Development / Re: Dialog problems
August 19, 2015, 09:39:02 PM
In line 11, instead of "oldman_helped_4B = true", try to use "game:set_value("oldman_helped_4B", true)". That will probably work.
#972
I put a summary of the conclussions I got and a possible solution for my problem:

There is no bug. The problem was that, in the event game:on_command_pressed(command), I was defining an action which is activated when the action effect is nil, which was obstructing the event custom_entity:on_interaction() since it does not change the action effect. Also, Christopho told me that the test for the on_interaction() event is the same that for the collision test of type "facing", so no new method is needed.

A solution for my problem would be the following. First, we use a collision test of type "facing", which notifies the hud by changing some custom action effect variable. (This action effect should be restored to nil when necessary, if the hero stops facing the entity, which can be done using a timer.) Then, in the custom action effect variable we have the info that this interaction can be started, which can be used in the event game:on_command_pressed(command) to start this action instead of the predefined one for the case when there is no action effect defined by the engine.
#973
Hi, I am trying to use the event custom_entity:on_interaction(), but nothing happens. I put a sound inside the event but it is not played when I press action command facing the custom entity. I have tried with traversable and non-traversable custom entities. I am aware that this was in the list of fixed bugs in version 1.2.1, so maybe I am doing something wrong (but it still could be a bug).

Also, since the hud does not show any dialog when the hero is facing the custom entity (which is probably intended since the action is not neccesary "talking", it could be anything, so I suppose that the engine does not change the effect of the action command), it would be nice to have a function to notify the hud that the event custom_entity:on_interaction() can be activated. This could be done with an event called "custom_entity:on_interaction_possible()", which is called when the hero can interact with the custom entity.

I point out that using collision tests to notify the hud that the hero can interact with the custom entity would not be perfect, since the test would not be the same that the engine uses, so it could happen that the hud is notified when the interaction is not possible or that the hud is not notified when interaction is possible.

PS: I have created two issues on Github:
https://github.com/christopho/solarus/issues/741
https://github.com/christopho/solarus/issues/742
#974
Development / Re: Carrying custom entities
August 15, 2015, 07:51:13 PM
However, my code is still not very clean and some functions are missing (to allow carry items to another map, for instance, but I am working on it). Another problem is that I have several scripts interacting (one of them is the one I use to switch between the three main heroes), so the code is a bit spread and not very usable for other people, unless you modify it a lot. Currently, I am improving/simplifying the code, and making the scripts more independent, so maybe other people could use the script. (If I get something more useful for others, I will add it to the LibSolarusMudora repository.)
#975
Development / Re: Carrying custom entities
August 15, 2015, 04:33:59 PM
Hi! My scripts are now working perfectly with Solarus bugfix 1.4.3, thanks to Christopho. (The shadows of my custom entities of type generic_portable, which can be carried, are now removed without crash after falling on the ground.) Some of you could use these scripts as a workaround until the day that the engine will allow to carry custom entities (if you are successful in understanding my code to modify and simplify it, which is not easy).

I have updated my repository with some new scripts and updated old ones in: https://github.com/Diarandor/