Pickable Item with No Shadow (Solved)

Started by llamazing, December 25, 2016, 12:02:10 AM

Previous topic - Next topic
December 25, 2016, 12:02:10 AM Last Edit: December 26, 2016, 09:33:26 PM by llamazing
Using the ALTTP resource pack, I wanted to create a pickable treasure for the bottle, which looks bad if it has a shadow.

According to the Equipment Items documentation, the method item:set_shadow(shadow_animation), where shadow_animation is nil gives no shadow. However, when I try doing item:set_shadow(), I get the following error:

Error: In on_created: [string "items/bottle_1.lua"]:9: bad argument #1 to set_shadow (string expected, got no value))

I also tried item:set_shadow(false) and item:set_shadow("nil") to no avail. What am I doing wrong here?

Try this:
Code (lua) Select
item:set_shadow(nil)
nil is a non-existent value and that is what the engine is searching for in this method. It should work as I just ran a quick test in a quest that I'm building from scratch.
This signature was way too long before, but now it's short!
Also, I am Still Alive!
On ad Off I go!

Do you ever get the feeling that the fandom of a product(s) ruin the potential that you could have had to enjoy the product?

Interesting, item:set_shadow(nil) does work, but item:set_shadow() does not. I thought those two expressions were equivalent.

Does anyone have an explanation for why item:set_shadow(nil) has a different behavior than item:set_shadow()? My understanding was that the two would be equivalent. Is it because the set_shadow function is written in C++?

nil is a value of the special type "nil", but no value is just no value passed to the function call. Some functions use as a convention that these are equivalent, some other don't. I decided that it does not make sense to write item:set_shadow() without parameter, so I don't allow it.

Quote from: Christopho on December 26, 2016, 07:57:36 PM
nil is a value of the special type "nil", but no value is just no value passed to the function call. Some functions use as a convention that these are equivalent, some other don't.

Is it a true statement that what you said only applies to functions written in C++?

When working purely in lua, there is no way to distinguish between "a value of special type nil" and "no value", correct?

In Lua, when you write a function with parameters, as you said, you have no way to distinguish between nil and no values.
Code (lua) Select

function f(a)
  if a == nil then
    -- Do stuff.
  end
end

Functions written in C++ can have more control, you are right.

However, there is still a way with the ... notation if you really want. Here is a Lua function that prints its number of parameters:
Code (lua) Select

local function f(...)
  print(select("#", ...))
end

f("hi", 2)
-> 2
f()
-> 0
f(nil)
-> 1


Interesting. Thanks for the info, Christopho!