try turret:set_pos(pos)azekill_DIABLO wrote:I have this error with that code, why? can you help me?Code: Select all
ERROR[Main]: ServerError: AsyncErr: ServerThread::run Lua: Runtime error from mod 'azewheel' in callback luaentity_Step(): ...ames\minetest-0.4.16-win64\bin\..\mods\azewheel/tank.lua:105: bad argument #1 to 'set_pos' (userdata expected, got table)
Code: Select all
function tank_turret.on_step(self) --tank_turret is an entity local turret = self.object local pos = {x=playerpos.x, y=playerpos.y, z=playerpos.z} --the position of player is correct turret.set_pos(pos) -- this line causes the bug, but why? end
Post your modding questions here
Re: Post your modding questions here
-
- New member
- Posts: 9
- Joined: Fri Aug 04, 2017 07:59
- GitHub: mezantrop
- Location: Brno, CZ
- Contact:
Re: Post your modding questions here
topic: Passing values between objects.
reason: I want to pass a custom value from one entity to another entity.
more info: There is an entity named "First", and in on_activate() I run this code o spawn a second entity and later to pass the value:
Obviously, I'm failing to pass the value. I suppose it's because I don't know well neither LUA nor Minetest. Couldn't you give me a clue how to pass a variable?
I also tried to define a function to achieve the task:
and in on_activate() of the First run:
but without any success.
reason: I want to pass a custom value from one entity to another entity.
more info: There is an entity named "First", and in on_activate() I run this code o spawn a second entity and later to pass the value:
Code: Select all
second = minetest.add_entity(second_pos, "my_mod:two")
second.my_var = "ImportantValue"
I also tried to define a function to achieve the task:
Code: Select all
minetest.register_entity("my_mod:second", {
...
set_var = function()
self.my_var = "ImportantValue"
end,
})
Code: Select all
second:set_var("ImportantValue")
-
- New member
- Posts: 9
- Joined: Fri Aug 04, 2017 07:59
- GitHub: mezantrop
- Location: Brno, CZ
- Contact:
Re: Post your modding questions here
I have missed your reply, thank you very much! It looks like now I'm struggling on the way to pass values between first and second objects. And it seems that:orwell wrote: 1. set_attach means "attach this object (the object that the function is called on) to the specified one".
2. the attachment status is lost on unloading
So what you need to do is:
1. the first object needs to hold all relevant data
2. in the on_activate function of the first object, create the second object, give it a reference to the first object for data storage (if you need this) and call set_attach on the second object and give the first object as argument
3. "bone" just needs to be an empty string
4. the attachment position is the place where the second object is positioned relative to the first5.Code: Select all
first's on_activate() local second=add_entity(...) local secondle=second:get_luaentity() secondle.first_reference=self second:set_attach(self.object, ...)
Code: Select all
local secondle=second:get_luaentity()
secondle.first_reference=self
- v-rob
- Developer
- Posts: 970
- Joined: Thu Mar 24, 2016 03:19
- GitHub: v-rob
- IRC: v-rob
- Location: Right behind you.
How to fine tune schematics?
So, I don't quite understand everything about schematics. I can make them, import them, and make them spawn in a world naturally (like trees), but there are a few points I don't understand.
----- How do you make a schematic override another node? Take grass for example. I made a tree a few weeks ago, but when it spawned on grass, the grass was still there instead of the tree trunk.
Like this:
| = tree trunk
M = grass
""""" = ground
I
I
M
"""""
I want the schematic to override the grass (or any node that might also be there, mushroom, farming plant, plantlife stuff, etc.) with the tree trunk, but I can't seem to.
----- I've looked at default trees, and there are multiple versions, but only one schematic file. How does this work? I want to make multiple variations of one tree, and I have no idea how to.
----- How do you make a schematic override another node? Take grass for example. I made a tree a few weeks ago, but when it spawned on grass, the grass was still there instead of the tree trunk.
Like this:
| = tree trunk
M = grass
""""" = ground
I
I
M
"""""
I want the schematic to override the grass (or any node that might also be there, mushroom, farming plant, plantlife stuff, etc.) with the tree trunk, but I can't seem to.
----- I've looked at default trees, and there are multiple versions, but only one schematic file. How does this work? I want to make multiple variations of one tree, and I have no idea how to.
- azekill_DIABLO
- Member
- Posts: 7507
- Joined: Wed Oct 29, 2014 20:05
- GitHub: azekillDIABLO
- In-game: azekill_DIABLO
- Location: OMICRON
- Contact:
Re: Post your modding questions here
oh, okay.Gerald wrote:try turret:set_pos(pos)azekill_DIABLO wrote:I have this error with that code, why? can you help me?Code: Select all
ERROR[Main]: ServerError: AsyncErr: ServerThread::run Lua: Runtime error from mod 'azewheel' in callback luaentity_Step(): ...ames\minetest-0.4.16-win64\bin\..\mods\azewheel/tank.lua:105: bad argument #1 to 'set_pos' (userdata expected, got table)
Code: Select all
function tank_turret.on_step(self) --tank_turret is an entity local turret = self.object local pos = {x=playerpos.x, y=playerpos.y, z=playerpos.z} --the position of player is correct turret.set_pos(pos) -- this line causes the bug, but why? end
It does work! Thanks a lot!
Gone, but not dead. Contact me on discord: azekill_DIABLO#6565
DMs are always open if you want to get in touch!
DMs are always open if you want to get in touch!
- azekill_DIABLO
- Member
- Posts: 7507
- Joined: Wed Oct 29, 2014 20:05
- GitHub: azekillDIABLO
- In-game: azekill_DIABLO
- Location: OMICRON
- Contact:
Re: Post your modding questions here
problems with set attach
returns
Code: Select all
turret:set_attach(turret, "azewheel:tank", {x=0,y=0,z=0}, playeryaw)
Code: Select all
ERROR[Main]: ServerError: AsyncErr: ServerThread::run Lua: Runtime error from mod 'azewheel' in callback luaentity_Step(): Invalid position (expected table got number).
Gone, but not dead. Contact me on discord: azekill_DIABLO#6565
DMs are always open if you want to get in touch!
DMs are always open if you want to get in touch!
Re: Post your modding questions here
azekill_DIABLO wrote:Code: Select all
(expected table got number).
I am a noob. still yet. Not so noob ) [vml] WIP and a little proof for fun PlantedTorch )))
MT Strike 78a36b468554d101e0be3b0d1f587a555f396452 Great! Somebody have found it )
"My english isn't well" I know. I'm sorry )
MT Strike 78a36b468554d101e0be3b0d1f587a555f396452 Great! Somebody have found it )
"My english isn't well" I know. I'm sorry )
Re: Post your modding questions here
I think this would work.azekill_DIABLO wrote:problems with set attach
returnsCode: Select all
turret:set_attach(turret, "azewheel:tank", {x=0,y=0,z=0}, playeryaw)
Code: Select all
ERROR[Main]: ServerError: AsyncErr: ServerThread::run Lua: Runtime error from mod 'azewheel' in callback luaentity_Step(): Invalid position (expected table got number).
Code: Select all
turret:set_attach(turret, "azewheel:tank", {x=0,y=0,z=0}, minetest.yaw_to_dir(playeryaw))
Can your read this?
- azekill_DIABLO
- Member
- Posts: 7507
- Joined: Wed Oct 29, 2014 20:05
- GitHub: azekillDIABLO
- In-game: azekill_DIABLO
- Location: OMICRON
- Contact:
Re: Post your modding questions here
i'll try, thank you!
EDIT: it crashes the game with no debug. (the window close with the Window$ error message "app has stopped working")
maybe a more detailed code should be helpful
EDIT: i don't have a small idea on how to make it work. I followed the instructions, my values are correct, i followed the syntax of helicopter mod... but nothing to do it crashes the app or says that (it depends if I switch from self to self.object and if I remove yaw_to_dir)
EDIT: he is never happy. I cna't find doc on what I should do!
FINAL EDIT: i found a way out, it's all okay, except orientation, but i'm able to fix that! thanks!
EDIT: it crashes the game with no debug. (the window close with the Window$ error message "app has stopped working")
maybe a more detailed code should be helpful
Code: Select all
function tank_turret.on_step(self)
local turret = self.object
turret:set_attach(turret, "azewheel:tank", {x=0,y=0,z=0}, minetest.yaw_to_dir(playeryaw))
end
Code: Select all
(userdata expected, got table).
Code: Select all
(expected table got number).
FINAL EDIT: i found a way out, it's all okay, except orientation, but i'm able to fix that! thanks!
Gone, but not dead. Contact me on discord: azekill_DIABLO#6565
DMs are always open if you want to get in touch!
DMs are always open if you want to get in touch!
- azekill_DIABLO
- Member
- Posts: 7507
- Joined: Wed Oct 29, 2014 20:05
- GitHub: azekillDIABLO
- In-game: azekill_DIABLO
- Location: OMICRON
- Contact:
Re: Post your modding questions here
Code: Select all
local newdir = {x=0, y=playerdir.y, z=0}
turret:set_attach(tankself, "", {x=0,y=10,z=0}, newdir)
EDIT: after testing, i found that the API is not very well informed, coause it's not precised that set_attach() works with degrees, meanwhile all other functions works in radiant... which is a bit ilogical. Then if you use set_attach with the values of player:get_dir(), with the conversion from radiants to degrees... you will find that the XYZ axis from the player is different from the one of an attached entity. Example, the x of the player conresponds to the Y of the entity, which is a total absurdity.
viewtopic.php?f=5&t=18296
Gone, but not dead. Contact me on discord: azekill_DIABLO#6565
DMs are always open if you want to get in touch!
DMs are always open if you want to get in touch!
Re: Post your modding questions here
As I know it's because entity have a bone too, but for example Blender have by default opposite axis orientation or something like this.azekill_DIABLO wrote:Example, the x of the player conresponds to the Y of the entity, which is a total absurdity.
I am a noob. still yet. Not so noob ) [vml] WIP and a little proof for fun PlantedTorch )))
MT Strike 78a36b468554d101e0be3b0d1f587a555f396452 Great! Somebody have found it )
"My english isn't well" I know. I'm sorry )
MT Strike 78a36b468554d101e0be3b0d1f587a555f396452 Great! Somebody have found it )
"My english isn't well" I know. I'm sorry )
- azekill_DIABLO
- Member
- Posts: 7507
- Joined: Wed Oct 29, 2014 20:05
- GitHub: azekillDIABLO
- In-game: azekill_DIABLO
- Location: OMICRON
- Contact:
Re: Post your modding questions here
It remains a total absurdity because it seems impossible to use without workarounds...
Gone, but not dead. Contact me on discord: azekill_DIABLO#6565
DMs are always open if you want to get in touch!
DMs are always open if you want to get in touch!
Re: Post your modding questions here
The "front" of a node or entity is entirely arbitrary. It's what you determine it to be. So if you made a tank entity in blender, and export it so that with yaw=0 it's cannon points south-east then that would be just fine and dandy.Nyarg wrote:As I know it's because entity have a bone too, but for example Blender have by default opposite axis orientation or something like this.azekill_DIABLO wrote:Example, the x of the player conresponds to the Y of the entity, which is a total absurdity.
So if you attach a player to an entity, and now things are looking weird, then that's probably because you didn't consistently declare "front" the same in between the entity and the player. Most likely you exported the entity in blender with incorrect axes. Try re-exporting the entity with different export axes, so that the models are consistent.
- azekill_DIABLO
- Member
- Posts: 7507
- Joined: Wed Oct 29, 2014 20:05
- GitHub: azekillDIABLO
- In-game: azekill_DIABLO
- Location: OMICRON
- Contact:
Re: Post your modding questions here
it's not a blender model. It's a voxel model and it's facing the right way, as far as i know.... the problem is that when i use rotation it rotates differently if i face a way and another. It's inverted sometimes... can you show me a bit of code that makes an attached entity face the same deirection as the player?
Gone, but not dead. Contact me on discord: azekill_DIABLO#6565
DMs are always open if you want to get in touch!
DMs are always open if you want to get in touch!
Re: Post your modding questions here
What is a "Voxel model" ? This doesn't mean anything in minetest...azekill_DIABLO wrote:it's not a blender model. It's a voxel model and
Entities in minetest are either static models (.obj) or animated (.x or .b3d). I don't care what program where used to create them, but the fundamentals are all the same - axes are arbitrary and exporting them incorrectly may cause strange directions.
So if you set the yaw of the player to 0, and the yaw of the entity to 0, are they facing the same way? and after attachment with those yaws?
- v-rob
- Developer
- Posts: 970
- Joined: Thu Mar 24, 2016 03:19
- GitHub: v-rob
- IRC: v-rob
- Location: Right behind you.
Re: Post your modding questions here
How do I make a minecart force load chunks and them make them unload after it passes through? I'm pretty sure this has been made multiple times elsewhere, but I don't know how to.
- azekill_DIABLO
- Member
- Posts: 7507
- Joined: Wed Oct 29, 2014 20:05
- GitHub: azekillDIABLO
- In-game: azekill_DIABLO
- Location: OMICRON
- Contact:
Re: Post your modding questions here
oh, i said a voxel model, sorry. I mean a MagicaVoxel model. an .objsofar wrote:What is a "Voxel model" ? This doesn't mean anything in minetest...azekill_DIABLO wrote:it's not a blender model. It's a voxel model and
So if you set the yaw of the player to 0, and the yaw of the entity to 0, are they facing the same way? and after attachment with those yaws?
Trying...
they seem to be facing the same way. A question now: isn't the dir of set_attach based on the dir of the parent object? I seem to have forgotten that...
Gone, but not dead. Contact me on discord: azekill_DIABLO#6565
DMs are always open if you want to get in touch!
DMs are always open if you want to get in touch!
Re: Post your modding questions here
Code: Select all
floodables = {
{ name = "carts:rail"},
But when I add the above line in the floodable category it tells me that it's trying to overide a non-existent node. What am I supposed to do ?
- azekill_DIABLO
- Member
- Posts: 7507
- Joined: Wed Oct 29, 2014 20:05
- GitHub: azekillDIABLO
- In-game: azekill_DIABLO
- Location: OMICRON
- Contact:
Re: Post your modding questions here
Code: Select all
local tank360 = tankyaw*180/math.pi -- tank yaw to degrees
local player360 = playeryaw*180/math.pi -- player yaw to degrees
local turretdir = tank360+player360 -- the attach direction of the turret [CAUSE PROBLEM]
local newdir = {x=0, y=turretdir, z=0}
turret:set_attach(tankself, "", {x=0,y=6,z=0}, newdir)
EDIT: neverming, it was a - instead of a + at the problmatic line xD, that five days i'm working on that, i never been so happy! yeeee!
Gone, but not dead. Contact me on discord: azekill_DIABLO#6565
DMs are always open if you want to get in touch!
DMs are always open if you want to get in touch!
- Desour
- Member
- Posts: 1469
- Joined: Thu Jun 19, 2014 19:49
- GitHub: Desour
- IRC: Desour
- In-game: DS
- Location: I'm scared that if this is too exact, I will be unable to use my keyboard.
Re: Post your modding questions here
Does
I thought I had understood it correctly but now I'm not sure, maybe I'm doing it always wrong. >_<
here mean that it's deprecated to use the "initial_properties" field that is directly beyond this and the reason for that is that now everything in object properties is read directly from here or that it's deprecated that everything in object properties is read directly from there?lua_api.txt wrote:Deprecated: Everything in object properties is read directly from here
I thought I had understood it correctly but now I'm not sure, maybe I'm doing it always wrong. >_<
he/him; Codeberg; GitHub; ContentDB; public personal TODO list; "DS" is preferred (but often too short)
Re: Post your modding questions here
Title: How to create a function that unlock a craft and only for one person ?
Reason: I want to make a research mod like in the minecraft mod Ancient Warfare 2
More info: I have already do the interface but I don't know how to do this.
Reason: I want to make a research mod like in the minecraft mod Ancient Warfare 2
More info: I have already do the interface but I don't know how to do this.
Sorry if my english isn't good.
I love making mesecon mechanisms. If you want a system, just tell it to me and I will try to make it.
I love making mesecon mechanisms. If you want a system, just tell it to me and I will try to make it.
-
- Member
- Posts: 818
- Joined: Tue Apr 14, 2015 01:59
- GitHub: raymoo
- IRC: Hijiri
- In-game: Raymoo + Clownpiece
Re: Post your modding questions here
You will have to do more than just make one function. Minetest doesn't have any built-in craft recipe unlocking mechanism so you will have to write it yourself (I assume the same thing is true for Minecraft).Baryhobal wrote:Title: How to create a function that unlock a craft and only for one person ?
Reason: I want to make a research mod like in the minecraft mod Ancient Warfare 2
More info: I have already do the interface but I don't know how to do this.
First of all, you will need to keep track of what recipes the player has access to. I would recommend representing this as a "set" (a table where the keys are the values in the set, and the values are all true) of the names of the recipe output items. You can store it as a player attribute using the set_attribute and get_attribute methods of players (https://github.com/minetest/minetest/bl ... .txt#L3279) to store the table after turning it into a string with minetest.write_json (https://github.com/minetest/minetest/bl ... .txt#L2979).
Secondly, to actually prevent the player from crafting the unlockable items, you will need to intercept the crafting attempts and prevent that craft from happening. For this you will need to use minetest.register_on_craft and minetest.register_craft_predict (https://github.com/minetest/minetest/bl ... .txt#L2347). In the callback you pass to register_on_craft, you would check if the player has access to the item, and if not, return an empty ItemStack. If they have access to the item then you let it be (return nil or the original ItemStack). The callback you pass to register_craft_predict should do the same thing (just pass the same function to both).
After you have done all that you can write a function that unlocks a craft for a player, by getting the attribute that stores the unlock table, deserializing it (with minetest.parse_json), adding the item name, then serializing it and storing it back again to the attribute.
Every time a mod API is left undocumented, a koala dies.
Re: Post your modding questions here
Ok thanks I will try it
Sorry if my english isn't good.
I love making mesecon mechanisms. If you want a system, just tell it to me and I will try to make it.
I love making mesecon mechanisms. If you want a system, just tell it to me and I will try to make it.
- BirgitLachner
- Member
- Posts: 393
- Joined: Thu May 05, 2016 10:18
- In-game: Bibs
Re: Post your modding questions here
Hi again ...
I wanted to have a couple of nodes that are quite similar und want to use a function to register them easily. But I get an error wtha I dont understand. Here is my code:
The first nodes are okay, but the function gives an error.
Line 14 is the "line" with "function ..."
What do I miss?
EDIT Got it ...
if I define
it works. I thought that "edusigns" is already there ...
I wanted to have a couple of nodes that are quite similar und want to use a function to register them easily. But I get an error wtha I dont understand. Here is my code:
Code: Select all
minetest.register_node("edusigns:symbol_1", {
description = "Number 1",
tiles = {"symbol_empty.png","symbol_empty.png","symbol_1.png","symbol_1.png","symbol_1.png","symbol_1.png"},
groups = {oddly_breakable_by_hand=2},
})
minetest.register_node("edusigns:symbol_2", {
description = "Number 1",
tiles = {"symbol_empty.png","symbol_empty.png","symbol_2.png","symbol_2.png","symbol_2.png","symbol_2.png"},
groups = {oddly_breakable_by_hand=2},
})
function edusigns.register_infonodes(what)
minetest.register_node("edusigns:symbol_"..what, {
description = "Number "..what,
tiles = {"symbol_empty.png","symbol_empty.png","symbol_"..what..".png","symbol_"..what..".png","symbol_"..what..".png","symbol_"..what..".png"},
groups = {oddly_breakable_by_hand=2},
})
end
edusigns.register_infonodes("3")
Code: Select all
Undeclared global variable "edusigns" accessed at /home/birgit/.minetest/mods/edusigns/init.lua:14
2017-08-21 09:49:59: ERROR[Main]: ModError: Failed to load and run script from /home/birgit/.minetest/mods/edusigns/init.lua:
2017-08-21 09:49:59: ERROR[Main]: /home/birgit/.minetest/mods/edusigns/init.lua:14: attempt to index global 'edusigns' (a nil value)
2017-08-21 09:49:59: ERROR[Main]: stack traceback:
2017-08-21 09:49:59: ERROR[Main]: /home/birgit/.minetest/mods/edusigns/init.lua:14: in main chunk
What do I miss?
EDIT Got it ...
if I define
Code: Select all
edusigns={}
Re: Post your modding questions here
With entries in depends.txt it is possible for a mod to check if other needed mods are installed.
Is it possible to check for a minimum version of the minetest-engine (e.g."needs 0.4.16-dev") ?
Is it possible to check for a minimum version of the minetest-engine (e.g."needs 0.4.16-dev") ?
'My' wiki-pages: Build-a-home - basic-robot - basic_robot_csm - basic-machines - digtron - xdecor -
Map-Database
Map-Database
Who is online
Users browsing this forum: No registered users and 5 guests