plug ins

This is a discussion on plug ins within the C++ Programming forums, part of the General Programming Boards category; I know now I am ruching into things again. But I gotta learn this so I am not asking you ...

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    731

    plug ins

    I know now I am ruching into things again. But I gotta learn this so I am not asking you to tell me how to do this. Once again like many other times I am asking for someone to point me tourds a nice tut on how to do this. I just want it so OTHER people can make plug ins for this. And of course me.

  2. #2
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Ive been looking into that same thing, I'll let you know if I find any god tutorials.

    (note: you oculd start with the DLL tutorial at www.gametutorials.com)

  3. #3
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    alrihgt maybe that is what I am looking for because I'm not srue any more.

  4. #4
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    I'm going to try and give a better description of what I want to do now. I am making a simple program for now that the user puts something in and it says something back if the word the user puts in matches. So I want to make it so people can make a "plug in" for it that would become a seperate file and if it is in the directry of the porgram it will put the code in the program. Like a dll but people can make them. They would add text so if the user puts something int hat matches it will say what the plug in tells it to say.

    I hope I didn't confuse people becuase I confused my self.

    Oh and this has really ben bothering me alot!

    Thank you a ton!!!!

  5. #5
    Registered User
    Join Date
    Aug 2004
    Location
    San Diego, CA
    Posts
    313
    Why not just have two .txt flatfiles? One called "words.txt" and the other called "responses.txt" that your program reads out of, one word/response per line? Then you can just get each individual line, and do string comparisons. Plus it's easy to swap in and out.

  6. #6
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    Lol I was just thinking of something like that. But the probebly I am trying to get around is having mroe then 1 .txt file. And if a user creates one the program will not know what to look for. But other wise that sounds like a great idea!

    Thanks

    Edit: Not sure how I would do that.

    Edit Edit: Would I have to open the txt files first?
    Last edited by Rune Hunter; 09-04-2004 at 08:45 PM.

  7. #7
    Registered User
    Join Date
    Aug 2004
    Location
    San Diego, CA
    Posts
    313
    Code:
    void Load()
    {
    	char ans[512];
    
    	std::cout << "What is your words file? ";
    	std::cin >> ans;
    
    	std::fstream file1(ans);
    
    	std::cout << "What is your responses file? ";
    	std::cin >> ans;
    
    	std::fstream file2(ans);
    }
    Something like that.. then you just work with file1 and file2.

    As to your Edit^2, you only have to open the file specified by the user at runtime. If you don't want that, then write a function that will auto-detect every file in a given directory - but good luck finding the companion files unless you have a convention like "All words files must have their companion responses file have the same name, except with a single "r" at the beginning" or some such thing.

  8. #8
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    alright now one mroe thing is confusing me.

    The words file would look something like this...

    hi
    bye
    hello

    And how would I compare a line? To a string?

    And same thing with the responses file. How would I pick a response to be spoken?

  9. #9
    Registered User
    Join Date
    Aug 2004
    Location
    San Diego, CA
    Posts
    313
    Ok. If I was going to do this, I would have a few conventions.

    1.) All lines in a file MUST BE NUMBERED.
    2.) All words and responses must be one single line.

    With that set, I would have a words file with something like:

    1 cat
    2 dog
    3 cow

    and a responses file like:

    1 You said "cat", that is correct!
    2 Woof Woof.
    3 Mooooooo

    And then, in the code, I would use file1.getline() and file2.getline() to store in two char variables (buffer1 and buffer2), then use strcmp() to compare the strings. If you want to compare the user input string, then you could strcmp(user_answer, buffer1) [where buffer1 is your words file with a line loaded], and when that evaluated to 0, you would activate a function to cout buffer2.

    The reason I would number the lines is so that I could write a function to go to a certain line, and then get whatever's after the number. And be able to match that to the responses.txt file.

    Get what I mean?

  10. #10
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    Alright I get what you mean here but what doesn't make sence is file1.getline() it would get the whole line wich would be one line...

    2.) All words and responses must be one single line.
    So how would it know wich oen to get?

  11. #11
    Registered User
    Join Date
    Aug 2004
    Location
    San Diego, CA
    Posts
    313
    You would have every word and response on a seperate line. They are numbered so you can write a function to look for "1" or "10" or "34" and load that line.

  12. #12
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    Hmm I was thinking and...I gotta look at anoutehr post first... I'll edit back soon....

  13. #13
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    why bother numbering them... why not just count them as you read them in?

  14. #14
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    So much for the edit but anyways I got this from anoutehr post that I needed help in. I needed to know hwo to save a game.

    So I got this code...


    Code:
    #include <fstream>
    
    int var1 = 20;
    int var2 = 30;
    
    struct TestClass
    {
       int objVar1;
       double objVar2;
    };
    
    TestClass test;
    
    int main()
    {
        test.objVar1 = 5;
        test.objVar2 = 4.5283928334328;
    
        std::ofstream file("filename.dat", std::ios::binary);
    
        file.write((char*)&var1, sizeof(var1));
        file.write((char*)&var2, sizeof(var2));
        file.write((char*)&test, sizeof(test));
        file.close();
    
        return 0;
    }

    .dat files or what ever I am goign to try and use. I could have a "plug in" maker type thing that creates .dat files! All I need is a ton of variables (wich I am good at) and other stuff!

  15. #15
    Registered User
    Join Date
    Aug 2004
    Location
    San Diego, CA
    Posts
    313
    Quote Originally Posted by Perspective
    why bother numbering them... why not just count them as you read them in?
    Good question. Perhaps because my mind works different than yours. That's just a matter of style and a couple of bytes. *shrugs* You could do it either way.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Case mods for fans?
    By Shadow in forum Tech Board
    Replies: 12
    Last Post: 04-04-2003, 01:03 PM
  2. Funniest thing happened to be earlier this year
    By face_master in forum A Brief History of Cprogramming.com
    Replies: 17
    Last Post: 11-07-2002, 04:39 PM
  3. Shameless plug...
    By Imperito in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 09-03-2002, 09:56 PM
  4. Insert plug here...
    By CompiledMonkey in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 04-07-2002, 07:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21