Author Topic: Pickable Item with No Shadow (Solved)  (Read 4204 times)

0 Members and 1 Guest are viewing this topic.

llamazing

  • Full Member
  • ***
  • Posts: 220
    • View Profile
Pickable Item with No Shadow (Solved)
« on: December 25, 2016, 12:02:10 AM »
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?
« Last Edit: December 26, 2016, 09:33:26 PM by llamazing »

YoshiMario2000
  • Jr. Member
  • **
  • Posts: 85
    • View Profile
Re: Pickable Item with No Shadow
« Reply #1 on: December 25, 2016, 12:31:16 AM »
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?

llamazing

  • Full Member
  • ***
  • Posts: 220
    • View Profile
Re: Pickable Item with No Shadow
« Reply #2 on: December 25, 2016, 03:12:09 AM »
Interesting, item:set_shadow(nil) does work, but item:set_shadow() does not. I thought those two expressions were equivalent.

llamazing

  • Full Member
  • ***
  • Posts: 220
    • View Profile
Re: Pickable Item with No Shadow
« Reply #3 on: December 26, 2016, 07:40:10 PM »
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++?

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1192
    • View Profile
Re: Pickable Item with No Shadow
« Reply #4 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. I decided that it does not make sense to write item:set_shadow() without parameter, so I don't allow it.

llamazing

  • Full Member
  • ***
  • Posts: 220
    • View Profile
Re: Pickable Item with No Shadow
« Reply #5 on: December 26, 2016, 08:32:13 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?

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1192
    • View Profile
Re: Pickable Item with No Shadow
« Reply #6 on: December 26, 2016, 09:09:21 PM »
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

llamazing

  • Full Member
  • ***
  • Posts: 220
    • View Profile
Re: Pickable Item with No Shadow
« Reply #7 on: December 26, 2016, 09:31:20 PM »
Interesting. Thanks for the info, Christopho!