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 - MetalZelda

#526
if I set a custom speed on the hero, let's say 20, before going on a shallow water terrain type, the hero would slow down, which is normal, the engine runs a algorithm to slow down speed a bit on shallow water, but if you set another speed while on shallow water, the new speed is only set when you're not on the shallow water terrain, same thing happen while in water, you need to press action (swim) or go on another solid terrain to update the new speed

You can reproduce this glitch with the debug keys.
#527
Just to be clear, this is NOT MY PROJECT, I found it on Youtube, it is stated to be made with Solarus.
https://www.youtube.com/watch?v=uVt3gd9XWr4
This is a nice start
#528
Issue tracking bellow

Hi

I'm quite stuck with a problem with items, I'm currently working on a new bow mechanism. I'm stuck with a problem.
I'm trying to get where the item is assigned (slot 1 or 2) by getting it's keyboard key (I'm using on_key_pressed, on_command_pressed freeze the hero  ???

Code (lua) Select
function game:on_key_released(key)
local map = game:get_map()
local hero = map:get_hero()

local bow_state = game:get_value("bow_state")
local can_fire = game:get_value("can_shoot")

if key == "x" and bow_state == 1 and item:get_amount() == 0 and can_fire == true and not game:is_suspended() then
hero:set_tunic_sprite_id("hero/item/bow_shoot_tunic1")
sol.audio.play_sound("/items/bow/no_arrows_shoot")
hero:freeze()
-- can't shoot arrows, but reset to state 1
sol.timer.start(100, function()
    game:set_value("bow_state", 1)
game:set_value("can_shoot", false)
hero:set_tunic_sprite_id("hero/item/bow_moving_free_tunic1")
hero:unfreeze()
game:set_pause_allowed(true)
end)
elseif key == "x" and bow_state == 1 and item:get_amount() > 0 and can_fire == true and not game:is_suspended() then
hero:set_tunic_sprite_id("hero/item/bow_shoot_tunic1")
shoot_arrow()
hero:freeze()
sol.timer.start(100, function()
game:set_value("bow_state", 1)
game:set_value("can_shoot", false)
hero:unfreeze()
hero:set_walking_speed(40)
hero:set_tunic_sprite_id("hero/item/bow_moving_free_tunic1")
game:set_pause_allowed(true)
end)
end
end


I'm trying to get the corresponding key where the item is assigned to replace the gross if key == "x" but it's kinda messy, Christopho suggested to me this code where the game retrieve info from the item but it's a mess too. I already tried a condition where the key value = x or v depending on the i value, but only x works, v doesn't, and if i print the value, the number I got is 1, even for the item in slot 2

Code (lua) Select
function game:get_item_slot(item)
for i = 1, 2 do
  if game:get_item_assigned(i) == item then
  return i
end
return nil
#529
You can desactivate a entity / layer on the Quest Editor

that mean, if your hole is on 1st layer, and the ground on the 2nd,or if there is a entity on the hole desactivate the 1st one and the entities, and ctrl select everything.
or, just ctrl all the things and on the tile you want to deselect, hold down CTRL again and deselect it, simple


#530
Development / Re: Camera zooming function ?
October 20, 2015, 12:33:57 AM
Quote from: zutokaza on October 19, 2015, 07:53:46 PM
Ah, so you want the ability to zoom in on the map. Maybe a screen scroll with a twinkle would be easier?

map:get_ground(x, y, layer)

map:get_camera_position()

Those might help you out. I'd check the documentation.
http://www.solarus-games.org/doc/latest/lua_api_map.html#lua_api_map_get_camera_position

Hmmm, I already know these, but the zooming function is something a bit more technical since it's function is to rescale each graphical, physical and logical elements on the map by increacing / decreasing the field of view (width and height view)
I might try soon to write the zoom script
#531
Development / Re: Camera zooming function ?
October 19, 2015, 05:27:27 PM
Quote from: zutokaza on October 19, 2015, 04:32:34 PM
To zoom in and out you? CTRL + Mouse wheel

I already know about this, the script I presented in the OP is a script that allow zooming on the map in-game, not on the editor
#532
Development / Re: Help? :/
October 18, 2015, 06:38:44 PM
If you have some knowledges in RUBY, it might be much easier to learn.
#533
Quote from: Diarandor on October 17, 2015, 12:23:15 AM
There are still some problems in your code.

First, you wrote "game:get_value("small_key", chest_savegame_variable)". But, the function "get_value" has only 1 parameter, so you should have something like :
"local open = game:get_value(chest_savegame_variable)".

Also, you wrote "game:set_value("small_key", chest_savegame_variable)", which is not what you should write. The first parameter must be the variable name, which in this case is the string stored in "chest_savegame_variable". The second variable should be the local variable "sk_chest" (I recommend you to set it as the boolean true when the chest has been opened). You will have something like:
"game:set_value(chest_savegame_variable, sk_chest)"
(I would use "open" or "is_open" for the name of the local variable where you store the boolean, instead of "sk_chest".)

With all of these changes you should be able to repair the script.

EDIT :

Finally it works, Thank you Christopho and Diarandor for your help !
#534
Quote from: Diarandor on October 16, 2015, 11:52:10 PM
Ok, I was wrong. The code to get the map name is actually "entity:get_map():get_id()". That will solve the problem. Sorry for my mistake.

Now you can use something like:

local chest_savegame_variable = "chest_".. map:get_id() .."_".. x_coordinate .."_".. y_coordinate


The same issue occurs, if I open 1 chest, the others are stated as "open" too while they shouldn't

Here is the issue documented in video :

https://www.youtube.com/watch?v=dNfP2sjp_bI&feature=youtu.be
#535
Quote from: Diarandor on October 16, 2015, 11:03:02 PM
I don't know what is producing that error, but maybe you did something wrong with the map_name variable. Could you post the new version of your script?
Anyway, I realized that you already had the name of the map stored in the variable "map", defined at the begining of the script.

this is the "new" script, the error occurs at line 5 (local chest_savegame_variable)

Code (lua) Select
local entity = ...
local game = entity:get_game()
local map = entity:get_map()
local x_coordinate, y_coordinate, layer = entity:get_position()
local chest_savegame_variable = "chest_" .. map .. "_" .. x_coordinate .. "_" .. y_coordinate
local hero = entity:get_map():get_entity("hero")
local sk_chest = game:get_value("small_key", chest_savegame_variable)

-- Hud notification
entity:add_collision_test("touching", function()
   if sk_chest == nil and hero:get_direction() == entity:get_direction() then
    game:set_custom_command_effect("action", "open")
   else
    game:set_custom_command_effect("action", nil)
   end
end)

function entity:on_created()
  self:set_drawn_in_y_order(true)
  self:set_can_traverse("hero", false)
  self:set_traversable_by("hero", false)
   if sk_chest then
    self:get_sprite():set_animation("open")
   end
end

function entity:on_interaction()

local volume = sol.audio.get_music_volume() -- used later
local x,y = entity:get_position()
local hero = entity:get_map():get_entity("hero")

  if hero:get_direction() == entity:get_direction() and sk_chest == nil then
       if entity:get_direction() == 0 then --right
           hero:set_position(x-16, y)
       elseif entity:get_direction() == 1 then --up
           hero:set_position(x, y+16)
       elseif entity:get_direction() == 2 then --left
           hero:set_position(x+16, y)
       elseif entity:get_direction() == 3 then --down
           hero:set_position(x, y-16)
       end

hero:freeze()
game:set_pause_allowed(false)

    sol.timer.start(1,function()
            hero:set_animation("drop")
    end)

    sol.timer.start(200,function()
           if hero:get_direction() == 3 or hero:get_direction() == 1 then
            hero:set_animation("stopped")
           else
            hero:set_animation("grabbing")
           end
    end)

    sol.timer.start(300,function()
           if hero:get_direction() == 0 or hero:get_direction() == 2 then
            hero:set_animation("stopped")
           end
      self:get_sprite():set_animation("open")
      sol.audio.play_sound("/common/chest_open")
    end)
     
    sol.timer.start(600,function()
    hero:set_animation("stopped")
    if hero:get_direction() == entity:get_direction() then
       if entity:get_direction() == 0 then --right
           hero:set_direction(3)
       elseif entity:get_direction() == 1 then --up
           hero:set_direction(2)
       elseif entity:get_direction() == 2 then --left
           hero:set_direction(3)
       end
      end
     end)

    sol.timer.start(750,function()
    hero:set_animation("chest_holding_before_brandish")
    end)

    sol.timer.start(1500, function()
      hero:unfreeze()
      hero:start_treasure("small_key")
      hero:set_animation("brandish_alternate")
      game:set_pause_allowed(true) -- restore pause allowed
      hero:set_direction(entity:get_direction()) -- restore direction
      game:set_value("small_key", chest_savegame_variable)
    end)


    elseif sk_chest == nil then
      game:start_dialog("gameplay.cannot_open_chest_side")
end
end



#536
Quote from: Diarandor on October 16, 2015, 09:29:27 PM
You can put a unique name for each entity in the map editor, so that each savegame variable would be different and that would solve your problem (but this would be a lot of work). The best solution is to include the (x,y) coordinates of the chest as part of the asociated savegame variable. You can concatenate something like:

local chest_savegame_variable = "chest_" .. map_name .. "_" .. x_coordinate .. "_" .. y_coordinate

This is also useful when you open the savegame file (which has the saved values for each savegame variable), because you can know which is the chest corresponding to each variable.

Edit: to get the map name and the entity position you can use:

local map_name = entity:get_map()
local x,y,layer = entity:get_position()


hmmm, strangely I got a "attempt to concatenate local 'map_name' (a user value)"
#537
Struggling so hard to get these to work, for the value, is there a way to retrieve the entity name info from the map ? entity:get_name(match("^small_key_chest_([1-9])$")) doesn't work and map:get_entity() too

edit :

entity:get_name() as value work but all chests do have the same state, thats why I ask if it is possible to get the info straight from the entity's name on the map
#538
Quote from: Christopho on October 16, 2015, 04:48:34 PM
It is easy: game:set_value("my_variable", value)
See http://www.solarus-games.org/doc/latest/lua_api_game.html

Oh yeah I completly forgot this one, shame on me, I'm gonna try with map:get_entity_name(entity) and map:get_id() as value
#539
Quote from: Christopho on October 16, 2015, 04:21:21 PM
You mean it resets when you leave the map and come back?
You should save its state in the savegame then. You need a unique name of savegame variable for each chest: a way to obtain one is to concatenate the map id and the name of the chest.

Yeah exactly it resets ^^

Hmmm, seems a bit complicated, is there any dedicated tutorial or such ?
#540
Quote from: Christopho on October 16, 2015, 04:04:09 PM
You never declared open as a local variable to your custom entity script, so it is a global value.

I do already tried to declare open as a local variable, but this time the chest resets even if it was open , I also trien to add a function to store the chest state on on_map_change, same thing occurs.