Solarus > Development

:on_interaction_item(item_used)

(1/2) > >>

ponderitus:
I was wondering if you can make this item specific? it seems to activate if any item is used..eg.


--- Code: ---function custom_sensor_1:on_interaction_item(boomerang)
sol.audio.play_sound("secret")
end

function npc_1:on_interaction_item(boomerang)
sol.audio.play_sound("secret")
end
--- End code ---

this would be activated if i used a bow or any item at all.

is there a different way to have something happen when an certain item is used in a specific place? maybe im looking in the wrong place?

Starlock:
I haven't tested this so not sure if it'll work with what you're trying to do but maybe this could work.


--- Code: ---function npc_1:on_interaction_item(item_used)
  if item_used == "boomerang" then
    sol.audio.play_sound("secret")
  end
end
--- End code ---

ponderitus:
nope that doesn't work i already tried that :( thanks though

nothing happens at all with the boomerang or anything in that situation and if you put an else in...like


--- Code: ---function custom_sensor_1:on_interaction_item()
  if item_used == "boomerang" then
    hero:freeze()
    sol.audio.play_sound("secret")
  else
    sol.audio.play_sound("wrong")
  end
end
--- End code ---

the "else" will always be activated...even when using a boomerang

Christopho:
The type of item_used is item, not string, that's why Starlock's example does not work.

ponderitus:
I don't know what that means...so how would you get that to work then?

Navigation

[0] Message Index

[#] Next page

Go to full version