Post your modding questions here

Hybrid Dog
Member
 
Posts: 2460
Joined: Thu Nov 01, 2012 12:46

Re: Post your modding questions here

by Hybrid Dog » Mon Jan 11, 2016 16:54

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
    local player_inv = player:get_inventory()
    local list = player_inv:get_list("main")
    local retval = {}
    for _, stack in pairs(list) do
        retval[#retval + 1] = stack:to_string()
    end
    local data_base = minetest.serialize(retval)

Can an item in list be nil?
Even if not, l'd use the index from the list:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
    local player_inv = player:get_inventory()
    local list = player_inv:get_list("main")
    local retval = {}
    for n, stack in pairs(list) do
        retval[n] = stack:to_string()
    end
    local data_base = minetest.serialize(retval)


Are you sure that get_list returns a copy?

l guess else there wouldn't be the set_item and remove_item
 

User avatar
kaeza
Member
 
Posts: 2141
Joined: Thu Oct 18, 2012 05:00
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza

Re: How can I save an inventory?

by kaeza » Mon Jan 11, 2016 17:05

rubenwardy wrote:I'm pretty sure it doesn't return nil items, at least it doesn't when you do print(dump(list)). Are you sure that get_list returns a copy?

Looked at the sources, and indeed the items are guaranteed to be `ItemStack`s. Also, a new table is created on the spot to hold the items, so editing it in-place has no side-effects.

Edit: Clarification.
Your signature is not the place for a blog post. Please keep it as concise as possible. Thank you!

Check out my stuff! | Donations greatly appreciated! PayPal | BTC: 1DFZAa5VtNG7Levux4oP6BuUzr1e83pJK2
 

User avatar
BrunoMine
Member
 
Posts: 902
Joined: Thu Apr 25, 2013 17:29
GitHub: BrunoMine

How can I save an inventory?

by BrunoMine » Mon Jan 11, 2016 17:09

Thanks! Another learning experience for me.
 

Byakuren
Member
 
Posts: 441
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri

Re: Post your modding questions here

by Byakuren » Mon Jan 11, 2016 20:05

Are detached inventories persistent like player and node inventories?
Every time a mod API is left undocumented, a koala dies.
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: Post your modding questions here

by rubenwardy » Mon Jan 11, 2016 20:14

Byakuren wrote:Are detached inventories persistent like player and node inventories?


No. They're deleted on shutdown.
 

User avatar
BrunoMine
Member
 
Posts: 902
Joined: Thu Apr 25, 2013 17:29
GitHub: BrunoMine

how can I delete a variable?

by BrunoMine » Mon Jan 11, 2016 21:44

I want to save memory.
This is correct?
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
mytable = {}
table.insert(mytable,"a string")
table.insert(mytable,"another string")
[...]
mytable[1] = nil
 

User avatar
qwertymine3
Member
 
Posts: 194
Joined: Wed Jun 03, 2015 14:33
GitHub: Qwertymine
In-game: qwertymine3

Re: how can I delete a variable?

by qwertymine3 » Mon Jan 11, 2016 22:44

BrunoMine wrote:I want to save memory.
This is correct?
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
mytable = {}
table.insert(mytable,"a string")
table.insert(mytable,"another string")
[...]
mytable[1] = nil

Yes this is the correct way, however...
The String
Strings in lua are references to a table of all strings, if the string "a string" is stored anywhere else (in any other variable in your mod or other mods), the interpreter won't be able to delete the global copy to free memory.
The Table
Tables in lua are only dynamically re-sized in memory when they are full - this means that setting only one of the indexes to nil won't cause it to re-size and reduce it's memory consumption

PS: Setting only [1] to nil means that you can no longer use ipairs() or # on the table - you may want to use...
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
table.remove(mytable,1) 
mytable[1] == "another string" --this is now true

This is much slower but it shuffles the entries in the table down to fill the hole in
or, if it work with what you are trying to do
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
mytable[1] = mytable[#mytable]
mytable[#mytable] = nil

This is faster, but messes up the order of the table
Avatar by :devnko-ennekappao:
 

User avatar
Evergreen
Member
 
Posts: 2131
Joined: Sun Jan 06, 2013 01:22
GitHub: 4Evergreen4
IRC: EvergreenTree
In-game: Evergreen

Re: Post your modding questions here

by Evergreen » Tue Jan 12, 2016 16:30

How can I add an item to a nodes inventory when it is thrown into said node? This is the code I have for it, but it seems to only remove the item and not add it to the specified list within the nodes inventory.

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
-- Store the old on_step function for __builtin:item so it can be called at the
-- end of the new on_step function.
local old_on_step = minetest.registered_entities["__builtin:item"].on_step
-- Register a new on_step function for __builtin:item
minetest.registered_entities["__builtin:item"].on_step = function(self, dtime)
   local item_pos = self.object:getpos()
   -- If the item is sitting in the same node as trash_can:trash_can_wooden,
   -- then continue.
   if minetest.get_node(item_pos).name == "trash_can:trash_can_wooden" then
      -- Get the ItemStack from the itemstring contained in this
      -- __builtin:item.
      local item_stack = ItemStack(self.itemstring)
      -- Get inventory of the trash_list:trash_can_wooden the item is sitting
      -- in
      local inv = minetest.get_inventory({type="node", pos=item_pos})
      -- Add the item to trash_list (a list defined in the formspec for
      -- trash_can_wooden
      inv:add_item("trash_list", item_stack)

      -- Remove the item itself
      self.object:remove()
      return
   end
   -- Call old on_step function.  This has the effect of simply adding this
   -- code to the beginning of the old on_step function.
   old_on_step(self, dtime)
end
"Help! I searched for a mod but I couldn't find it!"
http://krock-works.16mb.com/MTstuff/modSearch.php
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: Post your modding questions here

by rubenwardy » Tue Jan 12, 2016 16:36

Evergreen wrote:How can I add an item to a nodes inventory when it is thrown into said node? This is the code I have for it, but it seems to only remove the item and not add it to the specified list within the nodes inventory.

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
-- Store the old on_step function for __builtin:item so it can be called at the
-- end of the new on_step function.
local old_on_step = minetest.registered_entities["__builtin:item"].on_step
-- Register a new on_step function for __builtin:item
minetest.registered_entities["__builtin:item"].on_step = function(self, dtime)
   local item_pos = self.object:getpos()
   -- If the item is sitting in the same node as trash_can:trash_can_wooden,
   -- then continue.
   if minetest.get_node(item_pos).name == "trash_can:trash_can_wooden" then
      -- Get the ItemStack from the itemstring contained in this
      -- __builtin:item.
      local item_stack = ItemStack(self.itemstring)
      -- Get inventory of the trash_list:trash_can_wooden the item is sitting
      -- in
      local inv = minetest.get_inventory({type="node", pos=item_pos})
      -- Add the item to trash_list (a list defined in the formspec for
      -- trash_can_wooden
      inv:add_item("trash_list", item_stack)

      -- Remove the item itself
      self.object:remove()
      return
   end
   -- Call old on_step function.  This has the effect of simply adding this
   -- code to the beginning of the old on_step function.
   old_on_step(self, dtime)
end


You may need to floor the position, maybe?

Also, add_item won't necessarily add the whole stack.
You should check with inv:room_for_item(listname, stack).
See http://rubenwardy.com/minetest_modding_ ... -to-a-list
 

User avatar
Evergreen
Member
 
Posts: 2131
Joined: Sun Jan 06, 2013 01:22
GitHub: 4Evergreen4
IRC: EvergreenTree
In-game: Evergreen

Re: Post your modding questions here

by Evergreen » Tue Jan 12, 2016 19:06

rubenwardy wrote:
Evergreen wrote:How can I add an item to a nodes inventory when it is thrown into said node? This is the code I have for it, but it seems to only remove the item and not add it to the specified list within the nodes inventory.

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
-- Store the old on_step function for __builtin:item so it can be called at the
-- end of the new on_step function.
local old_on_step = minetest.registered_entities["__builtin:item"].on_step
-- Register a new on_step function for __builtin:item
minetest.registered_entities["__builtin:item"].on_step = function(self, dtime)
   local item_pos = self.object:getpos()
   -- If the item is sitting in the same node as trash_can:trash_can_wooden,
   -- then continue.
   if minetest.get_node(item_pos).name == "trash_can:trash_can_wooden" then
      -- Get the ItemStack from the itemstring contained in this
      -- __builtin:item.
      local item_stack = ItemStack(self.itemstring)
      -- Get inventory of the trash_list:trash_can_wooden the item is sitting
      -- in
      local inv = minetest.get_inventory({type="node", pos=item_pos})
      -- Add the item to trash_list (a list defined in the formspec for
      -- trash_can_wooden
      inv:add_item("trash_list", item_stack)

      -- Remove the item itself
      self.object:remove()
      return
   end
   -- Call old on_step function.  This has the effect of simply adding this
   -- code to the beginning of the old on_step function.
   old_on_step(self, dtime)
end


You may need to floor the position, maybe?

Also, add_item won't necessarily add the whole stack.
You should check with inv:room_for_item(listname, stack).
See http://rubenwardy.com/minetest_modding_ ... -to-a-list

It seems that for one reason or another the inventory for the trash can is not being retrieved correctly. Any ideas as to why that may be?

EDIT:
I found out that the formspec isn't reloaded on the node unless you dig and replace it. I suppose this makes sense since forsmpecs are metadata. Whoops. The reason this messed things up was that the old formspec contained in that trash can didn't have the list I was trying to access.
Last edited by Evergreen on Tue Jan 12, 2016 19:43, edited 3 times in total.
"Help! I searched for a mod but I couldn't find it!"
http://krock-works.16mb.com/MTstuff/modSearch.php
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: Post your modding questions here

by rubenwardy » Tue Jan 12, 2016 19:08

Try print(dump(inv:get_lists()))?
 

User avatar
Evergreen
Member
 
Posts: 2131
Joined: Sun Jan 06, 2013 01:22
GitHub: 4Evergreen4
IRC: EvergreenTree
In-game: Evergreen

Re: Post your modding questions here

by Evergreen » Tue Jan 12, 2016 19:41

Solved, see last post.
"Help! I searched for a mod but I couldn't find it!"
http://krock-works.16mb.com/MTstuff/modSearch.php
 

User avatar
BrunoMine
Member
 
Posts: 902
Joined: Thu Apr 25, 2013 17:29
GitHub: BrunoMine

Re: how can I delete a variable?

by BrunoMine » Wed Jan 13, 2016 00:43

qwertymine3 wrote:This is faster, but messes up the order of the table

but if it is not an ordinary table?
For example:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
database = {}
-- Keeps a value when the player connect
minetest.register_on_joinplayer(function(player)
   local name = player:get_player_name()
   database[name] = {<data_of_mod>}
end)
-- Remove the value when the player leaves
minetest.register_on_leaveplayer(function(player)
   local name = player:get_player_name()
   database[name] = nil
end)

This saves no memory?
 

User avatar
qwertymine3
Member
 
Posts: 194
Joined: Wed Jun 03, 2015 14:33
GitHub: Qwertymine
In-game: qwertymine3

Re: how can I delete a variable?

by qwertymine3 » Wed Jan 13, 2016 03:21

BrunoMine wrote:but if it is not an ordinary table?
For example:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
database = {}
-- Keeps a value when the player connect
minetest.register_on_joinplayer(function(player)
   local name = player:get_player_name()
   database[name] = {<data_of_mod>}
end)
-- Remove the value when the player leaves
minetest.register_on_leaveplayer(function(player)
   local name = player:get_player_name()
   database[name] = nil
end)

This saves no memory?


I would recommend reading this http://www.lua.org/gems/sample.pdf - this is my main reference for lua specific optimisations

+ My Attempt at an Answer
Avatar by :devnko-ennekappao:
 

User avatar
Merlin
Member
 
Posts: 63
Joined: Tue Dec 09, 2014 22:07
GitHub: sct-0
In-game: my

Re: Post your modding questions here

by Merlin » Wed Jan 13, 2016 11:36

Hi,

I've run into a problem when exporting DirectX files for mobs.
I tried to create a .x file like the ones PilzAdam uses in his SimpleMobs-Mod, but my .x just doesn't look like his and I am rather new to all that stuff and have no idea why.
I posted the whole story over here http://blenderartists.org/forum/showthread.php?390252-How-to-make-these-x-files-look-alike with all important files attached.
As no one yet answered there, I thought I'd try my luck here.

Thanks in advance!
 

User avatar
iangp
Member
 
Posts: 114
Joined: Sat May 31, 2014 19:26
GitHub: 14NGiestas
IRC: iangp
In-game: iangp

Re: Post your modding questions here

by iangp » Wed Jan 13, 2016 12:07

Merlin wrote:Hi,

I've run into a problem when exporting DirectX files for mobs.
I tried to create a .x file like the ones PilzAdam uses in his SimpleMobs-Mod, but my .x just doesn't look like his and I am rather new to all that stuff and have no idea why.
I posted the whole story over here http://blenderartists.org/forum/showthread.php?390252-How-to-make-these-x-files-look-alike with all important files attached.
As no one yet answered there, I thought I'd try my luck here.

Thanks in advance!

Did you have checked out the Export animation field before your exportation?
And did you have selected all objects of your model?
God's not dead, He's surely alive!
エル プサイ コングルー

My mods (WIP):
 

User avatar
Merlin
Member
 
Posts: 63
Joined: Tue Dec 09, 2014 22:07
GitHub: sct-0
In-game: my

Re: Post your modding questions here

by Merlin » Wed Jan 13, 2016 12:23

Yes and yes. I did an export with all options checked. It's more about the structure of the files. There are differences in the .blend files which are responsible for the differences of the .x files I guess, but as total noob, I'm unable to spot them.
 

User avatar
iangp
Member
 
Posts: 114
Joined: Sat May 31, 2014 19:26
GitHub: 14NGiestas
IRC: iangp
In-game: iangp

Re: Post your modding questions here

by iangp » Wed Jan 13, 2016 13:38

hmmm probably is because you have checked all options... (PilzAdam, maybe, only checked out some of them) and so that's can be the difference... got it?
but, why do you want this? planning some script for create .x files from zero in lua? or is a problem in-game?
God's not dead, He's surely alive!
エル プサイ コングルー

My mods (WIP):
 

Hybrid Dog
Member
 
Posts: 2460
Joined: Thu Nov 01, 2012 12:46

Re: Post your modding questions here

by Hybrid Dog » Wed Jan 13, 2016 16:53

For calculating those nether trees, would it work faster or slower if l used minetest.hash_node_position instead of the functions from vector.extras?
 

Byakuren
Member
 
Posts: 441
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri

Re: Post your modding questions here

by Byakuren » Thu Jan 14, 2016 00:27

How is set_attach's rotation argument supposed to be formatted? Is it rotation per axis?
Every time a mod API is left undocumented, a koala dies.
 

ABJ
Member
 
Posts: 2344
Joined: Sun Jan 18, 2015 13:02
GitHub: ABJ-MV
In-game: ABJ

Re: Post your modding questions here

by ABJ » Fri Jan 15, 2016 09:23

I am trying to do this.
Say I have a craft recipe that crafts 9 item1 when 1 item2 is placed in grid. Now I want to make a function that, when called, automatically creates a reverse recipe where 9 item1 goes into 1 grid each to create 1 item2. Anyone have any ideas?
 

User avatar
BrunoMine
Member
 
Posts: 902
Joined: Thu Apr 25, 2013 17:29
GitHub: BrunoMine

difference of teleport?

by BrunoMine » Sun Jan 17, 2016 17:45

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
player:setpos(pos)

player:moveto(pos)

These two perform exactly the same task?
What is the difference?
 

User avatar
iangp
Member
 
Posts: 114
Joined: Sat May 31, 2014 19:26
GitHub: 14NGiestas
IRC: iangp
In-game: iangp

Re: Post your modding questions here

by iangp » Sun Jan 17, 2016 19:53

setpos -> teleport/magic
moveto -> the player will walk from where he are to this point "pos"
(But I haven't tested this yet)
God's not dead, He's surely alive!
エル プサイ コングルー

My mods (WIP):
 

User avatar
BrunoMine
Member
 
Posts: 902
Joined: Thu Apr 25, 2013 17:29
GitHub: BrunoMine

Re: Post your modding questions here

by BrunoMine » Sun Jan 17, 2016 20:03

In 'moveto' the player is teleported.
 

User avatar
iangp
Member
 
Posts: 114
Joined: Sat May 31, 2014 19:26
GitHub: 14NGiestas
IRC: iangp
In-game: iangp

Re: Post your modding questions here

by iangp » Sun Jan 17, 2016 20:28

our savior archive: lua_api.txt

* `setpos(pos)`; `pos`=`{x=num, y=num, z=num}`
* `moveto(pos, continuous=false)`: interpolated move

check out this option "continuous" (turn it true and after that false) and see what happens with the player...
I really don't know why moveto are, by default, the same as setpos...
God's not dead, He's surely alive!
エル プサイ コングルー

My mods (WIP):
 

User avatar
BrunoMine
Member
 
Posts: 902
Joined: Thu Apr 25, 2013 17:29
GitHub: BrunoMine

Re: Post your modding questions here

by BrunoMine » Sun Jan 17, 2016 21:24

iangp wrote:check out this option "continuous" (turn it true and after that false) and see what happens with the player...

I did not realize the difference.
 

User avatar
iangp
Member
 
Posts: 114
Joined: Sat May 31, 2014 19:26
GitHub: 14NGiestas
IRC: iangp
In-game: iangp

Re: Post your modding questions here

by iangp » Sun Jan 17, 2016 23:16

that's a strange issue... I will finally make some simple script to test this (how do you implemented that?)
Are your minetest version the 0.4.13 one?
Well that can be a too new function... In rubenwardy's documentation (read it as: "nicer formatted version of lua_api.txt, the documentation that came with minetest.") there's a callback called on_secondary_use
that are called when the player left-click pointing to air (nothing) [I wanted this for my starwars mod] I tried and didn't worked... but I just downloaded the latest github code of minetes and then it worked...
Your situation can be similar to mine...
Last edited by iangp on Sun Jan 17, 2016 23:33, edited 2 times in total.
God's not dead, He's surely alive!
エル プサイ コングルー

My mods (WIP):
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: Post your modding questions here

by rubenwardy » Sun Jan 17, 2016 23:27

It's not my documentation you're refering to.

The page on my website is just a nicer formatted version of lua_api.txt, the documentation that came with minetest.
 

User avatar
iangp
Member
 
Posts: 114
Joined: Sat May 31, 2014 19:26
GitHub: 14NGiestas
IRC: iangp
In-game: iangp

Re: Post your modding questions here

by iangp » Sun Jan 17, 2016 23:29

I'm getting the same... I think this should be reported as an issue...
@rubenwardy do you know something about that?
Last edited by iangp on Sun Jan 17, 2016 23:32, edited 1 time in total.
God's not dead, He's surely alive!
エル プサイ コングルー

My mods (WIP):
 

User avatar
iangp
Member
 
Posts: 114
Joined: Sat May 31, 2014 19:26
GitHub: 14NGiestas
IRC: iangp
In-game: iangp

Re: Post your modding questions here

by iangp » Sun Jan 17, 2016 23:30

rubenwardy wrote:It's not my documentation you're refering to.

The page on my website is just a nicer formatted version of lua_api.txt, the documentation that came with minetest.

yes yes :D sorry about that...
God's not dead, He's surely alive!
エル プサイ コングルー

My mods (WIP):
 

PreviousNext

Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 52 guests

cron