Advertisement
Guest User

Untitled

a guest
Feb 20th, 2013
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. function get_item_meta (string)
  2. if string.find(string, "return {") then
  3. return minetest.deserialize(string)
  4. else return nil
  5. end
  6. end
  7.  
  8. function set_item_meta (table)
  9. return minetest.serialize(table)
  10. end
  11.  
  12. and example usage:
  13.  
  14. read values from item's meta:
  15. item=itemstack:to_table()
  16. local meta=get_item_meta(item["metadata"])
  17. if meta==nil then return false end --tool not charghed
  18. if meta["charge"]==nil then return false end
  19. charge=meta["charge"]
  20.  
  21. save them back:
  22. meta["charge"]=charge
  23. item["metadata"]=set_item_meta(meta)
  24. itemstack:replace(item)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement