Difference between revisions of "User:Xyz/stress"

From Minetest Developer Wiki
Jump to navigation Jump to search
Line 30: Line 30:
 
** <code>punch</code>
 
** <code>punch</code>
 
** <code>rightclick</code>
 
** <code>rightclick</code>
 +
 +
=== stressedInventory ===
 +
* <code>:empty()</code> — returns true if inventory is empty
 +
* <code>:clear()</code> — remove everything from inventory
 +
* <code>:size()</code> — get size of an inventory
 +
* <code>:size(N)</code> — set size of an inventory
 +
* <code>:width()</code>
 +
* <code>:width(N)</code>
 +
* <code>:stack(X)/code> ­— get the Xth stack from inventory, modifiable
 +
 +
=== stressedStack ===
 +
* <code>:count()</code>
 +
* <code>:count(N)</code>
 +
* <code>:wear()</code>
 +
* <code>:wear(N)</code>
  
 
== Global functions ==
 
== Global functions ==

Revision as of 09:55, 18 February 2013

_()!

http://irc.minetest.ru/minetest/2013-02-17#i_2877771

Core concepts

All functions are prefixed with :. All properties are prefixed with ..

Types

All stressed* members should have __type property containing theirs type as a string.

stressedPosition

Same as position. Can be created from either {x = …, y = …, z = …} or {…, …, …}

stressedNode

Created via _(position)

Implements:

  • :value() — get node name
  • :value("string") — set node name (like minetest.env:set_node())
  • :meta("name") — get meta
  • :meta("name", "value") — set meta
  • :inventory("name") — stressedInventory (name is actually listname)

stressedNodeDef (what a weird name! better think of another one)

Created via _("name"), i.e. _("default:dirt")

  • :on("event", function()) — registers event, possible ones:
    • dig
    • place
    • punch
    • rightclick

stressedInventory

  • :empty() — returns true if inventory is empty
  • :clear() — remove everything from inventory
  • :size() — get size of an inventory
  • :size(N) — set size of an inventory
  • :width()
  • :width(N)
  • :stack(X)/code> ­— get the Xth stack from inventory, modifiable

stressedStack

  • :count()
  • :count(N)
  • :wear()
  • :wear(N)

Global functions

  • _:on("event", function())
    • generated
    • shutdown

Something

An example of code in stress:

_("default:dirt"):on("place", function(me)
    me:value("default:dirt_with_grass")
end)

same without stress

minetest.register_on_placenode(function(pos, newnode)
    if newnode.name == "default:dirt" then
        minetest.env:set_node(pos, {name="default:dirt_with_grass"})
    end
end)

Something more?

dirttograss = nil
_:on("chat", function(message)
    if message == "/dirttograss" and not dirttograss then
        dirttograss = _("default:dirt"):on("place", function(me)
            me:value("default:dirt_with_grass")
        end)
    elseif message == "/nodirttograss" and dirttograss then
        _(dirttograss):clear()
    end
end)