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.


Messages - Maxs

Pages: [1] 2
1
Development / Re: Trouble porting a script
« on: June 25, 2017, 06:35:43 pm »
I don't think that there are a Lua equivalent to the next statement of Ruby, but you can easily reproduce this with a variable.

For example :

Code: Ruby
  1. for i in 0...@xy_pos.size
  2.   if (condition)
  3.      next
  4.   end
  5.   # rest of the code
  6. end
  7.  

becomes :

Code: Lua
  1. for i = 1, #items do
  2.   local to_next = false
  3.   if (condition) then
  4.      to_next = true
  5.   end
  6.  
  7.   if not to_next then
  8.     -- rest of the code
  9.   end
  10. end
  11.  

2
Your projects / Re: Path to Official Debian Package
« on: September 15, 2016, 06:27:55 pm »
because there was no .desktop file.

There are already a .desktop file in the solarus-quest-editor repo. ;)

I use it for the ArchLinux package in PKGBUILD.

3
If you choose LaTex (or something else that uses files that can be read in clear), it will be a good idea to create a git repository.
So the book could be maintained more easily (branch for manage versions, issues, team work, etc ...).

4
Development / Re: Question about dynamic tiles
« on: September 05, 2015, 03:50:34 pm »
If you want to use my script with solarus 1.4, you can remove the code that check for entities in the game:can_dig(x, y, layer) method. (line 116)

But you need to add code to update the mask when you dig, to not be able to dig in the same place twice.
With something like this (in the game:dig(x, y, layer) method):
Code: Lua
  1. function game:dig(x, y, layer)
  2.  
  3.   -- Check if can dig
  4.   -- Create the dynamic tile
  5.  
  6.   digable_mask[mask_layer][mask_x .. ";" .. mask_y] = nil
  7.   return true
  8. end
  9.  

5
Development / Re: Question about dynamic tiles
« on: September 05, 2015, 07:32:32 am »
I wrote a script to manage the digging ! ;D (but solarus 1.5 is needed)

It provides two methods for the game:
  • game:can_dig(x, y, layer) to check if can digging at the specified position
  • game:dig(x, y, layer) to create a hole with a dynamic tile
And the method digger:on_map_changed(map) that must be called in the game:on_map_changed(map) method.

It uses a 16x16 grid and allows to have different tiles for holes (e.g. for the grass and the sand). To do that you need to specify for each tiles of each tilesets (that allows digging) which tile to use for hole; and you can use the _default value to allow digging where there are no tile. (see the definition of the variable digging_rules in the script)

So here's the script (digging_manager.lua):
Code: Lua
  1. -- Script that manages digable positions and makes holes for the shovel.
  2.  
  3. -- Usage:
  4. -- local digging_manager = require("scripts/digging_manager")
  5. -- digging_manager:create(game)
  6.  
  7. local digging_manager = {}
  8.  
  9. -- Rules for each tilesets that allows to dig.
  10. local digging_rules = {
  11.   ["light_world"] = {
  12.     _default = "grass.under_stone",
  13.     ["grass.soil"] = "grass.under_stone",
  14.     ["grass.weed"] = "grass.under_stone",
  15.     ["grass.weed_big"] = "grass.under_stone",
  16.     ["grass.flower"] = "grass.under_stone",
  17.     ["grass.flower_double"] = "grass.under_stone",
  18.     ["grass.soil.diag.1b"] = "grass.under_stone",
  19.     ["grass.soil.diag.2b"] = "grass.under_stone",
  20.     ["grass.soil.diag.3b"] = "grass.under_stone",
  21.     ["grass.soil.diag.4b"] = "grass.under_stone",
  22.     ["sand.soil"] = "sand.under_stone",
  23.     ["sand.weed"] = "sand.under_stone",
  24.     ["sand.flower"] = "sand.under_stone",
  25.     ["sand.soil.diag.1b"] = "sand.under_stone",
  26.     ["sand.soil.diag.2b"] = "sand.under_stone",
  27.     ["sand.soil.diag.3b"] = "sand.under_stone",
  28.     ["sand.soil.diag.4b"] = "sand.under_stone",
  29.   },
  30. }
  31.  
  32. -- Creates a digger for the specified game.
  33. function digging_manager:create(game)
  34.  
  35.   local digger = {}
  36.   local current_map = nil
  37.   local digable_mask = {[1] = {}, [2] = {}, [3] = {}}
  38.  
  39.   -- Loads the digable mask from the current map.
  40.   local function load_digable_mask()
  41.  
  42.     digable_mask = {[1] = {}, [2] = {}, [3] = {}}
  43.  
  44.     -- Check the map.
  45.     if current_map == nil then return end
  46.  
  47.     -- Get the tileset.
  48.     local tileset = current_map:get_tileset()
  49.     if digging_rules[tileset] == nil then
  50.       return
  51.     end
  52.  
  53.     -- Set default rule for the low layer.
  54.     if digging_rules[tileset]._default then
  55.  
  56.       local width, height = current_map:get_size()
  57.       width, height = math.floor(width / 16), math.floor(height / 16)
  58.  
  59.       for x = 0, width do
  60.         for y = 0, height do
  61.           digable_mask[1][x .. ";" .. y] = digging_rules[tileset]._default
  62.         end
  63.       end
  64.     end
  65.  
  66.     -- Setup an environment to load map tiles.
  67.     local environment = {
  68.       tile = function(tile_properties)
  69.  
  70.         local layer = tile_properties.layer + 1
  71.         local x = math.floor(tile_properties.x / 8)
  72.         local y = math.floor(tile_properties.y / 8)
  73.         local width = math.floor(tile_properties.width / 8)
  74.         local height = math.floor(tile_properties.height / 8)
  75.  
  76.         local tile = digging_rules[tileset][tile_properties.pattern]
  77.  
  78.         for i = 1, width do
  79.           for j = 1, height do
  80.             local mask_x = math.floor((x + i - 1) / 2)
  81.             local mask_y = math.floor((y + j - 1) / 2)
  82.             digable_mask[layer][mask_x .. ";" .. mask_y] = tile
  83.           end
  84.         end
  85.       end
  86.     }
  87.  
  88.     setmetatable(environment, {
  89.       __index = function()
  90.         return function() end
  91.       end
  92.     })
  93.  
  94.     -- Load the map.
  95.     local chunk = sol.main.load_file("maps/" .. current_map:get_id() .. ".dat")
  96.     setfenv(chunk, environment)
  97.     chunk()
  98.   end
  99.  
  100.   -- Call this function to notify the digger that the current map has changed.
  101.   function digger:on_map_changed(map)
  102.  
  103.     current_map = map
  104.     load_digable_mask()
  105.   end
  106.  
  107.   -- Checks whether the specified position can be dug in the current map.
  108.   function game:can_dig(x, y, layer)
  109.  
  110.     if digable_mask == nil then
  111.       return false
  112.     end
  113.  
  114.     x, y = x - (x % 16), y - (y % 16)
  115.  
  116.     for entity in current_map:get_entities_in_rectangle(x, y, 16, 16) do
  117.       if entity:get_type() == "dynamic_tile" and entity:is_enabled() then
  118.         return false
  119.       end
  120.     end
  121.  
  122.     x, y, layer = math.floor(x / 16), math.floor(y / 16), layer + 1
  123.  
  124.     return digable_mask[layer][x .. ";" .. y] ~= nil
  125.   end
  126.  
  127.   -- Digs a hole at the specified position in the current map.
  128.   function game:dig(x, y, layer)
  129.  
  130.     if not self:can_dig(x, y, layer) then
  131.       return false
  132.     end
  133.  
  134.     local mask_layer = layer + 1
  135.     local mask_x, mask_y = math.floor(x / 16), math.floor(y / 16)
  136.     local tile = digable_mask[mask_layer][mask_x .. ";" .. mask_y]
  137.  
  138.     current_map:create_dynamic_tile({
  139.       layer = layer,
  140.       x = mask_x * 16,
  141.       y = mask_y * 16,
  142.       width = 16,
  143.       height = 16,
  144.       pattern = tile,
  145.       enabled_at_start = true
  146.     })
  147.  
  148.     return true
  149.   end
  150.  
  151.   return digger
  152. end
  153.  
  154. return digging_manager
  155.  

The digging_rules of this script is an example based on the alltp pack but you need to modify the light_world.tiles image to add "grass" and "sand" of tiles grass.under_stone and sand.under_stone. (have no transparency to override flowers)

Now, it remains only to write the script of the shovel.  :P

meanwhile here's the script that I've used for my tests (main.lua):
Code: Lua
  1. local digging_manager = require("digging_manager")
  2.  
  3. function sol.main:on_started()
  4.  
  5.   local game = sol.game.load("save")
  6.   local digger = digging_manager:create(game)
  7.  
  8.   function game:on_map_changed(map)
  9.     digger:on_map_changed(map)
  10.   end
  11.  
  12.   function game:on_key_pressed(key)
  13.  
  14.     local map = self:get_map()
  15.     if map and key == "t" then
  16.       local x, y, layer = map:get_hero():get_position()
  17.       self:dig(x, y, layer)
  18.     end
  19.   end
  20.  
  21.   game:start()
  22. end
  23.  

6
Development / Re: Trouble making a bridge.
« on: July 30, 2015, 02:54:38 am »
Do you have put sensors on good layers? And have you noticed that he uses invisible tiles placed on the upper layer to allow the transition?

7
Development / Re: Trouble making a bridge.
« on: July 30, 2015, 01:23:55 am »
Christopho made a bridge in zelda mercuris chest (under development).

You can see an example in `the forest_store` map. He use sensors named `layer_up_sensor` and `layer_down_sensor`, you can find the code to make that in the quest_manager.lua script.

8
Development / Re: Trying to force equip a usable item.
« on: July 29, 2015, 10:17:44 pm »
Ok, the `hero` variable isn't defined here, you need to get it like that:
Code: Lua
  1. item:get_map():get_entity("hero")
So you can replace the line 11 by:
Code: Lua
  1. item:get_map():get_entity("hero"):set_animation("book")

9
Development / Re: Trying to force equip a usable item.
« on: July 29, 2015, 09:56:03 pm »
If you have any problems with the error.txt file, you can always start the engine or editor from a console. If you're on Windows there is an option in the editor settings to display a console at launch.

This way you see all the error messages directly into the console.

10
It is already planned (see issue #39)

11
Development / Re: Trying to force equip a usable item.
« on: July 29, 2015, 09:26:38 pm »
I haven't tested this but I think it should work better like this (you made a few mistakes explained in comments) :
Code: Lua
  1. local item = ...
  2. local game = item:get_game() -- not map:get_game(), map isn't defined here
  3.  
  4. function item:on_created()
  5.  
  6.   self:set_savegame_variable("possession_book")
  7.   self:set_assignable(true)
  8. end
  9.  
  10. function item:on_using()
  11.   hero:set_animation("book") -- this method get a string as parameter, book doesn't exists here
  12.   game:start_dialog("book.test", nil, function ()  -- use the callback function of the dialog to finish after this one
  13.     item:set_finished()
  14.   end)
  15. end

You should see the messages in the error.txt file and learn to determine what it really mean to fix that yourself. ;)

12
Development / Re: Trying to force equip a usable item.
« on: July 29, 2015, 06:16:13 pm »
There is a problem with the `game` variable and I cannot help you more than that with the infos you gave me.

Could you give me a link with all the data of your quest? (Github, Drive, Dropbox, or something else)

13
Development / Re: Trying to force equip a usable item.
« on: July 29, 2015, 03:43:08 am »
I don't understand why the method `get_item` isn't defined in your script, but you can try with this code (in the map script) :
Code: Lua
  1. function map:on_obtained_treasure(item)
  2.   if item:get_name() == "book" then
  3.     game:set_item_assigned(1, item)
  4.   end
  5. end
  6.  
This way the item will be automatically assigned when you retrieve it.

14
Development / Re: Trying to force equip a usable item.
« on: July 29, 2015, 03:27:15 am »
It's weird, it means that this method is not defined in game. However, it is in the API and for me it works very well.

But I have even so a bug because it is necessary to possess an item before assigning it.

I suggest you do it in another way to get your item directly with the map editor, placing it in a chest or on the ground.

15
Development / Re: Trying to force equip a usable item.
« on: July 29, 2015, 02:26:12 am »
Replace (in your map script)
Code: Lua
  1. local game = ...
By
Code: Lua
  1. local game = map:get_game()

The `...` allow to get the arguments passed to the script, so you can only get the map from a map script by this way (the item from an item script, etc).

And for the `equipBook:on_activated` method, I think you need to write something like this :
Code: Lua
  1. function equipBook:on_activated()
  2.   game:set_item_assigned(1, game:get_item("book"))
  3. end

You have defined the method instead of call it and the variable `book` isn't defined, you need to get it by the method `game:get_item`.

Pages: [1] 2