Recent Posts

Pages: 1 [2] 3 4 ... 10
11
Development / Re: Heart Fully Replenished - Help
« Last post by Tulk on Today at 07:50:22 am »
Thank you guys! \o
12
Your projects / Designing the overworld of my quest.
« Last post by brlmnd on June 24, 2017, 03:16:27 pm »
A small part of the village and a one entrance to the woods.

https://www.dropbox.com/s/ulj9lgg4toiasrx/QTV.png?dl=0

Thanks to this wonderful community!
13
Development / Re: Jump movement direction4 error?
« Last post by Diarandor on June 24, 2017, 08:16:57 am »
I found the problem. The problem is that the facing direction will not change because function entity:on_movement_changed() is inside the function entity:on_created().
It is good to see that there is no engine bug this time and all is fixed. (The less bugs it has, the sooner we will have new features added by Chris.  ;D) Yes, we should close the github issue.
14
Development / Re: Jump movement direction4 error?
« Last post by Zefk on June 24, 2017, 07:32:36 am »
Quote
2) This part is really confusing and gives problems:

Ah, I think you are correct about the timer. I will do some tests later. That would not prevent a facing direction change though.

Quote
1) Your events on_interaction() and on_movement_changed() are not called the first time you create a jump, because they are defined inside your function "metatable_entity:jump". These events should be defined outside that function. Although the variable quick_movement is not defined outside the function "jump", you can still access the movement with entity:get_movement().

Everything is defined in my "Entity Create Jump Method" and it works, so I am not sure that is the problem. The only difference is that function self:on_created() is inside the script and the sprite is created by the function instead of being picked from the custom entity.

Code: Lua
  1. -------------------------------------------
  2. --Entity Create Jump Method
  3. -------------------------------------------
  4. function metatable_entity:jump_create(sprite_directory, speed, traversable, set_can_traverse_hero, set_traversable_by_hero, ignore_obstacles, direction8, jump_distance, start_animation, finish_animation, finish_jump_sound, start_jump_sound, sound_timer, dialog, dialog_activation_distance)
  5.  
  6.   local map = self:get_map()
  7.   local hero = map:get_hero()
  8.   local game = map:get_game()
  9.   local sprite
  10.   local quick_movement
  11.  
  12.   --speed default value
  13.   if speed == nil then
  14.     speed = 40
  15.   end
  16.  
  17.   if traversable == nil then
  18.     traversable = false
  19.   end
  20.  
  21.   --By default the entity cannot traverse the hero
  22.   if set_can_traverse_hero == nil then
  23.     set_can_traverse_hero = false
  24.   end
  25.  
  26.   --By default the hero cannot traverse the entity.
  27.   if set_traversable_by_hero == nil then
  28.     set_traversable_by_hero = false
  29.   end
  30.  
  31.   --By default the entity does not ignore obstacles
  32.   if ignore_obstacles == nil then
  33.     ignore_obstacles = false
  34.   end
  35.  
  36.   if direction8 == nil then
  37.     direction8 = 0
  38.   end
  39.  
  40.   if jump_distance == nil then
  41.     jump_distance = 100
  42.   end
  43.  
  44.   --By default the sprite directory is the hero tunic1
  45.   if sprite_directory == nil then
  46.     sprite_directory = "main_heroes/Eldran"
  47.   end
  48.  
  49.   if start_animation == nil then
  50.     start_animation = "jumping"
  51.   end
  52.  
  53.   if finish_animation == nil then
  54.    finish_animation = "stopped"
  55.   end
  56.  
  57.   if start_jump_sound == nil then
  58.     start_jump_sound = "jump"
  59.   end
  60.  
  61.   if finish_jump_sound == nil then
  62.     finish_jump_sound = "jump"
  63.   end
  64.  
  65.   if sound_timer == nil then
  66.     sound_timer = 500
  67.   end
  68.  
  69.   --By default the welcome sign dialog is used.
  70.   if dialog == nil then
  71.     dialog = "welcome_sign"
  72.   end
  73.  
  74.   --dialog_activation_distance default value
  75.   if dialog_activation_distance == nil then
  76.     dialog_activation_distance = 20
  77.   end
  78.  
  79.   function self:on_created()
  80.     sprite = self:create_sprite(sprite_directory) -- sprite_directory
  81.     self:set_can_traverse("hero", set_can_traverse_hero) -- set_can_traverse_hero
  82.     self:set_traversable_by("hero", set_traversable_by_hero) -- set_traversable_by_hero
  83.     self:set_drawn_in_y_order(true)
  84.     self:set_traversable_by(traversable)
  85.  
  86.     quick_movement = sol.movement.create("jump")
  87.     self:get_sprite():set_animation(start_animation) -- animation
  88.     quick_movement:set_ignore_obstacles(ignore_obstacles) -- ignore obstacles
  89.     quick_movement:set_direction8(direction8) --direction8
  90.     quick_movement:set_distance(jump_distance) -- distance
  91.     quick_movement:set_speed(speed) -- speed
  92.     quick_movement:start(self)
  93.  
  94.     sol.timer.start(sound_timer, function() --finish_time
  95.                  sol.audio.play_sound(start_jump_sound) --finish_animation
  96.           end)
  97.    
  98.   end
  99.  
  100.   local set_stop_aniamtion = false
  101.  
  102.   sol.timer.start(450, function()
  103.  
  104.     function quick_movement:on_finished()
  105.       set_stop_aniamtion = true
  106.     end
  107.  
  108.     if set_stop_aniamtion == true then
  109.      sol.audio.play_sound(finish_jump_sound)
  110.                  self:get_sprite():set_animation(finish_animation) --finish_animation
  111.    return false
  112.     end
  113.  
  114.    return true
  115.   end)
  116.  
  117.   function self:on_interaction()
  118.     local distance_check = hero:get_distance(self)
  119.  
  120.     if distance_check <= dialog_activation_distance then -- dialog_activation_distance
  121.       if hero:get_direction() == 0 then
  122.         self:set_direction(2)
  123.         map:get_game():start_dialog(dialog) -- dialog
  124.       end
  125.       if hero:get_direction() == 1 then
  126.         self:set_direction(3)
  127.         map:get_game():start_dialog(dialog) -- dialog
  128.       end
  129.       if hero:get_direction() == 2 then
  130.         self:set_direction(0)
  131.         map:get_game():start_dialog(dialog) -- dialog
  132.       end
  133.       if hero:get_direction() == 3 then
  134.         self:set_direction(1)
  135.         map:get_game():start_dialog(dialog) -- dialog
  136.       end
  137.     end
  138.   end
  139.  
  140.   function self:on_movement_changed()
  141.      sprite:set_direction(quick_movement:get_direction4())  
  142.   end
  143. end

Quote
I can paste a copy of the modified script if you want. It works and the sprite of the custom entity is always facing the direction of the jump, which I believe is what you wanted (otherwise I did not understand your final purpose).

I found the problem. The problem is that the facing direction will not change because function entity:on_movement_changed() is inside the function entity:on_created(). Taking it out results in correct direction change. That means it is not a bug I think. That is the only reason my script does not work for facing direction change.

I declared my function like this and that is why will not work.

function entity:on_created()
   entity:jump()
end

Try it out if you do not believe me.

Code: Lua
  1. local entity = ...
  2. local game = entity:get_game()
  3. local map = entity:get_map()
  4.  
  5. function entity:on_created()
  6.  
  7.     entity:set_drawn_in_y_order(true)
  8.     entity:set_traversable_by(true)
  9.  
  10.     quick_movement = sol.movement.create("jump")
  11.     entity:get_sprite():set_animation("jumping") -- animation
  12.     quick_movement:set_ignore_obstacles(true) -- ignore obstacles
  13.     quick_movement:set_direction8(2) --direction8
  14.     quick_movement:set_distance(100) -- distance
  15.     quick_movement:set_speed(100) -- speed
  16.     quick_movement:start(entity)
  17.  
  18.   function entity:on_movement_changed()
  19.      entity:set_direction(quick_movement:get_direction4())  
  20.   end
  21. end

I will go ahead and close the issue I reported.
15
Development / Re: Jump movement direction4 error?
« Last post by Diarandor on June 24, 2017, 06:09:37 am »
Sorry for my arrogance before, but I am under too much stress these days.
I have now tried the script directly (I didn't before, I had only read the code).

After "cleaning" the code a bit, it works, so I confirm that there is no bug (unless someone can prove that I am wrong  :P).
The problem is just that the script is not well coded, in the following parts:

I tested it with a custom_entity script. There is a line of code missing since "metatable_entity" is not defined, but I guess that it is
Code: Lua
  1. metatable_entity = ...

and in that case "metatable_entity" is not really a metatable in the formal sense (I think).

1) Your events on_interaction() and on_movement_changed() are not called the first time you create a jump, because they are defined inside your function "metatable_entity:jump". These events should be defined outside that function. Although the variable quick_movement is not defined outside the function "jump", you can still access the movement with entity:get_movement().

2) This part is really confusing and gives problems:
Code: Lua
  1.   sol.timer.start(450, function()
  2.  
  3.     function quick_movement:on_finished()
  4.       set_stop_aniamtion = true
  5.     end
  6.  
  7.     if set_stop_aniamtion == true then
  8.      sol.audio.play_sound(finish_jump_sound)
  9.                  self:get_sprite():set_animation(finish_animation) --finish_animation
  10.    return false
  11.     end
  12.  
  13.    return true
  14.   end)
  15.  
If your jump ends in less than 450 ms, the event quick_movement:on_finished() would never be called since it would be defined after the movement has ended. Actually you do not need a timer, and should probably write something like this instead of the above code:
Code: Lua
  1.     function quick_movement:on_finished()
  2.       sol.audio.play_sound(finish_jump_sound)
  3.       entity:get_sprite():set_animation(finish_animation)
  4.     end
  5.  

I can paste a copy of the modified script if you want. It works and the sprite of the custom entity is always facing the direction of the jump, which I believe is what you wanted (otherwise I did not understand your final purpose).

And I insist that having a clean code is more important that it may appear, not only for finding bugs, but also to make the code understandable to others who want to help you.
16
Development / Re: Jump movement direction4 error?
« Last post by zutokaza on June 24, 2017, 02:18:29 am »
I confirm the bug. I got the same problem when I checked this with a custom entity.
17
Development / Re: Jump movement direction4 error?
« Last post by Zefk on June 24, 2017, 01:37:20 am »
If you cannot figure it out by trying my script yourself, then I do not know what to tell you. The script is very simple in my opinion. It is just a bunch of defaults,  self properties, and movement functions. That is if we ignore the stop/start jump sound and interaction part of the script.

The only thing that needs to be looked at is this:
(I would suggest making a custom entity and apply a jump movement to it.)

Code: Lua
  1. function entity:on_created()
  2.     self:set_drawn_in_y_order(true)
  3.     self:set_traversable_by(traversable)
  4.  
  5.     quick_movement = sol.movement.create("jump")
  6.     self:get_sprite():set_animation(start_animation) -- animation
  7.     quick_movement:set_ignore_obstacles(ignore_obstacles) -- ignore obstacles
  8.     quick_movement:set_direction8(direction8) --direction8
  9.     quick_movement:set_distance(jump_distance) -- distance
  10.     quick_movement:set_speed(speed) -- speed
  11.     quick_movement:start(self)
  12.  
  13.   function self:on_movement_changed()
  14.      self:set_direction(quick_movement:get_direction4())  
  15.   end
  16. end

The problem lies with picking the sprite from the custom entity. If this is done, then the custom entity will not face the proper direction when jumping.


If the custom entity sprite is created with code, then the custom entity faces the proper direction. That is all I know.
Code: Lua
  1.  sprite = self:create_sprite(sprite_directory) -- sprite_directory

Why would "only" making the custom entity sprite from script work for the jump movement? I do not understand why the sprite will not face the proper direction when it is picked from the custom entity. That is literally the only major difference between the two scripts I posted previously. I only get this facing direction problem with the "jump" movement. That is why I think it is a bug.

Note:
I did not make this post for the following. (I do however appreciate the tips and advice because I will change my code later.)
1. Report an issue for a debug lesson
2. Shorten my code
3. Shorten the temporary fix.
18
Development / Re: Jump movement direction4 error?
« Last post by Diarandor on June 23, 2017, 07:23:53 pm »
I cannot understand anything. You did not explain properly what you are doing and what is the problem. And there is too much unnecessary information in the explanations.

-The image does not help at all. We cannot even know which entity is the hero, or what you are doing.
-In your explanations I cannot understand "what" is facing "what". All is unclear.
-You should learn to debug properly before we get crazy with your code.

Try this function instead:
Code: Lua
  1.   function self:on_movement_changed()
  2.      print("Movement Direction: " .. quick_movement:get_direction4())
  3.      print("Entity Initial Direction: " .. self:get_direction())
  4.      self:set_direction(quick_movement:get_direction4())
  5.      print("Entity Final Direction: " .. self:get_direction())
  6.   end
  7.  

Now, tell us the printed values that you get in the console, and what really happens in the game when you test it.
(We need more information. But only the useful one.)
I have tested the function custom_entity:set_direction() and it works perfectly for me, at least with the main sprite, so I cannot find functions that work in a wrong way as you say.

If you can write a new script with the MINIMAL and SIMPLEST code necessary to reproduce the bug, that would help a lot.
19
Game art & music / Re: [UDATE] Absolute Hyrule Map Package: ADT Alpha Floor Tiles
« Last post by ffomega on June 23, 2017, 05:55:28 pm »
Thank you so much for the support :)
20
Development / Re: Jump movement direction4 error?
« Last post by Diarandor on June 23, 2017, 05:42:19 pm »
I will try to find out what is the problem.

Anyway, some advices that you should take seriously into account to write better code:

1) This was already pointed out by MetalZelda but you did not change it:
Lines 121-136 of your "Entity Create Jump Method" and lines 174-189 of your "Entity Jump Method" can be shortened in a clearer way with only 2 lines:
Code: Lua
  1. self:set_direction((hero:get_direction() + 2) % 4)
  2. game:start_dialog(dialog)
  3.  
(You were repeating too much code unnecessarily.) If you don't understand the math, just ask.

2) This is just a matter of taste(not so important), but lines like:
Code: Lua
  1.   if speed == nil then
  2.     speed = 40
  3.   end
  4.  
can be also written (in a shorter way) like
Code: Lua
  1.   speed = speed or 40
  2.  
(Check the "or" and "and" operators in the Lua maual for more info.)
Pages: 1 [2] 3 4 ... 10