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

Topics - oHInsane

#1
Hi,

My learning is on a good way thanks to your various helps.

I have another question.

I have created a rake, but I need it the ability to cut a brush (a destructible with can_be_cut set to true).
The rake will eventually deal damage to enemy and cut thoses brushes.

I'm also trying to learn more about usable items this way, here is the code of my item "rake"





-- rateau.lua
local item = ...
local game = item:get_game()

function item:on_using()
  -- some code
  local entities_touched = { }
  rateau:set_origin(4, 5)
  rateau:add_collision_test("overlapping", function(rateau, entity)
  local nom_entite = entity:get_name()
  if(nom_entite == "plantation")then
    local sprite = "entities/bush_green"
      entity:create_sprite(sprite)
      entity:set_animation("destroy")
  end 
-- some code

So my idea is basically to detect if a collision is occuring between my "rateau" (rake) and the bush.
If the collided entity goes by the "plantation" name, then i want to start the bush destroyed sprite animation.

So with this code i have this error:
Error: In collision callback: [string "items/rateau.lua"]:39: attempt to call method 'create_sprite' (a nil value)

If I understand correctly it means my entity can't use the create_sprite animation.

I think i miss the methodology of doing this type of stuff. For the moment i'm thinking like this:
1) test colllision
2) get the entity that is collided
3) start the cut animation if it's a brush.

But It raises questions: the callbacck from the collision test is allowing me to access the "targeted entity". But how do I test if it's a destructible brush. I can test the "destructible" part with the get_type() function (instead of get_name() which force me to list and give one unique name for each damned brush on the map).
And why do I have an error on the create_sprite() function when i try to start the destroy animation of the brush.

Thanks


#2
Development / How to assign an item dynamically
January 19, 2017, 02:04:46 AM
Hi,

I'm getting my hands on solarus and i'm currently reading a lot of documentation and tryng out other projets to understand how far can solarus go.

1) So my first question is: i want to give directly the boomerang at the start of my quest.

I have tried this code

  local item = game:get_item("boomerang")
  game:set_item_assigned(1, item)


But i got the error: "Cannot assign item 'boomerang' because the player does not have it".

So my guess is that i need to instantiate the boomerang first but how?



Thank you.