Advertisement

Messages between the scripts and the core?

Started by January 26, 2004 02:14 PM
2 comments, last by Miksu_ 20 years, 10 months ago
I''ve been trying to figure out the basic concept of a scripting system. I''ve tried to read all the related stuff from the GameDev, but haven''t found the solution to this question. Hopefully you can help. Let''s say we have a game which has a class called CORE. I also have a class called ScriptSystem and a class called Script. If something happens in the main application(CORE), it can ask ScriptSystem to run the proper Script. My problem is the way how the Script-object deals with the CORE-class. The best solution I''ve come out this far is that I also have a class called ScriptToEngine, which works as an interface between the scripts and the main parts of the program. For example, the script can call "ScriptToEngine.CoreCreateObject(monster)" and then the ScriptToEngine-object passes the information to CORE-object. I think that''s kinda good solution but, in the long run, is it going to be too much work to update the interface-class everytime I need to add a new scripting-option to the program? Other option is that the Script-object somehow ''knows'' about the CORE-class and can pass messages to it directly. But what if I also have classes SOUND, AI etc? My main problem with this is that I''m not sure how I can tell to Script-object that "there are these objects called CORE, SOUND and AI and you can work with them directly". And also I think that it may give the scripts too much ''power'' if they can communicate with the other classes directly and not via some interface. What are your advices on this? Personally I prefer the interface-technic but I really hope that both of my options are wrong and you can tell me the right way to handle the messages from scripts to core-parts of the program.
I''m not sure what the problem is. You''re in control of all these classes so you can choose to do it whichever way is easiest for you. In my home-made scripting system I simply have a list of functions available to the scripts, and each of those functions has direct access to the core game data. So in summary, Script objects know about the Functions and the Functions can modify or query the game data. That''s as much abstraction as I need.

[ MSVC Fixes | STL Docs | SDL | Game AI | Sockets | C++ Faq Lite | Boost
Asking Questions | Organising code files | My stuff | Tiny XML | STLPort]
Advertisement
quote: Original post by Miksu_
Let''s say we have a game which has a class called CORE. I also have a class called ScriptSystem and a class called Script.
You have too many classes. Your problem is OO-itis. Objects are meant to encapsulate a known process or decompose an oversize one; yours are doing neither.

A script is a series of executable statements. Sound familiar? That''s right, it''s just like a function! And you can pass it the data it needs to operate on as arguments - implicitly or explicitly. Implicit passing would be a script dispatch method that supplies "hidden" parameters - like this (self in Python) on methods in most OO-capable languages - while explicit passing would require that the user actually supply those values himself.

I would recommend reading how existing languages do it. Python is very well documented, with a robust description of its global and local dictionaries in the Language Reference. Lua is also well documented (though not as well), and has an excellent C interface mechanism.
What you may need is something like the ''native'' keyword in UnrealScript. There area heaps of way to do this, it depends on the specs of your script language. If you are using a pre-existing language (eg. Python), this functionality is probably implemented.

If you roll your own language, you''ll have to work this out. Can''t help that much here, my main experience of scripting language integration is with Java, where reflection helps a lot to resolve method calls.

This topic is closed to new replies.

Advertisement