Recent Posts

Pages: 1 2 [3] 4 5 ... 10
21
Development / [Solved]Array in function?
« Last post by Zefk on May 15, 2017, 06:07:00 am »
I get the following error:
Code: [Select]
0] Error: Failed to load script 'scripts/lib/zefk_entity_lib.lua': [string "scripts/lib/zefk_entity_lib.lua"]:2093: '(' expected near '['
when trying this:

Code: Lua
  1.   function sprites[index]:on_animation_finished()
  2.     sprites[index]:set_animation(end_anime)
  3.     sol.audio.play_sound(end_sound)
  4.   end

The following function will only work if I convert my array to a normal variable.

Code: Lua
  1.     sprites2 = sprites[2]
  2.   function sprites2:on_animation_finished()
  3.     sprites[index]:set_animation(end_anime)
  4.     sol.audio.play_sound(end_sound)
  5.   end

Is there a way around this because I'd like to on_animation_finish() without having a limit set. I do not want to do something like this:

Code: Lua
  1.    
  2.  sprites2 = sprites[2]
  3.   function sprites2:on_animation_finished()
  4.     sprites[index]:set_animation(end_anime)
  5.     sol.audio.play_sound(end_sound)
  6.   end
  7.  
  8.  sprites1 = sprites[1]
  9.   function sprites1:on_animation_finished()
  10.     sprites[index]:set_animation(end_anime)
  11.     sol.audio.play_sound(end_sound)
  12.   end
  13.  
  14.  sprites3 = sprites[3]
  15.   function sprites3:on_animation_finished()
  16.     sprites[index]:set_animation(end_anime)
  17.     sol.audio.play_sound(end_sound)
  18.   end
  19.  
  20.  sprites4 = sprites[4]
  21.   function sprites4:on_animation_finished()
  22.     sprites[index]:set_animation(end_anime)
  23.     sol.audio.play_sound(end_sound)
  24.   end
  25.  
  26.  sprites5 = sprites[5]
  27.   function sprites5:on_animation_finished()
  28.     sprites[index]:set_animation(end_anime)
  29.     sol.audio.play_sound(end_sound)
  30.   end
  31.  
22
Development / Re: hero hurt duration
« Last post by Constantkaos on May 15, 2017, 04:56:16 am »
Just picked up aesprite today you guys are right tjhis program is awsome!!!!!!!!!!!!!definetley the way to go :D
23
Development / Re: Jump movement direction4 error?
« Last post by Zefk on May 14, 2017, 03:51:18 am »
For example, If I set the direction8 to 2 for sprite to jump up and I face him down from the custom entity, then the following script should make him face up.

Maybe a visual explanation will help.


I use this script to change his direction, but it does not work.
Code: Lua
  1.   function self:on_movement_changed()
  2.      self:set_direction(quick_movement:get_direction4())  
  3.   end


1.I set direction8 to 0 for the hero to jump to the right. From the entity I face the entity up. He will jump right while facing up.

Code: Lua
  1.   entity:jump(speed, traversable, ignore_obstacles, 0, jump_distance, start_animation, finish_animation, finish_jump_sound, start_jump_sound, sound_timer, dialog, dialog_activation_distance)

2.I set the direction8 to 2 for the hero to jump up. From the entity I face the entity right. He will jump up while facing right.

Code: Lua
  1.   entity:jump(speed, traversable, ignore_obstacles, 2, jump_distance, start_animation, finish_animation, finish_jump_sound, start_jump_sound, sound_timer, dialog, dialog_activation_distance)

My entity:jump_create() function works. It is 95% identical to entity:jump(). The major difference with entity:jump_create() is that it creates the sprite by script.  I believe that using a sprite from the custom entity with the jump movement causes a facing direction bug.
24
Development / Re: Jump movement direction4 error?
« Last post by Zefk on May 14, 2017, 03:01:56 am »
What I see is, you try to get the direction4, which doesn't exist in the jump movement

You can only get direction8 from a jump movement, which is understandable

http://www.solarus-games.org/doc/latest/lua_api_jump_movement.html#lua_api_jump_movement_get_direction8

So then, to get a 4 direction way, simply divide by 2

I do not understand what you mean. Doesn't the following script make the hero turn depending on the direction the movement is moving? The hero should still face the jumping direction.

Code: Lua
  1.   function self:on_movement_changed()
  2.      self:set_direction(quick_movement:get_direction4())  
  3.   end

Jump movements are particular movement objects. Therefore, they inherit all methods from the type movement.
http://www.solarus-games.org/doc/latest/lua_api_movement.html#lua_api_movement_get_direction4

0 will make the hero jump to the right with the direction8 movement. If I face the hero up from the custom entity and jump, then the hero jumps to the right while facing up. It does this for everything else. I understand that the direction8 is different from the direction4.

Quote
Also in on_interaction, you can save a lot of space by doing

Code: Lua
  1. self:set_direction((2 + hero:get_direction()) % 4) -- Make the entity face the hero
  2. map:get_game():start_dialog(dialog) -- dialog

Thanks for the tip. I will try it out sometime.

Quote
And i maintain, i don't get the on_interaction issue you're facing, so it comes from your code

If this doesn't solve the issue then it have something to do with your code, i'll investigate it tomorrow.

Did you try letting the custom entity move away from the hero after interacting with it? If you move the hero one step, then the bug cancels. If the custom entity is standing still, then you will never get the bug because you will move the hero. Also, this does not happen with an NPC entity. This is kinda off topic.
25
Development / Re: Jump movement direction4 error?
« Last post by MetalZelda on May 14, 2017, 02:36:25 am »
What I see is, you try to get the direction4, which doesn't exist in the jump movement

You can only get direction8 from a jump movement, which is understandable

http://www.solarus-games.org/doc/latest/lua_api_jump_movement.html#lua_api_jump_movement_get_direction8

So then, to get a 4 direction way, simply divide by 2

Also in on_interaction, you can save a lot of space by doing

Code: Lua
  1. self:set_direction((2 + hero:get_direction()) % 4) -- Make the entity face the hero
  2. map:get_game():start_dialog(dialog) -- dialog

And i maintain, i don't get the on_interaction issue you're facing, so it comes from your code

If this doesn't solve the issue then it have something to do with your code, i'll investigate it tomorrow.
26
Your projects / Re: Allied AI Script Project Alpha
« Last post by Zefk on May 14, 2017, 02:13:09 am »
Here is a cool function I made for this project. The lib I am making has a bunch of other functions to make showing images easier. This was made to display stats, item amounts, etc.



It is declared like this.

Code: Lua
  1. game:set_value("money", 2)
  2. game:set_value("gem", 3)
  3. game:set_value("silver", 4)
  4.  
  5. entity:font_draw(1,"MONEY: ", 30, 50, "money")
  6.  
  7. entity:font_draw(2,"GEM: ", 30, 80, "gem")
  8.  
  9. entity:font_draw(3,"SILVER: ", 30, 110, "silver")
  10.  
  11. entity:font_create(3, font_name, text_size, render_mode, color_rgb, map)
  12.  
  13. --remove gem text
  14. entity:font_undraw(2)
  15.  
  16. --true remove all text
  17. entity:font_undraw(font_index, true)
27
Development / Re: Jump movement direction4 error?
« Last post by Zefk on May 14, 2017, 01:19:00 am »
I attached the jump_lib.lua. Put it in the script directory.

From your main.lua put the following at the top.

Code: Lua
  1. require("scripts/jump_lib.lua")

Pick a sprite from the custom entity and paste the following into a custom entity script. The sprite will need a "jumping" and "stopped" animation. Also, a sound called "jump". Using the sample_quest and Eldran will work. Remember to change the direction of the custom entity. It jumps "right" by default.

Code: Lua
  1. -- Event called when the custom entity is initialized.
  2. function entity:on_created()
  3.   entity:jump()
  4. end

I have tested this outside of my project. I am pretty sure you will get the same result. That is why I reported it as a bug. This only happens with the jump movement.

https://github.com/solarus-games/solarus/issues/1057

For entity:jump_create() all you gotta do is paste it into a custom entity. This is the function that works. It uses Eldran as the default sprite. main_heroes/eldran

Code: Lua
  1. entity:jump_create()

You can change the directory.

Code: Lua
  1. entity:jump_create("main_heroes/eldran")

The jump_create function creates the sprite with script instead.

Code: Lua
  1. sprite = self:create_sprite(sprite_directory)
28
Development / Re: entity sounds
« Last post by ponderitus on May 13, 2017, 11:16:44 pm »
cheers man, that was my quick fix, just rename my files to be named the same and delete the old ones
29
Development / Re: Jump movement direction4 error?
« Last post by MetalZelda on May 13, 2017, 10:28:21 pm »
Can you send your project here ? I'll investigate this, weird issues there
30
Development / Re: Stopping npcs
« Last post by MetalZelda on May 13, 2017, 10:27:04 pm »
use entity:on_obstacle_reached(movement)

http://www.solarus-games.org/doc/latest/lua_api_entity.html#lua_api_entity_on_obstacle_reached

From there you have to configure the behaviour of what the entity do when it collide with something (and obviously, you can change it's movement)

Stopping an NPC ? No problem

Code: Lua
  1. function entity:on_obstacle_reached(movement)
  2.   -- Check if any movement exist
  3.   if movement ~= nil then
  4.     -- Stop the movement
  5.     movement:stop()
  6.  
  7.     -- Do whatever you want here (restart a movement or else)
  8.   end
  9. end
  10.  
  11.  

But you have to define this event for each NPC that does what you want
Careful though, this event is called each time the entity collide with something, so, if you want to make this entity to interact only with another entity, use

http://www.solarus-games.org/doc/latest/lua_api_entity.html#lua_api_entity_get_facing_entity

Code: Lua
  1. function entity:on_obstacle_reached(movement)
  2.   -- Check if any movement exist
  3.   if movement ~= nil then
  4.     -- Check the entity facing this entity
  5.     if self:get_facing_entity():get_name() == "name_of_your_npc" then
  6.       -- Stop the movement
  7.       movement:stop()
  8.  
  9.       -- Do whatever you want here (restart a movement or else)
  10.      end
  11.   end
  12. end
  13.  
  14.  
Pages: 1 2 [3] 4 5 ... 10