Quote: "Where would i be without you Grog"
Thanks.
Quote: "1) I take it that the first 'Clear Entry Buffer' has to be quite close to the do loop that that peice of code is in as it clears whatever the user might have typed while say loading screens or the like were part of the program. The further away this is the more time you have to sneak a key in (even though programs run very fast surely its possible if you held the key down for example)"
Yeah, that's exactly why that's there. The ENTRY$() command keeps every key pressed while Darkbasic Pro is running (with or without the command).
Quote: "2) a$=entry$(1) - The (1) part is a switch to make 'entry' automatically delete characters when backspace is pressed i think, if thats true why do i need the keystate(14) - i.e backspace - check?"
It only works if you don't use CLEAR ENTRY BUFFER while getting input and use the string from ENTRY$() to show input (like the example in the help files for ENTRY$()). I prefer more control over everything so I extract a character from ENTRY$() and add it to another string. Also without CLEAR ENTRY BUFFER if I tried to add the string from ENTRY$() to another string it would copy the input over and over again adding keys "a" would be "aa" then "aaaa" then "aaaaaaaa" doubling input very quickly.
Quote: "3) I cant figure out what timer is for and why it is also declared as tim when tim = timer(), why not just use timer(), also what does it do? i know what it does in relation to randomize but not what it is here."
Actually in this case it doesn't have anything to do with randomization but I'll talk about that first. The TIMER() is always counting up from the moment you turn your computer on that's why it's good to use it as a random seed because random number picking isn't exactly random. If you use the same exact seed it'll always pick exactly the same random numbers making it perfect for making encryption/decryption routines. We use RANDOMIZE TIMER() to make sure random number picking will be different each time the program runs because 99.9% of the time the TIMER() will be a different number when a user runs our programs. As a general rule if you're going to pick random numbers then add RANDOMIZE TIMER() once at the top of your code somewhere.
Now because the TIMER() is always going up we can't use it by itself to time anything so we use variables to store the current number from TIMER() (like Tim). We then compare the current number in TIMER() vs the stored TIMER() in the variable to determine how many milliseconds have gone by. In this case if the check for TIMER()>tim+100 was removed (or the TIMER() reset) just hitting the backspace key once would erase too many characters way too fast... usually the entire line of text.
Quote: "4) i see what the set text opaque does as without it, it certainly gets very messy, but on a nice neat picture background this would draw a horrible black (or whatever colour) box whereever you typed. Is there another way around this. I was thinking maybe another step where you add instantly what you type into another variable that you add to then sort of refresh the screen more deleting what was previously written but rewriting the new variable or something (i cant for the life of me think where to start)"
Yeah using SET TEXT OPAQUE is just a quick and dirty way to erase text on the screen for that example. There's an easier way than what you described. All you need is a screen sized image as a background (or just the input box size) and PASTE IMAGE or a simple BOX command to fill the area the text is going to be or even copied bitmaps. The text is redrawn every time so anything that clears the text will make backspace magically work without SET TEXT OPAQUE.
Same code using a bitmap:
` Make random number picking more random
randomize timer()
` Clear the buffer (so no previous keys are added to the string)
clear entry buffer
` Create a timer
tim=timer()
` Create a bitmap
create bitmap 1,screen width(),screen height()
` Change to the main view screen
set current bitmap 0
do
` Copy the bitmap to the main view screen
copy bitmap 1,0
` Show the prompt and user input
ink rgb(255,255,255),0
text 0,0,"User Input: " + Com$+"|"
` Get one character from entry$() and clear the buffer again
a$=entry$(1):clear entry buffer
` Check for backspace
if keystate(14) and timer()>tim+100
` Remove last character from the input string
Com$ = left$(Com$,len(Com$)-1)
` Clear a$ and reset timer
a$="":tim=timer()
endif
` Check for enter key
if keystate(28) then exit
` Add a$ to input string if it's more than nothing
if a$<>"" then Com$ = Com$ + a$
` Do something else while getting input
` Change to the dot bitmap
set current bitmap 1
` Pick a random color
ink rgb(rnd(255),rnd(255),rnd(255)),0
` Make a random dot
dot rnd(screen width()),rnd(screen height())
` Change to the main view screen
set current bitmap 0
loop
` Show the input string
text 0,20,Com$
wait key
Quote: "5) and finally, if i drew an actual box (lines only not solid) after where it says "Enter Name: " how could i get the cursor to pop up there only when they click in that box, otherwise it remains (i cant think of the word im trying to use) inactive, i.e typing wont do anything on that screen. I think i have an idea about this, perhaps a mousex + y check to see if a click is done then going into the input name, then when enter is pressed it just goes to a 'text 50, 50 name' until you click in it again."
You just make a routine to check the MOUSEX() and MOUSEY() to determine if the user is within in the box you want and MOUSECLICK() to see if they actually click a mouse button. We usually make an IF/THEN check like this: If MOUSEX()=>top left of boxes X coordinate and MOUSEY()=>top left of boxes y coordinate and MOUSEX()<=bottom right of boxes X coordinate and MOUSEY()<=bottom right of boxes Y coordinate.
Like this:
` Make a box
ink rgb(0,255,0),0
box 100,150,250,200
` Grab the entire background
get image 1,0,0,screen width(),screen height()
do
` Show the background
paste image 1,0,0
` Check for a mouse click
if mouseclick()
` Check if mouse is within the box
if mousex()=>100 and mousey()=>150 and mousex()<=250 and mousey()<=200
` Show that the button has been clicked
text 0,0,"Button Hit!"
endif
endif
loop
Where the text for "Button Hit!" is when you run the input routine is put or GOSUB to the input routine or call a function.
Quote: "Sorry for all the questions but i experimented a little with no avail, and had a look at the commands in the help file and they just arent helpful enough."
It's ok, that's why the Darkbasic Forums exist.
I'm not sure why it would do that. I personally like to use Indigo and BlueIDE which both have a help window that's always on (if we choose) that automatically updates when you click on a command (see attached image). I use them because they both allow saving of code snips in a tab that's easy to access quickly.
BlueIDE:
http://blueide.sourceforge.net/
Indigo:
http://forum.thegamecreators.com/?m=forum_view&t=173446&b=8