Make dirt head debugging an option, and disable head_code by default if has_head is not defined. #402

Merged
MrRar merged 11 commits from :fix-heads into master 2022-08-10 20:15:21 +02:00
Contributor
  1. Make dirt head debugging an option
  2. Disable head code by default and makes has_head somewhat useful.

Fixes #384
Fixes #383

Thanks to suggestions from @MrRar

Side note: I really need to fix my keys.

1. Make dirt head debugging an option 2. Disable head code by default and makes has_head somewhat useful. Fixes #384 Fixes #383 Thanks to suggestions from @MrRar Side note: I really need to fix my keys.
fbievan added 2 commits 2022-08-07 17:35:27 +02:00
fbievan added 2 commits 2022-08-07 17:46:11 +02:00
Owner

@fbievan The code itself looks good but it needs to be indented correctly. The two if statements are inside a function so they need to be indented one level. The minetest.add_particle call needs to be pushed to the right by an additional indentation level. Make sure to use tabs instead of spaces for indentation.

So it should look like:

function example()
	if minetest.settings:get_bool("mcl_debug_head_code", false) then
		minetest.add_particle({
			pos = pos,
			velocity = {x=0, y=0, z=0},
			acceleration = {x=0, y=0, z=0},
			expirationtime = 0.2,
			size = 1,
			texture = "default_dirt.png",
		})
	end
end

Congratulations on starting to learn programming Lua!

BTW you never need to close a PR you can always rename it and force push to the corresponding branch.

@fbievan The code itself looks good but it needs to be indented correctly. The two if statements are inside a function so they need to be indented one level. The minetest.add_particle call needs to be pushed to the right by an additional indentation level. Make sure to use tabs instead of spaces for indentation. So it should look like: ``` function example() if minetest.settings:get_bool("mcl_debug_head_code", false) then minetest.add_particle({ pos = pos, velocity = {x=0, y=0, z=0}, acceleration = {x=0, y=0, z=0}, expirationtime = 0.2, size = 1, texture = "default_dirt.png", }) end end ``` Congratulations on starting to learn programming Lua! BTW you never need to close a PR you can always rename it and force push to the corresponding branch.
fbievan added 1 commit 2022-08-08 00:36:43 +02:00
Author
Contributor

Should be formatted properly now. (I think), emacs for some reason makes ghost spaces when i press TAB. Mostly closed orginal pull request because the orginal intention of that pull request, is kind of far from this one. Kinda bumbling around right now, however: editing this project is super simple. Honestly could go hours editing and modifying MineClone5. I have some more changes that i want too add to the ghast too, but i'll sumbit those later.

Should be formatted properly now. (I think), emacs for some reason makes ghost spaces when i press TAB. Mostly closed orginal pull request because the orginal intention of that pull request, is kind of far from this one. Kinda bumbling around right now, however: editing this project is super simple. Honestly could go hours editing and modifying MineClone5. I have some more changes that i want too add to the ghast too, but i'll sumbit those later.
MrRar requested changes 2022-08-08 15:45:57 +02:00
MrRar left a comment
Owner

The indentation is mostly good but I did find one issue. The setting should not be looked up on every function call.

The indentation is mostly good but I did find one issue. The setting should not be looked up on every function call.
@ -34,3 +27,1 @@
texture = "default_dirt.png",
})
if minetest.settings:get_bool("mcl_debug_head_code", false) then
Owner

This setting should be cached to a local variable so the setting does not need to be looked up for every call to this function. Sorry I did not point this out in my prior code review. The variable should not be in the body of the function but just above it.

This is important because this function can get called multiple times per server tick.

This setting should be cached to a local variable so the setting does not need to be looked up for every call to this function. Sorry I did not point this out in my prior code review. The variable should not be in the body of the function but just above it. This is important because this function can get called multiple times per server tick.
fbievan marked this conversation as resolved
@ -37,0 +33,4 @@
size = 1,
texture = "default_dirt.png",
})
end
Owner

This "end" line 36 needs to be indented.

This "end" line 36 needs to be indented.
fbievan marked this conversation as resolved
Owner

Should be formatted properly now. (I think)

The things you inserted are actual tab characters.

emacs for some reason makes ghost spaces when i press TAB.

I have not tried emacs but I did try VIM. It's terrible.

I have some more changes that i want too add to the ghast too, but i'll sumbit those later.

PRs welcome. Mineclone mobs are garbage.

> Should be formatted properly now. (I think) The things you inserted are actual tab characters. > emacs for some reason makes ghost spaces when i press TAB. I have not tried emacs but I did try VIM. It's terrible. > I have some more changes that i want too add to the ghast too, but i'll sumbit those later. PRs welcome. Mineclone mobs are garbage.
fbievan requested review from MrRar 2022-08-08 16:49:49 +02:00
fbievan added 1 commit 2022-08-08 16:53:43 +02:00
Author
Contributor

I see what you mean, it calls that function, I think

	local debug_head =  minetest.settings:get_bool("mcl_debug_head_code", false) 
	if debug_head then

should work.

No minetest.settings:get_bool("mcl_debug_head_code", false) will be executed for every function call in this case.

The solution is to put the variable decaration at the root level in the file. That way it will only be executed when the file is loaded when the game is starting. debug_head stores the result of the minetest.settings:get_bool("mcl_debug_head_code", false) call (either true or false). The if statement just needs to check if debug_head is true or false.

> I see what you mean, it calls that function, I think > ``` > local debug_head = minetest.settings:get_bool("mcl_debug_head_code", false) > if debug_head then > ``` > should work. No `minetest.settings:get_bool("mcl_debug_head_code", false)` will be executed for every function call in this case. The solution is to put the variable decaration at the root level in the file. That way it will only be executed when the file is loaded when the game is starting. debug_head stores the result of the `minetest.settings:get_bool("mcl_debug_head_code", false)` call (either true or false). The if statement just needs to check if debug_head is true or false.
fbievan added 1 commit 2022-08-08 17:33:02 +02:00
fbievan added 1 commit 2022-08-08 22:50:55 +02:00
Author
Contributor

I see what you mean, it calls that function, I think

	local debug_head =  minetest.settings:get_bool("mcl_debug_head_code", false) 
	if debug_head then

should work.

No minetest.settings:get_bool("mcl_debug_head_code", false) will be executed for every function call in this case.

The solution is to put the variable decaration at the root level in the file. That way it will only be executed when the file is loaded when the game is starting. debug_head stores the result of the minetest.settings:get_bool("mcl_debug_head_code", false) call (either true or false). The if statement just needs to check if debug_head is true or false.

Is there a good way to debug this? I've looked inside minetest verbose mode and couldnt get anything releated to this.

It feels kinda weird having that being edited by you. Just kinda, but uh i think this should now fix it if im not really dumb and missed something else. Really first time i've done something productive with lua. From what i can tell, something is calling function

mobs.do_head_logic = function(self, dtime, player)

then repeatdly executing that. Moving it above it should therotically not have it run over and over again? Sorry if i am missing something obvious. If "if" statements work how i expect them to, they should call the variable "debug_head". Thought about putting it into mcl_init, but that just wouldnt make sense to make it a global variable. Lua documentation can sometimes be iffy. I have one question:

does the local variable call that function by itself and store that value, if not how would i therotically approach if i wanted to only store something once.

> > > > I see what you mean, it calls that function, I think > > ``` > > local debug_head = minetest.settings:get_bool("mcl_debug_head_code", false) > > if debug_head then > > ``` > > should work. > > No `minetest.settings:get_bool("mcl_debug_head_code", false)` will be executed for every function call in this case. > > The solution is to put the variable decaration at the root level in the file. That way it will only be executed when the file is loaded when the game is starting. debug_head stores the result of the `minetest.settings:get_bool("mcl_debug_head_code", false)` call (either true or false). The if statement just needs to check if debug_head is true or false. Is there a good way to debug this? I've looked inside minetest verbose mode and couldnt get anything releated to this. It feels kinda weird having that being edited by you. Just kinda, but uh i think this should now fix it if im not really dumb and missed something else. Really first time i've done something productive with lua. From what i can tell, something is calling function ``` mobs.do_head_logic = function(self, dtime, player) ``` then repeatdly executing that. Moving it above it should therotically not have it run over and over again? Sorry if i am missing something obvious. If "if" statements work how i expect them to, they should call the variable "debug_head". Thought about putting it into mcl_init, but that just wouldnt make sense to make it a global variable. Lua documentation can sometimes be iffy. I have one question: does the local variable call that function by itself and store that value, if not how would i therotically approach if i wanted to only store something once.
Owner

Is there a good way to debug this? I've looked inside minetest verbose mode and couldnt get anything releated to this.

No not directly. If you put a minetest.chat_send_all() call at the top of the function you will get a chat message whenever the function gets called. There maybe other/better ways I don't know. DBG (https://forum.minetest.net/viewtopic.php?t=28372&p=412304) maybe useful but I have not been able to test it.

does the local variable call that function by itself and store that value, if not how would i therotically approach if i wanted to only store something once.

If a veriable is inside a function it is not saved after the function returns. On the next function call it is recreated. If you want a variable to persist between function calls you have to put it at the root level in the file.

> Is there a good way to debug this? I've looked inside minetest verbose mode and couldnt get anything releated to this. No not directly. If you put a `minetest.chat_send_all()` call at the top of the function you will get a chat message whenever the function gets called. There maybe other/better ways I don't know. DBG (https://forum.minetest.net/viewtopic.php?t=28372&p=412304) maybe useful but I have not been able to test it. > does the local variable call that function by itself and store that value, if not how would i therotically approach if i wanted to only store something once. If a veriable is inside a function it is not saved after the function returns. On the next function call it is recreated. If you want a variable to persist between function calls you have to put it at the root level in the file.
MrRar requested changes 2022-08-09 18:29:00 +02:00
@ -6,3 +6,3 @@
return yaw*180.0/math.pi
end
local debug_head = minetest.settings:get_bool("mcl_debug_head_code", false)
Owner

Fix the indentation of the debug_head variable and I think we are good.

I did test your branch and it works so I realy think that is the last thing.

Fix the indentation of the debug_head variable and I think we are good. I did test your branch and it works so I realy think that is the last thing.
fbievan marked this conversation as resolved
fbievan added 1 commit 2022-08-09 19:36:44 +02:00
Author
Contributor

Fixed indentation, Shoudld be good now, Also moved the variable to align with the others. Learned alot from this pull request.

Fixed indentation, Shoudld be good now, Also moved the variable to align with the others. Learned alot from this pull request.
fbievan added 1 commit 2022-08-09 19:42:52 +02:00
fbievan added 1 commit 2022-08-09 19:44:03 +02:00
fbievan requested review from MrRar 2022-08-09 19:46:48 +02:00
MrRar merged commit a50255cb97 into master 2022-08-10 20:15:21 +02:00
Owner

RIP git log

RIP git log
Author
Contributor

RIP git log

i entirely agree

> RIP git log i entirely agree
fbievan deleted branch fix-heads 2022-08-11 16:43:58 +02:00
Sign in to join this conversation.
No description provided.