Menu

Advanced Programming Question: Scripting?

2003-01-17
2012-09-26
  • Nobody/Anonymous

    I am trying to make a game engine. Nothing, big like 3D or anything so please dont leave yet, in fact, it will be console. I am wondering how you can make a simple script engine, like PERL or those ray trace programs where you can see the code as it runs through it, and even change the code on the fly. I just need a pointer, and every search I can think of comes up with stupid or useless. I really need a few pointers.

    I am not new to programming, but the source code for PERL is overwhelming to say the least. The only source code to the ray trace programs I have use some external toolkit I do not know.  I have tried several searches on goggle and here is some of my results if any of you can think of a better query please let me know.

    Script Engine  Source Code - This search led to some interesting examples, and one with more pointers than I would want to track down.

    When that turned up with a great deal of examples that just wasnt working for me I tried to restrict it for c only.

    Script Engine Source Code C Programming - Nothing. Lots of good information I am sure, but none of it helped me very much as most links pointed to .

    Actually, that search did lead me to actually search for something a little different.

    Simple Interpreter Source Code - This led me a few examples on how to do exactly what I wanted. It was a basic interpreter, literally, it was an interpreter for the basic language.

    It was pure gold for my searches, but now, and here comes my questions if anyone is still reading, how can I improve on the design. If anyone can help with pointers on how to do these things or even provide me with a better search string please let me know.

    Basically, I am looking for any code examples on how to:
    - Create a variable number of script variables.
    ----- The best example I found had a set limit of 20.
    ----- Obviously, I could expand this, but waste space if only 5 are used.
    - Take certain data in and keep it stored for faster reference.
    ----- Actually, I may not need code help here; I need advice.
    ----- I can read and write files, so would it be better to read in
    ----- the file line by line, and store everything I may need fast
    ----- access and then just parse the file over for each rooms
    ----- description? Please, give me advice here.
    - Create a thread, and/or other complex things from the script.
    ----- What? Yea. I did say this is a console, but I read some
    ----- tutorials about using a text buffer. I am going to try and
    ----- have a ASCII sprite. From what I have seen the win32 API
    ----- is extremely hard, and I thought I could learn how to do
    ----- this kind of thing and develop it as I move into windows.
    ----- Also, the example I got is great and it did a great job of
    ----- showing how to emulate a external variable, but how on
    ----- earth is it even possible to do a loop command, like for?
    - How can I do faster parsing?
    ----- I am using a great many, no doubt poor, for loops with
    ----- a great many more if commands, to do my parsing.
    ----- Someone, please, tell me of an easier way. Is there a
    ----- library or something to provide fast parsing, like looking
    ----- for a certain string, saving to a variable, writing, and rewriting.

    Thanks for taking the time to read this, and for any help you may give me.

    Tom Hawkins

     
    • Nobody/Anonymous

      A good source for this type of stuff is
      www.gamedev.net

      Here is an url that may help you somewhat.  A tutorial of how to write a script engine in C++.

      http://www.gamedev.net/reference/programming/features/cppscript1/page3.asp

      There are many other tutorial about scripting on that site.

      Cheers,
      Willem

       
    • Nobody/Anonymous

      script variables, I'm not sure exactly what you want here...but I think you mean a script defined variable that is created/managed/deleted in C/C++ code. You can use an array of strings to store the names and build a hash table to index the actual variable in memory...This way the script variable can be dynamic and it's name will be used to look up the reference to the actual value, or more likely a structure which defines it's behaviour a complex excercise better to integrate an intepretor which manages this for you...

      For Scripting I would opt for compiling your own Tcl intepretor  ( or possibly Perl or other language ). All the constructs for looping, setting variables,defining special keywords etc are defined cleanly, at least in Tcl and you basically end up with your own personal shell with the extra commands for doing whatever ( 3d, gaming, testing ). You could do this with Cygwin on Windows but I have only ever implemented shell's on UNIX it's good fun..you can even create objects that auto-instantiate ( a little bit of TCL C code..documented in detail ).

       
    • Nobody/Anonymous

      Check out VPython at

      www.vpython.org

      Wayne

       
    • Nobody/Anonymous

      Thanks to all of you. Your pointers have been a big help, and I looked at all of them.

      I looked at gamedev. I didn't know it existed. I think it will be a big help.

      I have already looked at PERL source and it is to complicated. The source for the Tcl Interpreter looks wat to complicated as well.

      I looked at the source for PYTHON Interpreter as well, and it to looks very complicated.

      Again, thanks to you all, maybe I will get better as I go and will be able to understand the source, for the Interpreters you suggested, better, and make one myself.

      Tom Hawkins

       
    • Nobody/Anonymous

      Python, complicated.....bah!!!!!

      The only thing...different about Python is that it denotes its cluster of statements with indentiong, not with braces, or begin/end, or that sort of thing.  Thing I like BEST (besides VPythons easy and neat 3D graphics) is that it will NOT let you do the following:

      if (x=3)

      If I had a nickel for every time I have done that crap in C++.....

      I have used Perl a pretty good amount in my career, as a language, it is very similar to C, though when you get into regular expression work, it can look a lot like line noise.

      I have not used Tcl, but most folks I know who have will say it is...unusual.

      Seriously though, if you were to go the Python route, get the VPython package.  Even if you never use the graphics, the IDE is a step up from the base IDLE that comes with Python...

      Wayne

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.