Getting the name of the node below a node?

User avatar
scifiboi
Member
 
Posts: 96
Joined: Wed Jul 18, 2012 21:28

Getting the name of the node below a node?

by scifiboi » Wed Feb 20, 2013 01:08

I am trying to get whether or not a node has been placed in a spot where there is either dirt or dirt with grass directly underneath it. Here is the code I currently have, but it doesn't work. It only throws a lua exception.

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 nodePlantedPos = pos
nodePlantedPos.y = nodePlanted.y - 1
local nodePlanted = minetest.env:get_node(nodePlantedPos)
if (nodePlanted.name ~= "default:dirt" or "default:dirt_with_grass") then return end


The code after this is to make my sapling grow into a tree. It works. This is the section that I am having trouble getting to work. I'm not sure what's going wrong. It seems as if I have tried everything but the right way to get this to work. All help is much appreciated!
This is a signature virus. Add me to your signature so that I can multiply.
My mod: Thaumtest
 

lkjoel
Member
 
Posts: 778
Joined: Wed Feb 29, 2012 19:27

by lkjoel » Wed Feb 20, 2013 01:55

scifiboi wrote:I am trying to get whether or not a node has been placed in a spot where there is either dirt or dirt with grass directly underneath it. Here is the code I currently have, but it doesn't work. It only throws a lua exception.

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 nodePlantedPos = pos
nodePlantedPos.y = nodePlanted.y - 1
local nodePlanted = minetest.env:get_node(nodePlantedPos)
if (nodePlanted.name ~= "default:dirt" or "default:dirt_with_grass") then return end


The code after this is to make my sapling grow into a tree. It works. This is the section that I am having trouble getting to work. I'm not sure what's going wrong. It seems as if I have tried everything but the right way to get this to work. All help is much appreciated!

Sorry, too lazy to try it out... could you paste the exception?
My mods: The Nether | Doctor Who (WIP)

I have quit minetest ... again. I am heavily unimpressed by both the game and the community.
 

User avatar
scifiboi
Member
 
Posts: 96
Joined: Wed Jul 18, 2012 21:28

by scifiboi » Wed Feb 20, 2013 02:00

In the game window:

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
ServerError: LuaError: Error:
rubber.lua:69 Attempt to index


and in the console:

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
ServerError: LuaError: Error:
rubber.lua:69 Attempt to index global 'nodePlanted' (a nil value)
This is a signature virus. Add me to your signature so that I can multiply.
My mod: Thaumtest
 

lkjoel
Member
 
Posts: 778
Joined: Wed Feb 29, 2012 19:27

by lkjoel » Wed Feb 20, 2013 02:07

scifiboi wrote:-snip-

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
ServerError: LuaError: Error:
rubber.lua:69 Attempt to index global 'nodePlanted' (a nil value)

Okay, first of all, the game window never says anything useful xD (just look at the console, it says EVERYTHING!)

Second, the error is that it can't find the variable: "nodePlanted", because it doesn't exist when you accessed it on this line:
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
nodePlantedPos.y = nodePlanted.y - 1
--                     ^^^

So fix it by this:
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
nodePlantedPos.y = nodePlantedPos.y - 1
Last edited by lkjoel on Wed Feb 20, 2013 02:08, edited 1 time in total.
My mods: The Nether | Doctor Who (WIP)

I have quit minetest ... again. I am heavily unimpressed by both the game and the community.
 

User avatar
scifiboi
Member
 
Posts: 96
Joined: Wed Jul 18, 2012 21:28

by scifiboi » Wed Feb 20, 2013 02:19

Wow, don't I feel silly right now. :P Okay so the exception is no longer being thrown, but the sapling won't grow even when it is on top of dirt or dirt with grass. :
This is a signature virus. Add me to your signature so that I can multiply.
My mod: Thaumtest
 

lkjoel
Member
 
Posts: 778
Joined: Wed Feb 29, 2012 19:27

by lkjoel » Wed Feb 20, 2013 02:23

scifiboi wrote:Wow, don't I feel silly right now. :P Okay so the exception is no longer being thrown, but the sapling won't grow even when it is on top of dirt or dirt with grass. :

Haha, don't, I do the same kinds of mistakes all of the time (I remember I spent a couple hours trying to fix my rather complex algorithms, while the issue was that I had misspelled "brakes" to "breaks" lol)

Could you paste your code?
My mods: The Nether | Doctor Who (WIP)

I have quit minetest ... again. I am heavily unimpressed by both the game and the community.
 

User avatar
BrandonReese
Member
 
Posts: 836
Joined: Wed Sep 12, 2012 00:44
GitHub: bremaweb
IRC: BrandonReese
In-game: BrandonReese

by BrandonReese » Wed Feb 20, 2013 02:59

This line

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
if (nodePlanted.name ~= "default:dirt" or "default:dirt_with_grass") then return end


Should be

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
if (nodePlanted.name ~= "default:dirt" and nodePlanted.name ~= "default:dirt_with_grass") then return end


In the top code "default:dirt_with_grass" will always be true... there is no real evaluation going on, and since you were using an 'or' either side can evaluate to true and it will execute the code after 'then'... so that line of code will always 'return end'

The bottom code will only 'return end' if both sides of the 'and' are true.


Good catch on the typo, lkjoel. I didn't see that one, I make that mistake a lot too especially with languages where the variables are case sensitive... (ie nodePlanted is not the same as nodeplanted)
Last edited by BrandonReese on Wed Feb 20, 2013 03:11, edited 1 time in total.
 

User avatar
scifiboi
Member
 
Posts: 96
Joined: Wed Jul 18, 2012 21:28

by scifiboi » Wed Feb 20, 2013 03:26

Wow! That worked! Thank you bunches! Expect more questions later because I am a total noob with lua. :P By the way, ikjoel, I really like your nether mod! It is awesome, but if I stay there for more than 5 minutes or so, minetest freezes up. I assume it's because of my super-slow computer, though.
This is a signature virus. Add me to your signature so that I can multiply.
My mod: Thaumtest
 

lkjoel
Member
 
Posts: 778
Joined: Wed Feb 29, 2012 19:27

by lkjoel » Wed Feb 20, 2013 03:29

scifiboi wrote:Wow! That worked! Thank you bunches! Expect more questions later because I am a total noob with lua. :P By the way, ikjoel, I really like your nether mod! It is awesome, but if I stay there for more than 5 minutes or so, minetest freezes up. I assume it's because of my super-slow computer, though.

Oh sure, that's what this forum is for!

Thanks, hmm... any error logs in the output?
My mods: The Nether | Doctor Who (WIP)

I have quit minetest ... again. I am heavily unimpressed by both the game and the community.
 

User avatar
scifiboi
Member
 
Posts: 96
Joined: Wed Jul 18, 2012 21:28

by scifiboi » Wed Feb 20, 2013 03:34

Nope, none. Just the game freezes up.
This is a signature virus. Add me to your signature so that I can multiply.
My mod: Thaumtest
 

lkjoel
Member
 
Posts: 778
Joined: Wed Feb 29, 2012 19:27

by lkjoel » Wed Feb 20, 2013 03:35

scifiboi wrote:Nope, none. Just the game freezes up.

Weird... how long did you wait for it to un-freeze?
My mods: The Nether | Doctor Who (WIP)

I have quit minetest ... again. I am heavily unimpressed by both the game and the community.
 

User avatar
scifiboi
Member
 
Posts: 96
Joined: Wed Jul 18, 2012 21:28

by scifiboi » Wed Feb 20, 2013 03:37

About 30 minutes. I left the computer to see if anything happened. As far as I could see, nothing on the screen changed. I'm pretty sure it was because of the mod using up so much of my memory.
This is a signature virus. Add me to your signature so that I can multiply.
My mod: Thaumtest
 

lkjoel
Member
 
Posts: 778
Joined: Wed Feb 29, 2012 19:27

by lkjoel » Wed Feb 20, 2013 03:39

scifiboi wrote:About 30 minutes. I left the computer to see if anything happened. As far as I could see, nothing on the screen changed. I'm pretty sure it was because of the mod using up so much of my memory.

Yeah, that'd make sense. I'm working on a new version which should be at least 100-200x faster, and use... hmm... around 1000-10,000x less memory. How? I'll use C to do all the heavy work :P
My mods: The Nether | Doctor Who (WIP)

I have quit minetest ... again. I am heavily unimpressed by both the game and the community.
 

User avatar
scifiboi
Member
 
Posts: 96
Joined: Wed Jul 18, 2012 21:28

by scifiboi » Wed Feb 20, 2013 03:40

That will be great! I will definitely use it if you can get it to work fast and it will be a great addition to my industry mod with the netherrack and such! :)
This is a signature virus. Add me to your signature so that I can multiply.
My mod: Thaumtest
 

lkjoel
Member
 
Posts: 778
Joined: Wed Feb 29, 2012 19:27

by lkjoel » Wed Feb 20, 2013 03:45

scifiboi wrote:That will be great! I will definitely use it if you can get it to work fast and it will be a great addition to my industry mod with the netherrack and such! :)

Awesome! Netherrack being used in industry? O_o. I don't think I want to know what it does :P jk
My mods: The Nether | Doctor Who (WIP)

I have quit minetest ... again. I am heavily unimpressed by both the game and the community.
 


Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 6 guests

cron