Thread: workin' on a scripting engine....

  1. #16
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    If you're using C++, just use a map.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  2. #17
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    a what? never heard of maps before in C++....

    anyways, i've got v1.00b finished now, i made a cool little demo that goes with it, please download it and tell me what you think i'm looking for feedback...........

  3. #18
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Yeah, it's really cool to create your own programming language.
    Actually I was thinking of implementing a similar library for Omicron.

    I tested your compiler and code and it seemed to work fine.

    One thing that is useful is named variables, only numbers can be a little too esoteric, especially since you're targeting newbies.

    5) Any command without parameters must NOT have any parenthesis....that should make logical sense, lol
    Hmm, actually ( and ) are quite useful in long expressions.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  4. #19
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Originally posted by jverkoey
    a what? never heard of maps before in C++....
    Code:
    #include <map>
    #include <iostream>
    #include <string>
    int main()
    {
      using namespace std;
      
      map<string,int> myMap;
    
      myMap["one"] = 1;
      myMap["two"] = 2;
      ...
      myMap["zero"] = 0;
    
      cout << "Type in a number (as text) ";
      string s;
      cin >> s;
    
      cout << "You typed in " << myMap[s];
    }
    A map<string,double> is perfect to store variables. I'm using that technique in Omicron.
    Last edited by Sang-drax; 03-15-2003 at 06:04 AM.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  5. #20
    Cool stuff! I like the help file. This could turn into something pretty cool.

    Are you going to add anything in where you can make loops? A while and for loop should be enough, but a do...while loop wouldn't be bad either.

  6. #21
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    Originally posted by Sang-drax
    Code:
    #include <map>
    #include <iostream>
    #include <string>
    int main()
    {
      using namespace std;
      
      map<string,int> myMap;
    
      myMap["one"] = 1;
      myMap["two"] = 2;
      ...
      myMap["zero"] = 0;
    
      cout << "Type in a number (as text) ";
      string s;
      cin >> s;
    
      cout << "You typed in " << myMap[s];
    }
    A map<string,double> is perfect to store variables. I'm using that technique in Omicron.
    ok..........hmmmmm...........thinking...........

    ok

    i think i have an idea


    how's about, with the maps, if i do something like this:

    i'll have mutliple maps, one for each type of variable (character arrays, float, and ints), so it'll probably be something like this:

    map<char[40] [NUMVARS],int> integers;
    map<char[40] [NUMVARS],float> floats;
    map<char[40] [NUMVARS],char[1024]> chars;

    -edit-
    and 40 could possibly not the most amount of variables you could have, I could (theoretically) just resize it every time they got more than that..........
    -end of edit-

    oook, and that theoretically works (i'll need feedback on this, cuz i just found out about maps )

    and then, once I have those declared, if I want to create a variable, I would do something like so:

    @char <name>
    @int <name>
    @float <name>

    where name would be the name of the variable

    and then the engine would read that in from the file and see that it starts with an @ sign, and go in to variable declaration mode. It would then assign the name given to it to <mapname>[<charname]

    ex: you declared a @char name; , the engine would read that in, and assign "name" to the first available slot on the map. then, if you wanted to assign something to the variable, you'd just do: @<name>=<value>; and that would assign <value> to the corresponding <name> spot on the map.......this is assuming that what I assumed is correct, lol

    so, any input? i have NO idea as to whether or not this'll work....and it'll probably take me a while to implement (it took me about 2 hours just to implement the @<number> system, but I have to admit, that one IS kinda static....)
    Last edited by jverkoey; 03-15-2003 at 01:08 PM.

  7. #22
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    Originally posted by Sang-drax
    Hmm, actually ( and ) are quite useful in long expressions. [/B]
    wha? what I meant by that was that if you have a command that doesn't take any parameters, like Reset;, then you shouldn't PUT any parameters in it, so Reset("hey"); would return an error and the program would quit..........see what I mean?

  8. #23
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    err, and with the maps, I must be either A) missing something, or B) Visual Studio doesn't like maps.........because they aren't compiling (even though I included all the header files...)

    I'm assuming there's probably a library i need, but I dont' know which one.......

    -edit-

    added the namespace thing (which i don't like using that much) to the file, and all of a sudden, 68 errors popped up, that's why i don't use it I'm assuming that you HAVE to use the namespace thing, but if I won't be able to program anything else because of it, i'm just gonna screw the map things...........
    Last edited by jverkoey; 03-15-2003 at 12:46 PM.

  9. #24
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Originally posted by jverkoey
    err, and with the maps, I must be either A) missing something, or B) Visual Studio doesn't like maps.........because they aren't compiling (even though I included all the header files...)

    I'm assuming there's probably a library i need, but I dont' know which one.......
    Probably A), because Visual Studio likes maps. No library is needed, maps are part of C++.

    Originally posted by jverkoey

    added the namespace thing (which i don't like using that much) to the file, and all of a sudden, 68 errors popped up, that's why i don't use it I'm assuming that you HAVE to use the namespace thing, but if I won't be able to program anything else because of it, i'm just gonna screw the map things...........
    Remember to use correct headers, like <iostream> instead of <iostream.h>. Can you compile my example?
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  10. #25
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    well, thing is, i'm not using Dos console stuff, i'm using an API, so I don't even have the iostream.h header file, these are all the header files I have for my scripting engine:

    #include <fstream.h>
    #include <string.h>
    #include <windows.h>
    #include <ctype.h>
    #include "map.h"

    and map.h is a header i just created myself cuz i'm frustrated with the maps GRR

    this is the map.h header file:

    Code:
    #define BOOLEAN		1
    #define CHARACTER	2
    #define FLOAT		3
    #define INTEGER		4
    
    class map
    {
    private:
    	char name[100];
    	int type;
    	bool bvalue;
    	char cvalue[1024];
    	float fvalue;
    	int ivalue;
    	bool used;
    public:
    	map();
    	void create(char* Name,int Type);
    	bool createB(bool value);
    	bool createC(char* value);
    	bool createF(float value);
    	bool createI(int value);
    };
    
    map::map()
    {
    	used=false;
    }
    
    void map::create(char* Name, int Type)
    {
    	strcpy(name,Name);
    	type=Type;
    	used=true;
    }
    
    bool map::createB(bool value)
    {
    	if(type==BOOLEAN)
    	{
    		bvalue=value;
    		return true;
    	}
    	return false;
    }
    
    bool map::createC(char* value)
    {
    	if(type==CHARACTER)
    	{
    		strcpy(cvalue,value);
    		return true;
    	}
    	return false;
    }
    
    bool map::createF(float value)
    {
    	if(type==FLOAT)
    	{
    		fvalue=value;
    		return true;
    	}
    	return false;
    }
    
    bool map::createI(int value)
    {
    	if(type==INTEGER)
    	{
    		ivalue=value;
    		return true;
    	}
    	return false;
    }
    that all theoretically works, right now i'm putting it in to the engine.......

    -edit-

    ok, i've put it in the engine, and now I can create variables....just working on all the debugging for that, then i'm going to make it so you can use the variables
    Last edited by jverkoey; 03-15-2003 at 02:27 PM.

  11. #26
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Originally posted by jverkoey
    well, thing is, i'm not using Dos console stuff, i'm using an API, so I don't even have the iostream.h header file, these are all the header files I have for my scripting engine:

    #include <fstream.h>
    #include <string.h>
    #include <windows.h>
    #include <ctype.h>
    #include "map.h"
    That should read (or else the map header might not work):
    Code:
    #include <fstream>
    #include <cstring>
    #include <windows.h>
    #include <ctype.h>
    using namespace std;
    #include "map.h"
    If you want different data types, I suggest creating a "datatype" class:

    Code:
    class DataType
    { 
        enum Type {Int,String,Float};
        
        int intValue;
        string stringValue;
        float floatValue;
        ...
    
    public:
        DataType(string s);
        DataType(int i);
        ...
    
        string GetString();
        ...
    };
    
    //This map holds all your variables
    std::map<string,DataType> variables;
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  12. #27
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    baaha, yes, i forgot about overloading functions, that'll make my map.h header file easier to work with. All i'll need now is just an assign and create function, and just overload 'em with each of the variable types....

    but yah, right now i've got it so you can declare your own variables, and you can create an unlimited amount (until memory runs out ) and i'm halfway through making it so you can add/subtract/multiply, yadda each of the variables. I'm only going to have 4 types of variables, because I don't see the need in having any more than that.....float int char bool and that should be all anyone'll ever need.

    hoping to get all of the variable stuff done tonight, then tomorrow I'll add a bunch more commands to the language....and maybe even think of adding "header files" so that people can define their own commands....

  13. #28
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905

    yaaah, my 100th post!!

    whooohoo, my 100th post!

    *sniff* i knew, *sniff* this day would come, *sniff* i am now *sniff* a senior!!

  14. #29
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718

    Re: yaaah, my 100th post!!

    Originally posted by jverkoey
    whooohoo, my 100th post!

    *sniff* i knew, *sniff* this day would come, *sniff* i am now *sniff* a senior!!
    What a waste of a post. :P
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  15. #30
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    well, hey, i was sitting there, staring at the fact that i had 99 posts...I didn't have anywhere else to post, and I knew i'd be flamed if i started a whole new topic on my 100th post, so i just replied to this forum......lol seriously, it was like it was calling me to post the 100th post.....and i wanted to be a senior

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Game Engine Link Prob
    By swgh in forum Game Programming
    Replies: 2
    Last Post: 01-26-2006, 12:14 AM
  2. Scripting Engine - test proggie
    By Magos in forum Game Programming
    Replies: 4
    Last Post: 07-29-2005, 08:15 PM
  3. Updated sound engine code
    By VirtualAce in forum Game Programming
    Replies: 8
    Last Post: 11-18-2004, 12:38 PM
  4. Tile Engine Scripting Idea. Suggestions?
    By napkin111 in forum Game Programming
    Replies: 8
    Last Post: 07-28-2003, 02:01 PM
  5. How do you do 'scripting' and make your own game engine?
    By Leeman_s in forum C++ Programming
    Replies: 1
    Last Post: 01-02-2002, 03:25 PM