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.

Newcomers DBPro Corner / read from file as code

Author
Message
Aaron Miller
18
Years of Service
User Offline
Joined: 25th Feb 2006
Playing: osu!
Posted: 23rd Mar 2006 08:34
Hello! I need help, i'm working on a C++ project, but i dont need help with c++, i need help with darkbasic pro... I need to know how to read text from a file as a string of code.

For example:
Read the non-parameter code, suspend for key as pause
in text file= PAUSE | PAUSE as PRINT "Press a key to continue..." : SUSPEND FOR KEY

or the parameter-full MESH CUBE
in text file= MESH CUBE 1,200 | MESH CUBE 1,200 as MAKE OBJECT CUBE 1,200

How do i do this???

Ive seen and tried to use the following commands:



Please, i need help. The project im working on is a scripting engine to read data.

The engine will be used as an external file, apart from the main file. (I dont see how this wouldnt be possible...) And then the file will be included in a main exe file used to create a file maker that makes my own .dvx file extension, View my site at [href]www.freewebs.com/directexecute[/href] for more info. Ive got log off now, so i cant release any more information, just visit the site.

Thanks

View my website![href] http://www.freewebs.com/directexecute/index.htm [/href]
Euphoria
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: United Kingdom
Posted: 23rd Mar 2006 11:12 Edited at: 23rd Mar 2006 11:15
This should read in a file and store each line as an array element, if you are planning on using multiple commands per line in your script then you will need to break down each line further using a command delimiter.



hope it helps
Aaron Miller
18
Years of Service
User Offline
Joined: 25th Feb 2006
Playing: osu!
Posted: 23rd Mar 2006 22:38
Thanks i'm testing the code right now.

View my website![href] http://www.freewebs.com/directexecute/index.htm [/href]
Aaron Miller
18
Years of Service
User Offline
Joined: 25th Feb 2006
Playing: osu!
Posted: 24th Mar 2006 08:11
So how do i do it with multiple parameters?
Ive got a lot so far, heres the source

do
Dim commandList() as string
cmd$ = ""
var$ = ""

open to read 1,"script.src"

main:
` read in file and add each line to array
if file open(1)=1
while file end(1)=0
do
read string 1,cmd$
if left$(lower$(cmd$),5) = "print" then print right$(cmd$,len(cmd$)-6)
if cmd$ = "dir" then dir
if cmd$ = "pause" then print "Press any key to continue..." : suspend for key
if cmd$ = "drives" then drivelist
if cmd$ = "exit" then end
if cmd$ = "cls" then cls
if cmd$ = "paint" then goto paint
if cmd$ = "done" then goto start
if cmd$ = "text color 1" then ink rgb(0,0,255),0
if cmd$ = "text color 2" then ink rgb(0,255,0),0
if cmd$ = "text color 3" then ink rgb(255,0,0),0
if cmd$ = "text color 4" then ink rgb(0,255,255),0
if cmd$ = "text color 5" then ink rgb(255,255,0),0
if cmd$ = "text color 6" then ink rgb(255,0,255),0
if cmd$ = "text color 7" then ink rgb(255,255,255),0
if cmd$ = "key wait" then suspend for key
loop
array insert at bottom commandList()
commandList() = cmd$
endwhile
close file 1

endif


` Walk through array and display each line
array index to top commandList()
repeat
next array index commandList()
until array index valid(commandList()) = 0
loop

paint:
cls
oldMouseX=mousex()
oldMouseY=mousey()
ink rgb(255,255,255),0
box -35,-35,1000,1000
ink rgb(0,0,0),0
do
if mouseclick() = 1 then line oldMouseX,oldMouseY,mousex(), mousey()
if mouseclick() = 2 then cls : ink rgb(255,255,255),0 : box -3,-3,650,650 : ink rgb(0,0,0),0
if returnkey()=1 then get image 1,0,0,640,480 : save image "artpad.bmp",1 : cls : goto main
oldMouseX=mousex()
oldMouseY=mousey()
sync
loop

start:
cls
ink rgb(255,255,255),0
print "Program is done!"
print "Press any key to close..."
suspend for key
end


Thats what ive got. And ive been trying to get a "MESH MATRIX" command. This works fine, i got dbpro a month or 2 ago, and i havnt updated it, it looks like it says it version 5.5 and thas what this works on. Anyways, since i got the help from here and it works, i would assume that everything works fine. My version still has the icon bug, and occaisonoly after i compile this program and it runs, the compiler stops at the very end, the program runs, but the editor stops. Anyways, heres the source for a file made in my language...
SCRIPT.SRC

cls
text color 1
print Hello World!
text color 2
print Hello World!
text color 3
print Hello World!
text color 4
print Hello World!
text color 5
print Hello World!
text color 6
print Hello World!
text color 7
print Hello World!
pause
cls
print Here is a list of files in this directory
dir
pause
cls
print Initializing the paint system...
print Press ENTER to save the picture and end your PAINTING SESSION
pause
cls
paint
print Done!
print Press any key to end...
key wait
done


Thats the SOURCE.SRC file, place it in the same directory as READ.EXE file (thats what i call the main source file). Anyways, Thats what ive got so far, i would like to know how to use a MESH MATRIX command (because the entire matrix, with the users complete input, has a lot of parameters, so it should help me a little bit)

Thanks for all your help

View my website![href] http://www.freewebs.com/directexecute/index.htm [/href]
Euphoria
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: United Kingdom
Posted: 24th Mar 2006 10:41
I can't help on the mesh matrix thing, but on the first thing. Reading lines with multiple commands:

You could just set a delimiter for each command (for example "|") and then split the line based on that. So loop through each character on that command line, if you hit the delimiter or end of line then that command is complete.

Take another look at your code as well, you should be executing each command 'AFTER' you have read the file in as oppose to 'AS' you read it in. Your conditions (take a look at the SELECT & CASE commands as well) should be in the loop marked 'walk through array'.

Lastly try to avoid using Goto in the way you have.....gosub and functions are your friends oh and when posting code use the button to ensure it displays properly in the forum.


good luck
Aaron Miller
18
Years of Service
User Offline
Joined: 25th Feb 2006
Playing: osu!
Posted: 25th Mar 2006 08:53
(I did use the buttons, i accidently did something by accident and it was erased (by accident, sorry about that).

I'll take more to tutorials so that should help me too.

I dont know exactly what you mean by the "|" line, I know that that is what is used in batch files, and some other programs and stuff. But other then that i've got a good idea of what youre getting at. I dont know the differance between executing the commands while the program reads them, or after the program reads them, but this way is easier for me

Anyways, i took some functions from code snippets and the codebase and now i have support to encrypt/decrypt a file, and display meesages. I'm not sure about everything i added but this is what ive got (hopefully working this time)


That should be in a code snippet now, Most of the functions are from other peoples code.

Anyways, thank you for your response

View my website![href] http://www.freewebs.com/directexecute/index.htm [/href]

Login to post a reply

Server time is: 2024-11-27 23:34:02
Your offset time is: 2024-11-27 23:34:02