Make dirt head debugging an option, and disable head_code by default if has_head is not defined. #402
No reviewers
Labels
No Label
bug
contribution inside
CRITICAL
discussion
ELEVATED PRIORITY
fresh ideas
HIGH PRIORITY
missing feature
offtopic
requires engine change
No Milestone
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: MineClone5/MineClone5#402
Loading…
Reference in New Issue
No description provided.
Delete Branch ":fix-heads"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes #384
Fixes #383
Thanks to suggestions from @MrRar
Side note: I really need to fix my keys.
@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:
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.
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.
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
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.
@ -37,0 +33,4 @@
size = 1,
texture = "default_dirt.png",
})
end
This "end" line 36 needs to be indented.
The things you inserted are actual tab characters.
I have not tried emacs but I did try VIM. It's terrible.
PRs welcome. Mineclone mobs are garbage.
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
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.
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.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.
@ -6,3 +6,3 @@
return yaw*180.0/math.pi
end
local debug_head = minetest.settings:get_bool("mcl_debug_head_code", false)
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.
Fixed indentation, Shoudld be good now, Also moved the variable to align with the others. Learned alot from this pull request.
RIP git log
i entirely agree