Mobkit - Entity API [mobkit][alpha]

User avatar
ElCeejo
Member
Posts: 66
Joined: Thu Feb 28, 2019 23:29
In-game: ElCeejo
Location: The darkest corner in your house

Re: Mobkit - Entity API [mobkit][alpha]

by ElCeejo » Post

Walking underwater. Pretty much just ignoring the water entirely so it would walk along the bottom instead of floating and wouldn't avoid walking into water.

Termos
Member
Posts: 310
Joined: Sun Dec 16, 2018 12:50

Re: Mobkit - Entity API [mobkit][alpha]

by Termos » Post

ElCeejo wrote:Is there a way of letting mobs freely roam through water as if they were on land aside from rewriting half of mobkit?
I recommend setting buoyancy slightly greater than 1.

The parameter affects the balance between gravity and buoyancy force, it's defined as percentage of collisionbox submerged in water so for example if you set it to 0.8 then 20% will stick above water.
> 1.0 will make them sink
== 1.0 is zero buoyancy, useful for fish with bladders, submarines etc.
< 0.0 should give an MC-like bouncy water effect

If you really want them to completely ignore water, you could override 'physics' entity field with a custom function, but I wouldn't do that, it doesn't look right if water doesn't give any impression it's there.

User avatar
Wuzzy
Member
Posts: 3938
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy

Re: Mobkit - Entity API [mobkit][alpha]

by Wuzzy » Post

It's an interesting new approach to how to do mobs. I appreciate any experimentation and exploration done in the name of mobs. Because Minetest still does very poorly in this area.


However, judging from the example code, I have the impression that it's hard work for any real-world usage. This is a low-level API and it gives you almost nothing for free. So maybe this is by design, and I kinda understand.

But I think this makes it pretty impractical for real-world usage.

The example mobs have a huge amount of custom code, which isn't pretty. It looks like there isn't any primitive for stuff like “swimming” or “walking” …

I think it will be hard to use for real games which tend to register lots of similar mobs. The heart of this API seems to be the brain function which you must define for all mobs. In real games, you tend to create a lot of mobs that are similar, with only a minor behavior change. But it seems you are forced to re-register a complete new function for those again.
Basically for each new mob you add, you basically start from zero again.

The brain function is also much more than just behavior. You not only must define how it behaves, but also when it takes damage. Not even damage comes for free. In fact, it seems you have to manually hack in damage handing for every mob. Why you are even forced to include the damage handling inside the brain function is beyond me. Why isn't this at least separated logically? If I want to add a new way to damage mobs, all hell breaks lose, as suddenly I have to update dozens of mobs by hand.

This looks like for any real world usage you will be forced to create a lot of code duplication, or to just write lots of mob-specific code for rather basic behavior.

Another reason why I think this is too low-level, the internals of Minetest entities bleed out everywhere.

This API doesn't even give you a “register mob” function. Instead, you must call minetest.register_entity with some callback functions set to predefined defaults (=boilerplate). This is very bad IMO, as soon the required boilerplate changes, all mobs will break and need to be updated by hand.

I think my biggest issue with this mod is that the way it is designed right now looks like I am forced.
It seems I don't win much above just directly registering my mob as entity and do *everything* by hand. This mod looks more like a collection of utility functions instead of a fully functional API.
A good API helps you to reduce the amount of code, not increase it.


Anyway, I accept this mod is still in WIP. Some of the concepts I read about are likable, for example the concept of using queues for behavior. I also don't want to say this mod is useless, you obviously can still make interesting mobs with it. My issues is just that it needs lots of low-level code. I also suppose this mod is great if you want to experiment with unorthodox mob behaviors just for fun. But for creating an actual game with it … I think this mod still needs a lot of work.

I'm also not saying this mod is ultimately doomed. Maybe what this mod needs is just more convenience functions and functions that help you to reduce annoying code duplication. I don't want to teach each mob individually how to take damage.

Note that I only looked at this mod rather superficially, so I probably made mistakes.
My creations. I gladly accept bitcoins: 17fsUywHxeMHKG41UFfu34F1rAxZcrVoqH

User avatar
ElCeejo
Member
Posts: 66
Joined: Thu Feb 28, 2019 23:29
In-game: ElCeejo
Location: The darkest corner in your house

Re: Mobkit - Entity API [mobkit][alpha]

by ElCeejo » Post

"Mobkit differs significantly in this regard to typical MT mob mods where you have a ready to go code and toggle switches.
This is an api that gives you infinitely more possibilities, but requires coding." - Termos

This API is a lot more advanced than mobs_redo and so registering mobs, as Termos said, will require more coding. I do agree that it would be nice to have something as easy to use as mobs_redo that would still have all the advanced functionality of mobkit but who knows, maybe somebody has already been working on it ;)

User avatar
Lone_Wolf
Member
Posts: 2328
Joined: Sun Apr 09, 2017 05:50
GitHub: LoneWolfHT
IRC: Lone_Wolf or LoneWolfHT
In-game: Lone_Wolf
Location: Not there, THERE!

Re: Mobkit - Entity API [mobkit][alpha]

by Lone_Wolf » Post

In reply to Wuzzy:
There are functions for walking, attacking, and much more
I recommend looking at and testing the mob mods that use this API. I've found mobkit a lot easier to use that mobs_redo, considering the quality of the mob you get from your work.
You should also note that mobkit isn't only for mobs, IIRC Termos did a sailboat mod with it

Gundul
Member
Posts: 845
Joined: Thu Aug 27, 2015 10:55
GitHub: berengma
IRC: Gundul
Location: Europe/Asia

Re: Mobkit - Entity API [mobkit][alpha]

by Gundul » Post

Wuzzy wrote:
I'm also not saying this mod is ultimately doomed. Maybe what this mod needs is just more convenience functions and functions that help you to reduce annoying code duplication. I don't want to teach each mob individually how to take damage.

Note that I only looked at this mod rather superficially, so I probably made mistakes.
I think you misunderstood some things. Maybe you should try using this api before judging it.
The heart are the lq and hq behaviors. This gives you a powerful tool to exactly control what your
mobs do or not. The brain only controls when are which behaviors to be used.

If you are lazy and like convenience it is pretty easy to just define a few behaviors for carnivore,herbivore,land
and sea animal and that's it. You can use any behavior with any mob and even only one brain for all if you want to.
But like this the mob will end up like many do, sharing just only one brain XD.
Basic behaviors are already provided in the api, as long as you stick to collisionboxes not bigger than 1 node,
there is not too much you have to code.

And one other thing, this api has an extremly low impact on hardware. It is possible to run water_life mod and mobkit on a raspberry pi2.
Anything camparable to this together with mobs_redo and you would not even be able to connect more than one player. I tried it :)

In the end I would recommend an other strategy: less convenience and more responsibility and power to the
modder. Otherwise you will end up with a second mobs_redo, which nobody needs and will vanish in wide universe
of forgotten apis in this forum.
My servers: Jungle, Lilly in the valley, ZombieTest

Termos
Member
Posts: 310
Joined: Sun Dec 16, 2018 12:50

Re: Mobkit - Entity API [mobkit][alpha]

by Termos » Post

Wuzzy, it's nice of you to stop by.
Like it or not, you might just be a godfather of this project, in a sense. Mobs in MCL2 were so goddamn horrible so it might have been the most important drop that spilled the bucket and made me decide mobs/entities were the most neglected aspect of MT.
Wuzzy wrote:This mod looks more like a collection of utility functions instead of a fully functional API.
Yes it does! An API is supposed to be that, more or less.
The concept of an API seems to be largely misunderstood in this community, this is most puzzling as everyone uses minetest api, which is definitely api like. Yet there are self contained mods out there that go and claim to be apis even though there's nothing for an Application Program to Interface with.

That's why I think you seem to take issue with an API for being an API, as opposed to a switch flippin mod with customizable skins you're used to.

Yes, it is relatively low level, built on a yet lower level minetest API, and in turn free to be built upon, that how things are done, and that's the idea.
Yes, you need to handle damage yourself, see, there are infinitely many ways for damage to work, not only the one you know, in fact one of the examples, zombiestrd, does damage quite differently. But even if using the same damage model for all mobs and code duplication is your biggest concern, just code one wrapper for it, no duplication if you know what you're doing.
Yes, the examples contain a fair amount of code, that's because they are examples and their function is to help understand how to code using this api, but if I were trying to make mobs that work like those from MCL2, the code would be closer to about five lines long.

I kind of shared some of your concerns when starting out, but they weren't really concerns, because for me this was just a for fun project, something to occupy my fingertips during occasional quiet night shifts, so I didn't really care. I expected it to bee too complex for people to use, and me to get bored after a few months.
But it turns out runs and Gundul for example, already are doing pretty amazing stuff with it even at this early stage, so yeah, it's been fun and we're just gonna see where it takes us, cheers.

User avatar
runs
Member
Posts: 1562
Joined: Sat Oct 27, 2018 08:32
GitHub: runsy

Re: Mobkit - Entity API [mobkit][alpha]

by runs » Post

Basically for each new mob you add, you basically start from zero again.
No really. Thermos say to me that that was the better method but in my petz mod I did the opposite, only 5 brains for all kind of mobs. Then specific behaviours inside each brain are selected via particular mob properties or calling external functions.

So you can elaborate one brain for all the mobs or a brain for each mob. So it is totally flexible.
Another reason why I think this is too low-level
Yes it is very low level, is a API for an engine, not a mob kit, so the name of the mod is wrong it should be mobengine or mobapi LOL.
The core of mobkit is an engine based on HQ and LQ functions and two quees to execute then. No more. Well, Thermos also added a lot of useful low level functions (API) to start with it.
So you cannot make a mob and running it, you have to code a lot of things firstly.
My petz mod is a kit over mobkit, you can add your own mobs and run them without coding. But it requires mobkit as subjacent engine. So petz is not as flexible as mobkit, it is a high level API (It's not really an API either, is a mod coded as an API for efficiency reasons).
So mobkit is difficult to use, not easy. This is the reason I think is a cool concept to be added to the Minetest engine. But powerful at the same time, you can do all you want with it and not restricted to only one method of making mobs to production, see above.

An advantage of mobkit being an engine API and not a kit as mobs_redo is: SPEED. Another advantage: flexibility.

Disadvantage: Difficulty.

Translating to programming languages and to clarify concepts:
- Assembly = Minetest API.
- C = mobkit
- Visual Basic = mobs_redo, petz
Anyway, I accept this mod is still in WIP.
You are wrong again, mobkit is already "finished". The main core is already done: The concept of HQ & LQ funtions and the quee management thru priorities. Accesory things and addons could be polished or added, yeah.
Day 42 of the quarantine

User avatar
Wuzzy
Member
Posts: 3938
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy

Re: Mobkit - Entity API [mobkit][alpha]

by Wuzzy » Post

Like it or not, you might just be a godfather of this project, in a sense. Mobs in MCL2 were so goddamn horrible so it might have been the most important drop that spilled the bucket and made me decide mobs/entities were the most neglected aspect of MT.
I agree, the MCL2 mobs are horrible, it has been a long-standing problem. Note that MCL2 mobs are just Mobs Redo …
Mobs Redo is fine but its so-called “API” is horrible. A lot of the core mob behavior is hardcoded and not even documented well. That's my biggest issue with Mobs Redo. The lack of spatial awareness is also strong.

The upside of Mobs Redo is, in theory, that it's very data-driven. You just write down mob definitions and that's basically it. This is actually a good thing!
I disagree that Mobs Redo has no API. It is undoubtedly an API, just a very high level one, and not a very good one as well. But I do understand that you don't want to have a mod with tons of hardcoded behavior. I also did NOT want to say that mobkit must become the next Mobs Redo. Hell no! :D

Hmmm, I just had a thought. Would it be possible to re-implement Mobs Redo's core features with using mobkit only?

This sounds a lot like to make mobkit actually useful for production, I first have to build a “wrapper” around it, for e.g. mob templates, to make registrations of similar mobs simpler.
The fact that Petz is actually just doing just that, is kinda evidence for that.
It would certainly be very bad coding if I just write one brain for each possible mob, I would become crazy very fast! :D That's what I meant with “code duplication”.

If that's the case, I actually agree with the idea to move the concepts of this mod into the engine/builtin, because it is low-level. Or is it still too early to do that?

I'm a bit disappointed I did not get a reply to my complaint of no “register_mob” function existing. I really don't get it why such a function does not exist. Why am I forced to hardcode boilerplate for every mob?
Yes, the examples contain a fair amount of code, that's because they are examples and their function is to help understand how to code using this api, but if I were trying to make mobs that work like those from MCL2, the code would be closer to about five lines long.
Maybe the examples are just too large. They try to do many things at once, so they aren't really helpful in understanding the core concepts … I did only look at them briefly.

My complaint isn't really about difficulty, but about reusability of code. How does this mod make sure I am not forced to duplicate tons of code? Or do I have to work that out all by myself?

But yes, I have to admit, I did not really look at this mod too seriously right now.

Maybe mobkit will be the key with which I can finally move MCL2 mobs out of their misery. But it will be a lot of work. I basically have to start at zero again.

Maybe the best thing to do is to first make a mobkit-wrapper that gives Mobs Redo features out of the box? It would also help to convert legacy Mobs Redo mobs as well. Just an idea …

Please remember I only looked at the mod superficially, so forgive me my ignorance. Maybe I'll write more when I have looked deeper into this mod.
You are wrong again, mobkit is already "finished"
But why does this mod have “Alpha” in its name? ;-)

- Visual Basic = mobs_redo, petz
Bwahahaha, that was mean! :D
But it's not really true. These mods are not “visual”, i.e. there's no clicky-flashy GUI or anything. But if you look at the code quality of Mobs Redo, on the other hand …
I think PHP seems to be a more fitting comparison, at least for Mobs Redo. :P
My creations. I gladly accept bitcoins: 17fsUywHxeMHKG41UFfu34F1rAxZcrVoqH

User avatar
runs
Member
Posts: 1562
Joined: Sat Oct 27, 2018 08:32
GitHub: runsy

Re: Mobkit - Entity API [mobkit][alpha]

by runs » Post

Code: Select all

Would it be possible to re-implement Mobs Redo's core features with using mobkit only?.
Yes, I've reimplemented mobs_redo to fit mobkit in fact. I cut & copy some mobs_redo funtions and refactored (readapting) them indeed. For example, the drop feature or the eating grass one is a copycut. The 80% of the petz mobs properties are the same (i.e self.tamed). So not only it is possible, is real. But it was a hard work for me, mobs_redo is a complex project of lasting years.

But petz is not a wrapper. Nor a pure API. It is only intended to be a mod.

A wrapper? Someone could take the petz mod apis (api directory) as reference and do it. But it is not easy (I mean quick).

Code: Select all

 But if you look at the code quality of Mobs Redo, on the other hand …
No, the code is not as bad. I dove hard on it and I like it. Its fault is more an old fashioned concept to resolving the mob approach: a lineal structure of conditions to make the things.
Day 42 of the quarantine

Termos
Member
Posts: 310
Joined: Sun Dec 16, 2018 12:50

Re: Mobkit - Entity API [mobkit][alpha]

by Termos » Post

Wuzzy wrote:The upside of Mobs Redo is, in theory, that it's very data-driven. You just write down mob definitions and that's basically it. This is actually a good thing!
I totally agree, that's a perfectly good thing for whatever that mod is trying to be, which seems to be a quick mob mod for people who can't or don't want to code or just like it out of the box.
Mobkit is a different category entirely, it deliberately operates at a different level, these two things are not in competition and I think they get to be compared only because there's so little going on in the mobs department here.
Wuzzy wrote:Hmmm, I just had a thought. Would it be possible to re-implement Mobs Redo's core features with using mobkit only?
Definitely.
Well, mobkit and minetest api to be precise. MR is a fully fledged mod which references specific game features, definitions and other mods too, mobkit on the other hand, by design interfaces only with minetest api and never references any specific game stuff, not even the name "air", and never will, that kind of stuff belongs on the mod side.
Wuzzy wrote:It would certainly be very bad coding if I just write one brain for each possible mob, I would become crazy very fast! :D That's what I meant with “code duplication”.
I don't see why.
Ultimately every mob that is to behave differently ends up with it's own partially unique behavior code, there's only the question of structuring that code.
What would you prefer, a modular approach which lets you take care of each one individually in isolation, or rather have it all mixed in a bucket with the quail eggs on top?
Wuzzy wrote:I'm a bit disappointed I did not get a reply to my complaint of no “register_mob” function existing. I really don't get it why such a function does not exist.
It simply never occured to me why I should need one, minetest.register_entity is perfectly fine by me.
I don't know, maybe I do need one, feel free to try and convince me.

Termos
Member
Posts: 310
Joined: Sun Dec 16, 2018 12:50

Re: Mobkit - Entity API [mobkit][alpha]

by Termos » Post

Update 200222

mobkit
  • entity definition: added full support for initial_properties
    and documented [rubenwardy]
    • both styles of entity definition should work alike, old and new, no changes to existing mods required.
wildlife
  • better handling of environmental damage (i.e. lava) [FaceDeer]

User avatar
ElCeejo
Member
Posts: 66
Joined: Thu Feb 28, 2019 23:29
In-game: ElCeejo
Location: The darkest corner in your house

Re: Mobkit - Entity API [mobkit][alpha]

by ElCeejo » Post

Code: Select all

    local func = function(self)
        local pos = mobkit.get_stand_pos(self)
        local searchnodes = self.stay_near[1]
    
        if type(searchnodes) == "string" then
            searchnodes = {self.stay_near[1]}
        end
        
        local radius = self.view_range
        local nearby_nodes = minetest.find_nodes_in_area(
            {x = pos.x - radius, y = pos.y - 1, z = pos.z - radius},
            {x = pos.x + radius, y = pos.y + 1, z = pos.z + radius},
            searchnodes)
        
        if #nearby_nodes < 1 then
            return false
        end
        
        local target = nearby_nodes[math.random(1, #nearby_nodes)]
        
        local tpos = mobkit.get_node_pos(target)

        mobkit.lq_turn2pos(self,tpos)
        
        mobkit.animate(self,"walk")
        
        mobkit.go_forward_horizontal(self,speed)
        
        return true
    end
    mobkit.queue_high(self,func,prty)
So I've been trying to make a behavior that makes mobs go to a certain block, regardless of if it's water or not, this is what I have so far and it seems that when it tries to actually go to the block it goes forward slightly, stops, and repeats the process. Any recommendations?

Termos
Member
Posts: 310
Joined: Sun Dec 16, 2018 12:50

Re: Mobkit - Entity API [mobkit][alpha]

by Termos » Post

The most immediate problem is the behavior returns true unconditionally.
Returning true means it signals it's done and finished, so basically your behavior ends as soon as it began, and only runs for a single server step.
The proper way would be returning true on the condition the mob has reached its destination (check with is_there_yet2d() or isnear2d()).

Better yet, move it with a low level behavior, the high one would only be responsible for finding a new node to go to and kicking off an new low, on the condition the previous one has finished (lq empty).

Another thing, you probably don't need to do find_nodes_in_area on the whole view range, I bet you're interested only in nodes adjacent to the one the mob is on, so a specific value there would make more sense.

User avatar
ElCeejo
Member
Posts: 66
Joined: Thu Feb 28, 2019 23:29
In-game: ElCeejo
Location: The darkest corner in your house

Re: Mobkit - Entity API [mobkit][alpha]

by ElCeejo » Post

Thanks, that first one was an especially dumb oversight on my part. Now I'm getting crash with lq_dumbwalk that only occurs when the mob walks into water. It tells that there was an attempt to index a nil value in line 1000 of mobkits init.lua so I assume it has to do with liquidflag.

User avatar
Wuzzy
Member
Posts: 3938
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy

Re: Mobkit - Entity API [mobkit][alpha]

by Wuzzy » Post

So when will this mod be finished?
My creations. I gladly accept bitcoins: 17fsUywHxeMHKG41UFfu34F1rAxZcrVoqH

User avatar
Lone_Wolf
Member
Posts: 2328
Joined: Sun Apr 09, 2017 05:50
GitHub: LoneWolfHT
IRC: Lone_Wolf or LoneWolfHT
In-game: Lone_Wolf
Location: Not there, THERE!

Re: Mobkit - Entity API [mobkit][alpha]

by Lone_Wolf » Post

Wuzzy wrote:So when will this mod be finished?
You could use it now AFAIK. I've successfully used it to make mobs for my game

Termos
Member
Posts: 310
Joined: Sun Dec 16, 2018 12:50

Re: Mobkit - Entity API [mobkit][alpha]

by Termos » Post

ElCeejo wrote:Now I'm getting crash with lq_dumbwalk that only occurs when the mob walks into water. It tells that there was an attempt to index a nil value in line 1000 of mobkits init.lua so I assume it has to do with liquidflag.
Not sure, in the recent version there's nothing at 1000 that could cause that error under normal circumstances.

Yes. it's probably a good idea to use builtin example behaviors, get_next_waypoint() is what you'd modify to make them ignore water, If you really want to go with the allowed-nodes-list approach then is_neighbor_node_reachable() is the thing.
Just don't forget not to write to mobkit namespace if you're going to distribute.
Wuzzy wrote:So when will this mod be finished?
No later than Minetest is, I'm afraid.

The core is usable as is, however I'm trying to get a few engine PRs in to combat some issues that can't be solved LUA side, and then will do some modifications, so probably some time around MT 5.3
Example behaviors development on the other hand is an ongoing process.

Gundul
Member
Posts: 845
Joined: Thu Aug 27, 2015 10:55
GitHub: berengma
IRC: Gundul
Location: Europe/Asia

Re: Mobkit - Entity API [mobkit][alpha]

by Gundul » Post

ElCeejo wrote:Thanks, that first one was an especially dumb oversight on my part. Now I'm getting crash with lq_dumbwalk that only occurs when the mob walks into water. It tells that there was an attempt to index a nil value in line 1000 of mobkits init.lua so I assume it has to do with liquidflag.
Just a spontan idea:

let the brain check for liquidflag and use a hq function with lq_dumbwalk if not in water, return true as soon as you enter water and then use an other hq function with different lq func for underwater. You can even do this inside one hq behavior if you like with the two different lq functions..

Maybe this can help you a bit:

Code: Select all

#################################################
water_life.hq_swimto(self,prty,speed,node,tgtpos)
#################################################

mob will swim to given node which must be in its view_range
node can be a string or a table of string
OR
if tgtpos is set it will swim there, node will be ignored then
returns if distance <= 1 node

My servers: Jungle, Lilly in the valley, ZombieTest

User avatar
runs
Member
Posts: 1562
Joined: Sat Oct 27, 2018 08:32
GitHub: runsy

Re: Mobkit - Entity API [mobkit][alpha]

by runs » Post

...
Day 42 of the quarantine

User avatar
Clyde
Member
Posts: 148
Joined: Sat Jul 30, 2016 14:23
GitHub: acmgit
In-game: clyde

Re: Mobkit - Entity API [mobkit][alpha]

by Clyde » Post

Hello,

i'm not sure, that this is the right thread, but nevermind, i post it at both:
2020-02-29 13:00:51: ERROR[Main]: ServerError: AsyncErr: ServerThread::run Lua: Runtime error from mod 'petz' in callback luaentity_Step(): ...re/minetest/games/Smalltech/mods/mp_mobs/mobkit/init.lua:298: attempt to perform arithmetic on local 'yaw' (a nil value)
2020-02-29 13:00:51: ERROR[Main]: stack traceback:
2020-02-29 13:00:51: ERROR[Main]: ...re/minetest/games/Smalltech/mods/mp_mobs/mobkit/init.lua:298: in function 'turn2yaw'
2020-02-29 13:00:51: ERROR[Main]: ...re/minetest/games/Smalltech/mods/mp_mobs/mobkit/init.lua:623: in function 'drive_to_pos'
2020-02-29 13:00:51: ERROR[Main]: ...st/games/Smalltech/mods/mp_mobs/petz/misc/behaviours.lua:822: in function 'func'
2020-02-29 13:00:51: ERROR[Main]: ...re/minetest/games/Smalltech/mods/mp_mobs/mobkit/init.lua:737: in function 'execute_queues'
2020-02-29 13:00:51: ERROR[Main]: ...re/minetest/games/Smalltech/mods/mp_mobs/mobkit/init.lua:955: in function 'stepfunc'
2020-02-29 13:00:51: ERROR[Main]: ...st/games/Smalltech/mods/mp_mobs/petz/petz/bee_mobkit.lua:107: in function <...st/games/Smalltech/mods/mp_mobs/petz/petz/bee_mobkit.lua:106>
Greetings, Clyde

User avatar
runs
Member
Posts: 1562
Joined: Sat Oct 27, 2018 08:32
GitHub: runsy

Re: Mobkit - Entity API [mobkit][alpha]

by runs » Post

Clyde wrote:Hello,

i'm not sure, that this is the right thread, but nevermind, i post it at both:
2020-02-29 13:00:51: ERROR[Main]: ServerError: AsyncErr: ServerThread::run Lua: Runtime error from mod 'petz' in callback luaentity_Step(): ...re/minetest/games/Smalltech/mods/mp_mobs/mobkit/init.lua:298: attempt to perform arithmetic on local 'yaw' (a nil value)
2020-02-29 13:00:51: ERROR[Main]: stack traceback:
2020-02-29 13:00:51: ERROR[Main]: ...re/minetest/games/Smalltech/mods/mp_mobs/mobkit/init.lua:298: in function 'turn2yaw'
2020-02-29 13:00:51: ERROR[Main]: ...re/minetest/games/Smalltech/mods/mp_mobs/mobkit/init.lua:623: in function 'drive_to_pos'
2020-02-29 13:00:51: ERROR[Main]: ...st/games/Smalltech/mods/mp_mobs/petz/misc/behaviours.lua:822: in function 'func'
2020-02-29 13:00:51: ERROR[Main]: ...re/minetest/games/Smalltech/mods/mp_mobs/mobkit/init.lua:737: in function 'execute_queues'
2020-02-29 13:00:51: ERROR[Main]: ...re/minetest/games/Smalltech/mods/mp_mobs/mobkit/init.lua:955: in function 'stepfunc'
2020-02-29 13:00:51: ERROR[Main]: ...st/games/Smalltech/mods/mp_mobs/petz/petz/bee_mobkit.lua:107: in function <...st/games/Smalltech/mods/mp_mobs/petz/petz/bee_mobkit.lua:106>
Greetings, Clyde
I have a 'drive_to_pos' function in a LQ function.
if mobkit.drive_to_pos(self, tpos, 1.5, 6.28, 0.5) then
...
end
Then 'mobkit.drive_to_pos' calls 'mobkit.turn2yaw'

And the error occurs when:

Code: Select all

function mobkit.turn2yaw(self,tyaw,rate)
	tyaw = tyaw or 0 --temp
	rate = rate or 6
		local yaw = self.object:get_yaw()
		yaw = yaw+pi
The 'get_yaw' returns 'nil'. I guess the mob dies when is turning.

How can avoid this, Termos?
Day 42 of the quarantine

Termos
Member
Posts: 310
Joined: Sun Dec 16, 2018 12:50

Re: Mobkit - Entity API [mobkit][alpha]

by Termos » Post

Shouldn't happen if you call it correctly, behaviors are called from within on_step, an that in turn is called only on active objects.

Maybe you're trying to call turn2yaw on behalf of a saved entity? In that case mobkit.is_alive should be called first thing to check if it's still around.

User avatar
runs
Member
Posts: 1562
Joined: Sat Oct 27, 2018 08:32
GitHub: runsy

Re: Mobkit - Entity API [mobkit][alpha]

by runs » Post

Termos wrote:Shouldn't happen if you call it correctly, behaviors are called from within on_step, an that in turn is called only on active objects.

Maybe you're trying to call turn2yaw on behalf of a saved entity? In that case mobkit.is_alive should be called first thing to check if it's still around.
I do not think so cos get_pos() is checked in the LQ function and it works OK.

I suspect a water_life conflict, cos it has a yaw global variable that could conflict with the mobkits "yaw = yaw + pi" line that causes the crash. But i am not sure at all cos lua globals and even locals have some mistery for me.
Day 42 of the quarantine

User avatar
runs
Member
Posts: 1562
Joined: Sat Oct 27, 2018 08:32
GitHub: runsy

Re: Mobkit - Entity API [mobkit][alpha]

by runs » Post

I've check the lua manual and it has sense: http://www.lua.org/manual/5.2/manual.html#3.5

If yaw is global and has a nil value, doing "yaw = yaw + pi" produces nil + pi. So it should be better make "local yaw = ...get_yaw() + pi" than "local yaw = ...get_yaw(); yaw = yaw + pi"
Day 42 of the quarantine

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests