Solarus-Games English Forum

Solarus => Development => Topic started by: lefthandedhero on January 26, 2024, 04:46:11 PM

Title: What does this error in my item script mean?
Post by: lefthandedhero on January 26, 2024, 04:46:11 PM
I recently started making an item and one thing about this item is that, when the hero obtains the item, an entity appears near the hero. I saw that all item scripts have "local map = item:get_map()" near the top of the script, so, in my item:on_obtained() function, I wrote, "local hero = map:get_hero()" so that I could then obtain the hero's position for knowing where to place the entity. However, when I tested my code by having the hero obtain the item, I got this error message:

"attempt to index upvalue 'map' (a nil value)"

What does this error mean?

EDIT: I fixed the problem by adding, "local map = item:get_map()" to the function.