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

Pages: 1 [2]
Development / Re: Freezing/locking keyboard during specific event?
« on: June 26, 2018, 09:13:05 AM »
Alright, sry for the missing code in the last post.
For better understanding, the Item uses up "MP" everytime it is used.
You see the keyboard_binding unchanged, so you see how I indended to do it.
The collision_test is new. I want to try to make a clone on a walkable switch to activate it (the switch deactivates when you step off of it), so the hero can pass f.e. a bridge while the clone is active. When the clone vanishes the switch should deactivate and the bridge should disappear. But maybe thats another topic ^^

Code: (Lua) [Select]
--Script of the Item "Clone"--

local item = ...
local game = item:get_game()

--Item "Clone"--
function item:on_created()

--function item:on_obtained(variant, savegame_variable)

function item:on_using()

         local map = item:get_map()
         local player = map:get_hero()
         local x, y, layer = player:get_position()
         local direction = player:get_direction()
         local mp_needed = 5

--Control back to Player--
         function done()

--Create Dublicate Entity--
         clone = map:create_custom_entity({
                                            direction = direction,
                                            layer = layer,
                                            x = x,
                                            y = y,
                                            width = 24,
                                            height = 24,

--Clone Sprites & Animationen--
         function clone_animation()
                  clone_create = clone:create_sprite("entities/clone")
                  sol.timer.start(clone, 5000, function()
                                                         game:set_command_keyboard_binding("item_1", "x")

--Collisions Switch-- --Not finished!!--
         clone:add_collision_test("overlapping", function(clone, entity)

--Start "Clone", when enough MP--
         if game:get_life() > mp_needed and
         item:has_variant(1) then
            player:set_animation("clone", function()
                                                    game:set_command_keyboard_binding("item_1", nil)

--End Item "Clone"--

And this is, what I added in the game_manager:

Code: (Lua) [Select]
function game:on_map_changed(map)
                  game:set_command_keyboard_binding("item_1", "x")

As always, thanks in advance ;)

Development / Re: Freezing/locking keyboard during specific event?
« on: June 25, 2018, 03:35:25 PM »
So, may I get your opinion on this one:

I tried it with map:has_entity("clone"), but it didn't work. He didn't start a second animation, thats true, but he still thinks there is a second usage of the item and he can't "remove" the sprite at the end.
I now added "game:on_map_changed(map)" with "game:set_command_keyboard_binding("item_1", "x")" in game_manager, so everytime I move to another map, the binding is set new. Seem to work, no errors   8)

Development / Re: Freezing/locking keyboard during specific event?
« on: June 25, 2018, 02:23:41 PM »
Good points there guys ;)

Don't worry, I didnt end up setting the state false in on_item_finished() ^^

Yes Max, you're right - The duplicate is a custom entity created by the coresponding item and it disappears when I move to another map...
For now I tried things just on one map, so I didn't realise that :P

So thanks for the mention I will have to consider that in the future.

Development / Re: Freezing/locking keyboard during specific event?
« on: June 20, 2018, 11:15:41 AM »
Solved it on my own ^^

The Problem with this is, that the hero gets out of the item state and is able to use another "instance" of the same item, I feel.
So whatever you do with variables, its working but the engine says there is no first entity sprite to remove at the end, if you have created two of them.

For others with similar tasks:
So what I did now, is to set the keyboard binding of the item slot nil, when the animation of the item starts...
game:set_command_keyboard_binding("item_1", nil)
... and give it back to the key (x) after the sprite of the entity is removed
game:set_command_keyboard_binding("item_1", "x")

For me that works perfectly fine for now, because I dont intend to use another item, while the duplicate is activ (and its way simpler) :)

Development / Re: Freezing/locking keyboard during specific event?
« on: June 20, 2018, 09:42:25 AM »
So, back in the topic.
The tips above work perfectly for "normal" items:
local variable ("using_item") -> set false -> in on_using() set true -> and tackle on_using() with: if using_item ~= true then -> and on_item_finished set false again.

But... I made an item, that creates a duplicate (entity having the same sprite) of the hero - like in Minish Cap :)
This duplicate cannot do anything, it is just standing where it is created and vanishes after a timer.
While the duplicate is on screen, I wanted the hero to be able to walk around normaly. Therefore I unfreeze him in the middle of the item (crazy me!  :P) when the duplicate is created. Works, but then I can use the item again because the hero is back in his normal state and there comes the problem of the item beeing able to activate again, especially in the same spot, where it causes an error, because at the end of the item it removes the entity sprite. And when there are two sprites it cannot remove the first one created.

Hope you have an idea or something, this item seems to be a special candidate ^^
Thanks in advance again ;)

Development / Re: Freezing/locking keyboard during specific event?
« on: June 14, 2018, 05:09:12 PM »
Yes, makes sense. Didn't think of that ^^
I'll have to try, to see how it fits best.

Thanks for the fast reply  ;)

Development / Freezing/locking keyboard during specific event?
« on: June 14, 2018, 04:26:57 PM »
Hi there again  ;)

Today I have a quick question. Hope I can describe it the right way:
I made a custom item with animations and all of that, the hero can use with the "item_1" command key (x). Works - so far so good ^^
But when I press the key, while the animation of the item used is running - the animation stops and starts new. In further consequence errors occur obviously...

Is it possible to lock the keyboard input, til item:on_using is finished, or you may have another idea?
Thanks for your advises in advance  :)

Development / Re: Switch between two sprites by pressing a key?
« on: May 28, 2018, 10:11:23 AM »
@neovyse: Thanks for the tip, I already thought, there was something like this ^^

@Ilamazing: Thanks for the reply. That makes sense. It wasn't a problem till now, because I haven't made a titlescreen for now. But I will consider it  ;)

@Dirandor: Thanks for the link. I will watch it. Maybe I can use something from it  :)

The code/script is constantly improving and evolving. For now its working perfectly. Thanks again

Development / Re: Switch between two sprites by pressing a key?
« on: May 22, 2018, 12:46:45 PM »
So I tried Max's advice and had to play a little bit around. But IT WORKED!!
I post my result, if anyone has a similar task ;)
I tried so many things and as often with new programs, overcomplicated it  :P

I now didn't go with the "get_ability()" method in the main lua, but with "set_tunic_sprite_id()" directly in the hero.lua (see below)
I set up two sprites (playersprite1 & playersprite2) and now let the engine change between those two whenever "w" is pressed.
Exactly what I wanted, thanks again Max for the great tip, which made it work: ;)

Code: (lua) [Select]
--Initialize the behaviour of the hero in the quest--


local hero_meta = sol.main.get_metatable("hero")

local function initialize_player(game)
                local player = game:get_hero() --Took the name "player", because the sprite has the same name--
                player:set_tunic_sprite_id("hero/playersprite1") --Sprite to begin with--

      function sol.main:on_key_pressed(key, modifiers) --key-press function--

        local handled = false
        if key == "w" then --change on key "w"--
              if player:get_tunic_sprite_id() == "hero/playersprite1" then --if current sprite is sprite1, then--
                 player:set_tunic_sprite_id("hero/playersprite2") --change to sprite2--
              elseif player:get_tunic_sprite_id() == "hero/playersprite2" then --and back--
                     player:set_tunic_sprite_id("hero/playersprite1") --to sprite1--
          handled = true
        return handled

--Set up the hero features on any game that starts--
local game_meta = sol.main.get_metatable("game")
game_meta:register_event("on_started", initialize_player)
return true

Development / Re: Switch between two sprites by pressing a key?
« on: May 22, 2018, 11:36:56 AM »
Thanks for the tip ;)
I understand the lua-concept a little bit. I know what you mean with the "ends" ;)
I'll try your advice, since that is something I've not tried yet ^^

Hello there  ;)
New here and just started with Solarus and the programming-thing  :P
First, thank you for such an amazing programm! Great job.

My question:
I already have my own character-sprite implimented as the "hero". The thing is, that my idea is, to be able to switch the sprite of my hero between two sprites everytime I press a certain key. (F.e. I press "w" -> sprite of hero changes to "tunic1", I press "w" (again) -> sprite of hero changes to "tunic2", and back, and back...)
I already tried some things myself, but can't really figure it out...
(Still got problems with the whole "game:get things, game:set things" thing ^^)

Pages: 1 [2]