New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
using addEvent with item that has no uniqueId #3297
Comments
Interesting proposal, although surely there is a cleaner and correct way to do it, for now this should have a feature tag Note: it is worth mentioning that currently you can work with unique articles in addEvent, only you must know how to do it correctly, if you know what you want to do and you are clear about the result you can work well without the need for this that you propose |
Use issue template. |
It's purposely done that way. If you need to track that item, you may add a custom attribute to it and check for that attribute whenever some interaction is triggered (like player moving an item for example). |
I do get it what you all are saying, but I'd say the behavior is inconsistent comparing to other such cases (ex. Player) and your solutions seem to be workarounds for the existing problem. |
I see, you probably want to construct |
Yeah I wrote something similar to you some time ago. Your code will fail to obtain stackables that were modified (merged, split, even moved, stacks are entirely remade), guid will change and your code will fail to obtain your saved item by the guid. To make something like this work either remake stacking system (probably a lot of work) |
You can't use UID on stackables. Every implementation will be wrong. You can add code like in this pastebin, but it should not work on stackable items (return error / nil / 0).
With 'do something on interaction' idea, you cannot use that item in addEvent and execute action like 'remove after 15 seconds'. |
I agree with everyone in this thread. My own implementation is a temp id, which obviously does not work for stackable items but can help a lot in certain situations. |
Obviously not, but you can set that item decay to 15 seconds and add a new event to source code. Something that would trigger when item decay finishes. |
It's not a bad idea |
0.4 has a track of all items in Lua and you can access them by UID, if they were not removed or split [for stackable]. Maybe in 1.x there should be special functionality to 'track Item' ex. |
example:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local item = Item(item.uid)
print(item:getName())
addEvent(test, 5000, item.uid)
end
function test(uid)
local item = Item(uid)
if item == nil then
print("item is nil")
return
end
print(item:getName())
end
this will always output:
itemname
item is nil
althrough the item gets assigned uniqueid the scriptenv resets and with it the uniqueid assignemnt data is lost when event is executed
example quick solution that demonstrates how it should behave (tested, works as intended, code quality is meh):
https://pastebin.com/qzEeYL63
The text was updated successfully, but these errors were encountered: