Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Run a string as a command

Author
Message
A r e n a s
18
Years of Service
User Offline
Joined: 9th Jun 2008
Location:
Posted: 19th May 2010 20:19
Hey guys, I was wondering if it is possible to open to read a file and then take the files contents and run it within the program. For example:

Program:



File To Run:



So this program would read what is in the file and run it as part of the program.

Any help on the subject would be massively appreciated.

Thanks, Arenas

Kryogenik
16
Years of Service
User Offline
Joined: 22nd Sep 2009
Location: Heidelberg, Germany
Posted: 19th May 2010 20:27
Well, you can't run code from a text file, because DBPro exports machine code, and the exe's can't actually read the language and do stuff. I know that sounds bad, but DBPro would be slower if it ran it's source from a file and then had the exe interpret it. I guess you could just do something like this.

If you did it right, then it would work fine. You could have commands wth parameters and have the program run them like normally, with the values from the text file. I think there is also an LUA plugin that lets you have seperate source files that get read in program, and includes most of the DBPro commands, but I've never tried it.
Hope that helped.

Codesurge is so awesome, thanks Hyrichter.
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 19th May 2010 20:32
Aha, the fun of scripting... Anyway, to answer your question, no your can't (which Kryogenik beat me to when I was writing this), but what you can do is use a string from a file to reference a function or in this case a command. We will call this low level scripting.

So basically you:

Read string ¬
Check if string is a key word like 'end' ¬
If it does end program.

Or:



Even better:



A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
A r e n a s
18
Years of Service
User Offline
Joined: 9th Jun 2008
Location:
Posted: 19th May 2010 21:03
This isnt ideal if I then choose to do more advanced pieces of code in the text files... I was thinking of doing something more advanced in the textfiles. This code is really being used for an AI system with a list of commands so there would be very few AI commands as simple as end...

Thanks anyway guys, it looks like i will be hard coding the AI, which will make the program less flexible if I choose to add new AI once its built...

Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 19th May 2010 21:16
That's an odd response given that it wasn't what you asked for. If you'd mentioned that it needed to be more advanced and its for AI then I would have responded accordingly.

Could you give us an example of something more advanced you put in a text file please, then maybe we could help.

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
A r e n a s
18
Years of Service
User Offline
Joined: 9th Jun 2008
Location:
Posted: 19th May 2010 21:54
Ye, I'm not getting at you guys cause the advice was helpful anyways The idea is that this will be run in C++. I have scrapped the idea of text files cause it would have caused a massive strain on the engine opening and closing so many text files

Login to post a reply

Server time is: 2026-07-25 16:19:27
Your offset time is: 2026-07-25 16:19:27