Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Valderman

Game <--> Script interaction

This topic is 5576 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How would you go about integrating a VM style scripting system with the rest of your game? My VM currently does this by allowing functions in a DLL to be called directly from scripts, this does however introduce a problem: the script language can crash the game itself. If the wrong number of arguments is pushed, the engine will break down Chernobyl-style. What method would you suggest for this interaction? I have only written an assembler for the VM yet, and was thinking that if I require a function header for DLL functions to be called in the high-level compiler which I will create later on, that would make it a lost safer, but it still isn''t perfect. Are there any other good ways to do this interaction which I am missing, or can you suggest any other ways to make my current method safer? As for Game --> Script interaction, I was thinking of having the game engine pass a fixed number of parameters when calling scripts, like pScript->Run(NPC_TALK, iTheIdOfTheNpc, iStringTableLineIndex), and the script calls the appropriate function within itself to handle the NPC_TALK event. Do you have anythhing to say about this, or does seem to be a good way to go?
For crying out loud, she has fishes coming out of her head on either side. How can you find this hot?!

Share this post


Link to post
Share on other sites
Advertisement
I don''t have much experience with VM scripting systems but you could probably avoid the crashes by precompiling the scripts. This can be done explictly from a seperate compiler program or by the game itself when the script is loaded. In either case, you would generate the appropriate errors and force the correction of those mistakes. Hope this helps...

insert witty signature here

Share this post


Link to post
Share on other sites
I''ll probably have a mechanism like that when I create that high-level compiler. Right now, function calling is handled quite horribly:
spush param3
spush param2
spush param1
spush num_params
extcall function
...which is not very user-friendly. I''ll have to get around to creating that compiler...


For crying out loud, she has fishes coming out of her head on either side. How can you find this hot?!

Share this post


Link to post
Share on other sites
I''ve just put in the scripting engine into my game (It took a whole half a day to get it working..). I use the inbuilt windows Visual Basic Scripting which seems very fast.. I didn''t notice any effect on the game speed (but then again I am only executing functions in the script based on events)

Ofcourse, for VBS to access your program (or objects within your program..) each object has to be a COM.. if you are already using c++ and OO game objects then it''s not much more overhead.

If any script errors occur, I just bring up a warning dialog and continue on..

if you are calling a method in the script then you always know what the API is going (or has to be) and pass the correct number of arguments..

hope that helps

Jumpman - Under Construction

Share this post


Link to post
Share on other sites
Well, I could use VBS scripting, but where would the fun in that be? By creating my own VM instead of using a pre-built one, not only will I feel more satisfied when it''s done, but I will also have learned a lot of things on the way there.


For crying out loud, she has fishes coming out of her head on either side. How can you find this hot?!

Share this post


Link to post
Share on other sites
I have implemented a system very similar to yours about a month ago Valderman.

For the compiler I allow a script to include the a file of prototypes for native functions. It doesn''t stop the prototypes from being wrong, but if they are right it will allow you to catch errors at script compile time.

Then once the script is loaded, or befor I can''t remember, the embedding code passes (function pointer,name) pairs to the vm which links to the script, the function pointers all have the same prototype which takes a vm stack and numArgs parameter. This way they can at least check that the right number of arguments is passed.


For calling functions from the script I have a call function member of the vm which has a variable argument list, the arguments are extracted from the argument list and pushed onto the vm stack for use by the script function.

This is prone to mucho majour crashes if some of the names or arguments are missmatched, but it is about as far as I want to go.

Share this post


Link to post
Share on other sites
The probability of a type mismatch when calling a function isn''t very big for my VM, since all vars are DWORDs. Basically everything can be done using DWORDs, and almost all Windows functions take DWORDs as parameters (be it numbers, pointers, handles, etc.).


For crying out loud, she has fishes coming out of her head on either side. How can you find this hot?!

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!