Jump to content
  • Advertisement


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


loading code

This topic is 5936 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

im working on my basecode(basically making nehe''s code more custom to myself) anyway, i was wondering when you want to execute code from a textfile(you know, so you dont have to recompile everytime you want to make a change) can you just save the code into a string and then execute that, for instance, have a function that initializes my players stats, can i just put
int playerhealth = 0;
into a text file then load that and use the string so that the actual program will execute that code when run or do i have to make if/switch statements and determine if certain variables are true or false and then base it on that, i hope im being clear, if not i will try to clear anything up on request, thank you in advance ,Matt -= kill one your a murderer, kill thousands your a conquerer =-

Share this post

Link to post
Share on other sites
I see what your trying to do, basical you want to define infomation in a text file and use that to make small changes to the program to reduce the hardcoding.

Basical, how you want to do it, load text and execute isnt gonna happen without building some kinda scripting system.

all you really need is a text file which, apon running of your program, get read in and the values used, and because its your own system you can define it how you want, so basical say your doing player health and armor could do have a txt file with

parmor 50
phealth 100

in it, when you start your problem, open the text file, read in the first line, get the number from it, set your players armor, repeat for health, simple isnt it.
and as your code will only read what you tell it to, after those line you could put what you want and then change your code later to read it when you are ready for it.

However, thats just one idea, i belive the system is called ''data driven programming'' so you might wanna google that

Share this post

Link to post
Share on other sites
On a more basic note, Samosa, you need to learn the difference between a ''compiled'' language and an ''interpreted'' programming language.

Now, directly altering code from a file read isn''t always possible. Let''s take C++ as an example of ''compiled'': You edit your code, then the compiler works on it and creates extremely streamlined machine code to make an executable file. Now since you''re not going to code a full-fledged C++ compiler as part of your application (I hope! ) no C++ program could read -code- from a file and execute it. The same goes for other ''compiled'' languages.

There are ''interpreted'' languages out there. Several versions of Basic (Not VB, however) will actually read their files on-the-fly and send machine code to your OS as it reads the file. As a rule of thumb, those languages are slower than ''compiled'' languages. BUT some might enable you to alter code on the fly.

I know for a fact that LISP is capable of sending chunks of its own code to its own functions as parameters and alter it on the fly. It''s no surprise that it''s a good language for university AI projects.

== Teachers and leaders should remember: Give not the people what they want, give them what they need! ==

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!