python with bge

Does regular expressions in python work with the blender game engine?

I don’t see why they wouldn’t, although that depends on how you want to use them.

I would like python in the blender game engine to identify keywords in a sentence and have a videogame character do something.

Have you tried it?

In future, better to attempt this yourself and report your findings.
To answer your question, most python libraries are included with Blender

No I have not.I was just wondering if it was compatible.

Can I make a game in BGE? yes
Can I program in BGE? yes
Can I get input from a webcam in BGE? yes
Can I load objects dynamically in BGE? yes
Can I deal with multi-dimensional arrays in BGE? Sure
Can I program the most sophisticated AI ever in BGE? I don’t see why not
Does BGE support regular expressions? Yup
Does BGE support animated textures? Yes
Does BGE have feature A? Possibly
Can BGE do B? Probably
Can I eat things I make in blender? Nope.

Oh, sure you can:), now whether or not you’ll live through it, I don’t know.

I think the point being made is that the Python inside Blender is just Python. All the standard Python libraries are available and you can add any Python module to the system that you want.

For example, if you want to you can add ‘httplib2’ to your system and you can download data from web servers and display in your game (maybe you have a server that tracks the high scores). You can install MySQL and the Python DB driver and have access to a database in Blender. You can do arbitrary file access with Blender.

The point is, Blender has not put any restriction on Python. Python is still a general purpose programming language.

Can it be done easier than using it?

If you need regular expressions or not really depend on how complicated your sentences are. Do you have an example of what you will be trying to parse?

My general impression is that usually systems like this are so simple that you can just pick out words. For example, you always take the 3rd word out the input and scan it against a list of known action words. Or they are so complicated that you have to have a basic parser to process the grammar of your command language. In both cases, regular expressions don’t really help you very much.

I have done this myself. Regular python functions, expressions, methods, what have you, all work with BGE. As was said above, it’s all python.

I made a prototype of the “NPCs that reply to player-entered chat and keywords” thing from Everquest, with favorable results. It’s totally possible.

I would like to ask a question how I would like to and answer them how I want to in the blender game engine.And have the character understand me know matter what.They are many different ways to ask a question and many different ways to answer a question.I just don’t want to have type it in exactly.Because that would be so unnatural.

Be aware, AI which understand you require a much greater level of complexity than others. To be honest, it’s almost impossible (given that essentially one would have to pass the turing test), and most big name games struggle with it.

You should take a look at natural language processing as a topic, should lead you the right places.

So they are no good tutorial for doing what I am asking?So you think identifying keywords and types of punctuation would not make that happen?

Yeah, that’s bordering on science fiction here, haha. You should look into the way Everquest does it, as well as a smaller MMO (that might be dead by now) called PlaneShift. They do this, too.

If making a sensible AI that responded in a human-like way was as simple as picking out keywords and punctuation, our interaction with our computers today would be vastly different.

But when you realize that there are a thousand ways to say “The man walked from his house into his fields” and that a phrase containing “man” “house” and “field” can mean a thousand different things, then you may discover how complex it actually is.

I’d suggest going with a choice of several preset sentences and responses. It is simpler to code, and will probably seem more familiar to gamers anyway.

The games I know of just fake the “understanding” part. Ultima online used to work like that for npc interaction. Basically the game splits the sentence of the player into words and looks for basic combinations of one or two words. Like “buy” and “weapon” pops out the weapons’ inventory. The player writes “I’d like to buy a weapon from your fine inventory”, the ai sees the words he knows about and reacts accordingly.
I don’t now if we are even close to having software that actually understand things. They can’t even translate yet.

Okay, make up three?Could more than one of you make submission?This is very interesting i never new you could.

A thousand ways to say “The man walked from his house into his fields”

The man strolled from his residence to his meadows (Word Substitution, 548 different options detected on initial sweep)
A man walked to his fields from his house (Word order, combined with above brings total to 7690 combinations)
The farmer exited his building (Implied meaning, ??? different options)

More examples:
Into his fields the farmer strolled, leaving his house behind.
As he left his home, he noticed the acres of hay surrounding him.

Show some creativity, there are thousands and thousands of options.

A phrase containing “man” “house” and “field” can mean a thousand different things

A man’s house caught fire, which then spread to his fields (Change subject)
A field surrounded the mans house (No implied action)
If you decide to enter a field, first check that the house is not in view, as the man who owns the property may see you and chase you away (Change meaning)
Houses jump, fields flee, I am not a man. (Nonsense, no meaning)

And there are countless others.

Honestly, parsing and creating sentences in such a way to give a sense of true intelligence is something that is too CPU-intensive to be done on consumer hardware in real-time.

There are millions of possible combinations and answers and it requires a supercomputer like IBM’s Watson to do it at the speed required for games. You will need to use a dumb system that picks out keywords and gives a rough answer to give the illusion of intelligence, now it will make the AI character more like a dog (which responds according to sounds he is trained to know) than a person, but we have to look at hardware limits here and the fact that even rudimentary AI can require a lot of code and a bit of skill.