Page 86 of 169

Re: Post your modding questions here

PostPosted: Wed Sep 09, 2015 12:55
by everamzah
I generally use Programming in Lua[1] which covers 5.0. Is string.trim() a 5.1 feature? Is there a good place to learn more about how to use it? Related: Is filtering for only A-Z and a-z and 0-9 better than trying to filter out anything like spaces, apostrophes, etc.?
[1] http://www.lua.org/pil

Re: Post your modding questions here

PostPosted: Wed Sep 09, 2015 13:58
by kaeza
string.trim is Minetest-specific, documented in doc/lua_api.txt, and implemented in builtin/common/misc_helpers.lua, IIRC

Re: Post your modding questions here

PostPosted: Wed Sep 09, 2015 14:40
by jp
Or that :

Code: Select all
param:gsub("%W", "")


(note : %W in uppercase, different from %w)

Re: Post your modding questions here

PostPosted: Wed Sep 09, 2015 15:01
by everamzah
jp wrote:Or that :

Code: Select all
param:gsub("%W", "")


(note : %W in uppercase, different from %w)

that seems to do the trick! thanks very much for help HybridDog, kaeza, and jp. :)

Re: Post your modding questions here

PostPosted: Thu Sep 10, 2015 07:52
by Ferk
minetest.luaentities only holds the entities that are currently loaded.

Is there a way I can obtain all the entities of an area? ...or force an area to be loaded, along with its entities.

Alternatively: given a particular area, how can I know if all the entities inside it are loaded? this way at least I could tell apart the entities that were removed from the ones that are simply not loaded and update my data accordingly.

I could assume that the area around an entity has been completely loaded every time I find an entity. But then if a player removed all the entities from an area I won't have a way to know if it was simply not loaded.

Thanks!

Re: Post your modding questions here

PostPosted: Thu Sep 10, 2015 19:18
by ArguablySane
Ferk wrote:minetest.luaentities only holds the entities that are currently loaded.

Is there a way I can obtain all the entities of an area? ...or force an area to be loaded, along with its entities.

Alternatively: given a particular area, how can I know if all the entities inside it are loaded? this way at least I could tell apart the entities that were removed from the ones that are simply not loaded and update my data accordingly.

I could assume that the area around an entity has been completely loaded every time I find an entity. But then if a player removed all the entities from an area I won't have a way to know if it was simply not loaded.

Thanks!

There are functions to force-load an area. I'm not sure of their range though:
minetest.forceload_block(pos)
minetest.forceload_free_block(pos)

You can check if an area is loaded by querying a node inside it and seeing if you get "ignore",

Re: Post your modding questions here

PostPosted: Thu Sep 10, 2015 20:16
by Ferk
Thanks for the reply, ArguablySane :)

ArguablySane wrote:There are functions to force-load an area. I'm not sure of their range though:
minetest.forceload_block(pos)
minetest.forceload_free_block(pos)


I didn't know about this, thanks.
However, it seems that this only loads the node in the position given and it won't load the entities around this node

You can check if an area is loaded by querying a node inside it and seeing if you get "ignore",


This would have been already good enough for my case.. but it seems entities have a much lower range than nodes. I still discover entities that get unloaded when the player walks away even though the block where they were placed is still loaded.

What is the range from the player in which the entities get loaded/unloaded? Maybe at least I can get the entities close to the player to update properly.

Re: Post your modding questions here

PostPosted: Thu Sep 10, 2015 20:38
by Don
I think that is the active_block_range in minetest.conf
https://github.com/minetest/minetest/bl ... nf.example

Re: Post your modding questions here

PostPosted: Fri Sep 11, 2015 21:17
by Nathan.S
I'm trying to determine what node is placed in an inventory slot. Currently I know how to check if the inventory is a certain item with if inv:contains_item('slot_name', 'item_name') then
however I'm trying to create a local value that has that item_name as it's value, so I can drop that item to the ground on a button click, or move it to the player inventory with a button.
I'm guessing this should be possible, I just can't seem to figure it out.

Re: Post your modding questions here

PostPosted: Mon Sep 14, 2015 19:38
by Ben
Nathan.S wrote:I'm trying to determine what node is placed in an inventory slot. Currently I know how to check if the inventory is a certain item with if inv:contains_item('slot_name', 'item_name') then
however I'm trying to create a local value that has that item_name as it's value, so I can drop that item to the ground on a button click, or move it to the player inventory with a button.
I'm guessing this should be possible, I just can't seem to figure it out.


The dev wiki on InvRefs should contain everything you need. But since you wrote "if the inventory is a certain item", and refer to the first parameter as "slot_name", I'm not sure you understand that each of these "slots" is in fact a list of slots. If you do, my apologies; other readers may not, so it can't hurt to mention it.

The following code should iterate over an inventory list:
Code: Select all
for i=1, inv:get_size('slot_name') do
  local stack 
= inv:get_stack('slot_name', i)
  local name = stack:get_name()
  --# do stuff with name and stack
  inv:set_stack('slot_name', i, new_stack) --# write back changes
end


Does that help?

Re: Post your modding questions here

PostPosted: Mon Sep 14, 2015 19:48
by Ben
ArguablySane wrote:There are functions to force-load an area. I'm not sure of their range though:
minetest.forceload_block(pos)
minetest.forceload_free_block(pos)


A related question: I'm contemplating a teleportation mod with a delay of a second or two. After this time, I will most likely teleport a player to a given position, the server might as well have this position loaded by that time. I'd also like to query the nodes at the position being teleported to, but this is not strictly required.

Now I could forceload the position in question at the start of the two seconds, and free it after teleportation, but that seems very heavy-handed. Also, what if the position was already forceloaded by other means? With no way to check, I would clobber that.

Is there an alternative way to "hint" to the server that the area will become relevant? An actual method call as above, or a trick like spawning a temporary entity there?

Re: Post your modding questions here

PostPosted: Tue Sep 15, 2015 01:15
by Nathan.S
Ben, you are my HERO, okay that might be going overboard, but yes, that code you provided is exactly what I needed.
I hadn't realized that each of those slots are a list of slots, but I guess that makes sense as you can have them be more than one slot. Coincidentally this could also be what I need to finish my smoker, as it has multiple slots for input, and all of them with meat need to be replaced once the smoking is done. A million thank yous.

Re: Post your modding questions here

PostPosted: Tue Sep 15, 2015 15:50
by Hybrid Dog
Ben wrote:
ArguablySane wrote:There are functions to force-load an area. I'm not sure of their range though:
minetest.forceload_block(pos)
minetest.forceload_free_block(pos)


A related question: I'm contemplating a teleportation mod with a delay of a second or two. After this time, I will most likely teleport a player to a given position, the server might as well have this position loaded by that time. I'd also like to query the nodes at the position being teleported to, but this is not strictly required.

Now I could forceload the position in question at the start of the two seconds, and free it after teleportation, but that seems very heavy-handed. Also, what if the position was already forceloaded by other means? With no way to check, I would clobber that.

Is there an alternative way to "hint" to the server that the area will become relevant? An actual method call as above, or a trick like spawning a temporary entity there?

l think voxel manipulation works in unloaded chunks

Re: Post your modding questions here

PostPosted: Tue Sep 15, 2015 16:03
by Ferk
Hybrid Dog wrote:l think voxel manipulation works in unloaded chunks

I'm wondering how does this work for chunks that were not only unloaded but also not generated.
I mean, would the engine automatically generate the area as soon as you try to perform any manipulation in there?

If for example, I define an on_generate callback for a particular area that loads a big mts schematic that covers several chunks, will all the chunks that would be affected by my mapgen have to be generated?

This means that if I add too many areas that load mts schematics it could cause a chain of on_generate calls that could potentially lock up the server. Is that correct?

If that's the case I guess it would be faster for my mapgen to try to parse the mts files from lua and feed it every time to the mapgen algorithm within the limits of the on_generate call.

Re: Post your modding questions here

PostPosted: Wed Sep 16, 2015 08:56
by Hybrid Dog
Ferk wrote:
Hybrid Dog wrote:l think voxel manipulation works in unloaded chunks

I'm wondering how does this work for chunks that were not only unloaded but also not generated.
I mean, would the engine automatically generate the area as soon as you try to perform any manipulation in there?

No, but if the map gets generated there, core mapgen (should) only replaces nodes which are ignore and keeps the other ones (firstly). l thought you mean a teleporter like the one of Zeg9, so generated but unloaded (because of rejoining) chunks.

If for example, I define an on_generate callback for a particular area that loads a big mts schematic that covers several chunks, will all the chunks that would be affected by my mapgen have to be generated?

No, but if the map becomes generated there, stone walls get ores, caves appear, etc.

This means that if I add too many areas that load mts schematics it could cause a chain of on_generate calls that could potentially lock up the server. Is that correct?

no, putting nodes into not generated chunks doesn't call the mapgen functions there

If that's the case I guess it would be faster for my mapgen to try to parse the mts files from lua and feed it every time to the mapgen algorithm within the limits of the on_generate call.

lf you place schematics in not generated areas, stone walls may get ores, caves may appear, etc.

Re: Post your modding questions here

PostPosted: Wed Sep 16, 2015 19:05
by swordpaint12
Okay, so I am working on a practice mod suggested in rubenwardy's book, and I need to know where to find the contents of the default mod so I can use it. Do any of you know where that may be?

Re: Post your modding questions here

PostPosted: Wed Sep 16, 2015 20:54
by Nathan.S
swordpaint12 wrote:Okay, so I am working on a practice mod suggested in rubenwardy's book, and I need to know where to find the contents of the default mod so I can use it. Do any of you know where that may be?


If you running Linux and installed from a PPA or software center they will be in usr/share/minetest/ if you compile yourself, guessing not though, they'll be in your directory you compiled in. Not sure on Windows, but this article on the wiki should help. http://wiki.minetest.net/Installing_Mods

Re: Post your modding questions here

PostPosted: Thu Sep 17, 2015 01:37
by swordpaint12
I'm on Windows. I managed to find an edited version in one of my sub games. I just got past that. Now, I'm puzzling over

Code: Select all
action = function(pos, node, active_object_count, active_object_count_wider)
      minetest.set_node({x = pos.x, y = pos.y + 1, z = pos.z}, {name = "aliens:grass"})


It isn't really making any sense to me. It's in chapter six.

Re: Post your modding questions here

PostPosted: Thu Sep 17, 2015 01:43
by Nathan.S
swordpaint12 wrote:I'm on Windows. I managed to find an edited version in one of my sub games. I just got past that. Now, I'm puzzling over

Code: Select all
action = function(pos, node, active_object_count, active_object_count_wider)
      minetest.set_node({x = pos.x, y = pos.y + 1, z = pos.z}, {name = "aliens:grass"})


It isn't really making any sense to me. It's in chapter six.


Well this is an action that is called when you do something, not sure what comes before the action part, I'm guessing on_dig, on_place, on_punch, on_rightclick, anyway. When this action is called Minetest sets a node, in this case aliens:grass, which will probably come up as an unknown node, unless you have an aliens mod installed. I might replace that will default:dirt or something. The location of the node is in the table {x = pos.x, y = pos.y + 1, z = pos.z} the pos, or position is passed on to the action, pos contains X, Y, and Z data, the table just adds one to the y position. When the action is called the node will be placed one node above the current node.

Re: Post your modding questions here

PostPosted: Thu Sep 17, 2015 01:53
by swordpaint12
So, do I need to do anything with it? I'm practicing on the decay mod as suggested at the end of that chapter. Do I need to change anything with it, like enter in numbers? Sorry, I'm pretty new at this. Do I just copy it in to my code?

Re: Post your modding questions here

PostPosted: Thu Sep 17, 2015 02:39
by Nathan.S
It should be good as is, but you could play around with the numbers just to see the difference.

Re: Post your modding questions here

PostPosted: Thu Sep 17, 2015 05:52
by paramat
Ben wrote:A related question: I'm contemplating a teleportation mod with a delay of a second or two. After this time, I will most likely teleport a player to a given position, the server might as well have this position loaded by that time. I'd also like to query the nodes at the position being teleported to, but this is not strictly required.

As far as i know, for teleportation to an ungenerated area, you need to know what the ground level will be at that point before mapgen generates it. Then teleport the player to that point and altitude to trigger mapgen, the player will float trapped in 'ignore' nodes until the terrain is generated.
So far this can only be done by porting mgv6 mapgen into a lua mod to predict the ground level at a certain point. Possible but not easy. There are core functions that get ground level at point for each mapgen but i would have to add APIs for those, i might actually do this.

Re: Post your modding questions here

PostPosted: Thu Sep 17, 2015 09:44
by Ferk
Hybrid Dog wrote:l thought you mean a teleporter like the one of Zeg9
paramat wrote:for teleportation to an ungenerated area [...]

Ow.. my question regarding manipulations on non-generated chunks was not really about the teleportation mod from Ben, I'm working on a different project. Though the question was related and your replies have been insightful, thank you.

I'm making a game that divides the map in rooms for an infinite dungeon maze, where each room is randomly chosen from a set of selected schematics. The idea is that people would be able to create their own "challenge rooms" and add them to the pool so the number of possibilities keeps growing.

So far I have the layout and I can generate an infinite binary-tree maze of rooms fairly fast. However, loading the (worldedit) schematics slows down the generation quite a lot. I was thinking on ways to optimize it.

Would using mts files instead of worldedit improve the performance?

How does the mapgen know how further away from the player it needs to generate? My game will be full of closed walls, so I don't really need a big radius. So far I was trying to ease the amount of rooms generated simultaneously by putting bigger gaps between the levels. But there's still a lot of generation going on.

Maybe I should decouple the schematic load from the mapgen. Something like.. have an ABM in the center of each room that loads the schematic as soon as it's at a distance from the player. This way I can control better the pace in which the schematics load. Would this be a good idea?

Also, right now I'm using singlenode. But it might be cool to consider using some mapgen in such a way that the whole underground can be the dungeon while the surface can have the standard biomes, if I figure out a way to make the mapgen not interfere with the dungeon (I guess I can disable ores, but I'm not so sure about lava, caverealms seemed to have trouble with that, maybe being a subgame helps here).

Re: Post your modding questions here

PostPosted: Thu Sep 17, 2015 10:46
by Don
@Ferk - I did something similar with mineshafts. It is a work in progress. I found that .mts files seem to load better then we files for larger schematics.
I made a node that is used as a point to place the schematic. Then i generated it with register_ore. Then I used an abm to place the schematic.
The shafts.lua has the code I am talking about if you want to see. Please let me know if you find a better way.
https://github.com/DonBatman/mymineshaft

Re: Post your modding questions here

PostPosted: Thu Sep 17, 2015 16:39
by DoyleChris
Im wondering if there is a way that a pipe supplying a technic grinder to know if the queue in the grinder is full or different item.

Example I have a grinder being feed by a pipe, grinder already is working on iron, i want to feed iron to it till its done. Then work on another kind and not have it send copper down the pipe when its working on iron.
I have tried it and the copper just stays in the tube.