AI scripting

Started by
15 comments, last by ColdfireV 24 years ago
I wanted to post this here, because not many people read the AI board often. Anyway... How is it possible to write an AI scripting language in C++? I''ve been thinking about it for awhile, but no good ideas have come up. Of course, I could do a function that have a million different IF-THEN''s or CASE''s or whatever conditionals there are, but that''s just not good enough. I''m talking about a scripting language that''s truly robust, non-compiled, and fast enough to be run in a game. Here''s an example of the script itself: OBJECT Light //declaration IF (DISTANCE(Player) < 100) TURNON() END IF END OBJECT Yeah, that''s just pretty basic... But let''s say that for every object created in the game, you can have the flexibility to do anything that''s possibly done by the object. Obviously, there would be some hard-coding of the C++ code to do the action, but it must able to be called by the script. How can I possibly start working on something like that? Any ideas would be great. ColdfireV
[email=jperegrine@customcall.com]ColdfireV[/email]
Advertisement
i guess you could make a file parser and compile the script runtime and have like a separate thread manage the AI script.. that''s rather daunting.

You could also set up a sorta half script where there a some predefined modes of AI motion, but the script defines how and when to switch into the different motions.

I''m out of ideas and looking for more too.
___________________________Freeware development:ruinedsoft.com
You could use a scripting language to do this. Lua interfaces with c/c++ quite easily and is reasonably fast (I haven''t done testing but it works well for my AI scripting needs)
I wrote an AI scripter that took logical statements like the one you described and parsed them into logical operator trees attached to functions. It was all done at load time but could be parsed on the fly.

Bascially you''d need all your functions to have tags that were defined in the scripting language and could be translated into function pointers (mine were all void* (function) (void*)) for use in the game. It was based around controlling npc actions more than object but it could be used for both with little change. You''re welcome to the code which is fairly well written and well commented.

I even put in an ability to define your own statements so you could make the script langage as English as you want.

Mike
I have written a scripting language just for things like this. It is EXTREMELY flexible (you can add any command you can think of, within reason). I wrote it for use in my MUD, but I am now adapting it to run qbasic/truebasic style programs (aka interpreted, but not part of a bigger project). You should be able to download it off my website in a few days... I haven''t put it up yet. Send me an email and I will let you know when my website is totally up.

--------------------


You are not a real programmer until you end all your sentences with semicolons;

Yanroy@usa.com

--------------------

You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are unique. Just like everybody else.
"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor

Yanroy@usa.com

I personally am a fan of function pointers and DLLs for scripting. You basically have triggers and the triggers would call function pointers that are bound to the object/character/or map section. Besides, no compiled script is going to be as fast as native computer language
- I kode kuz I kan!
Don''t re-invent the wheel! Use Lua!

"Paranoia is the belief in a hidden order behind the visible." - Anonymous
MikeD, I''d like to take a look at your script engine. I''d just like to see how it''s done. How would you "parse them into logical operator trees attached to functions"? I''m probably not C++ advanced enough to figure that out (I really am advanced at C++, but I just can''t think of how that would be done. A good look at your code would probably help.)

An idea I had was to do a Java-like compile. In the start of the program, all the AI would be compiled into byte-code, and the byte-code could be interpreted. I have absolutely no idea whatsoever how that would be done, but it would be a really good idea I believe.

Lastly, what is Lua? It sounds like it''s somewhat useful, but how is it incorporated with C++, what''s the language like, etc? I might want to look into that, but insight on that would be appreciated. Thanks guys...



ColdfireV
[email=jperegrine@customcall.com]ColdfireV[/email]
You should have a look at the scripting engine tutorial on flipcode (http://www.flipcode.com/tutorials/tut_scr01.shtml) by Jan Niestadt. It''s a quite good introduction in scripting languages.
Staffan:
Someone wise once said: "If nobody ever reinvented the wheel, all our cars would roll on logs."

Just a thought. Reinventing a better wheel is a great idea.

This topic is closed to new replies.

Advertisement