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 / Positioning User Input feature

Author
Message
DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 12th Sep 2010 15:17
Hi all,

I can't seem to get this right. You know how games have high scores and they allow the user to input their name? Well I've done all that using the INPUT command but the only problem I'm having with is that I don't know how to move it.

If I done a normal code, the input is near the top left of the screen.

I want the name input to appear in the middle of the screen. How do I do this?

Also, I was told that using Input to record a user's name is not the best way... is there another method?

Thanks.
Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 12th Sep 2010 15:22
You can use 'set cursor' to change the location.

If you need more control, you should have a look at using 'entry$()' instead.

[b]
DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 12th Sep 2010 15:24
Ah entry$, I think that's the one I was told to use.

But uh... I actually don't know how to use entry$ properly =/

Do you have an example code by any chance?
Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 12th Sep 2010 16:07 Edited at: 12th Sep 2010 16:10
There, a quick example.


My computer surpasses all the technologies of the day. What computer do I have?

DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 12th Sep 2010 16:23
Cool thanks ^^

Is there also a way to limit the number of characters a player can insert?
DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 12th Sep 2010 16:51 Edited at: 12th Sep 2010 16:52
Hmm... I can't seem to get it to work.

This is my code:



I also declared in the beginning of my program that the variable 'name' is a string. The text comes up indicating a high score, but I can't type in anything.
Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 12th Sep 2010 16:54 Edited at: 12th Sep 2010 16:55
Yes, just do this which makes sure it is only 8 characters long at the most.
Also you need to put it in a loop since it needs to constantly update.


My computer surpasses all the technologies of the day. What computer do I have?

DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 12th Sep 2010 17:23
Hmmm... something's still wrong.

I tried your code and it's not working. But then again I think it's because I wasn't specific. I wanted so that when the player is typing, once it reaches X amount of letters, the player can't type anymore until they hit Backspace.

That's not the main problem though, the main one is that I can't seem to get my code to record and store the user input after they insert their name.

This is my code:



So when the player loses, if the score the player gets beats the last stored score, then 'highscore' becomes 1, which allows the player to insert their name. After the player presses ENTER, the game restarts and the name is stored.

Obviously the code above doesn't work because the condition to store the info happens basically before the player gets to insert their name (at least that's how I understand it)

But I can't seem to figure out how to fix this and make it do what I want... I've never played around with user inputs before, so yea =/
Igglepud
15
Years of Service
User Offline
Joined: 14th Aug 2010
Location:
Posted: 12th Sep 2010 21:18 Edited at: 12th Sep 2010 21:20
I've been working on a high score table myself. Here's what I've got. It works for me. all you need to add to it is a "center text" command or a cursor position. "INPUT" works fine for this score table since it asks for the player name immediately before displaying the high scores. I use entry$(1) in the rest of my program, but that is because a lot of other stuff is going on that can't be interrupted.

This also stores a list of the top 10 scores so the scores are still there next time you run the program. I hope this is helpful.



DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 13th Sep 2010 11:51 Edited at: 13th Sep 2010 13:18
Thank for that ^^

I'm trying to start slow first but for some reason, the text in my input command isn't showing up. This is my code for the high score:



So in my program somewhere, if score > bestscore then highscore = 1.

The above does all I want but the text after the input command doesn't show o.O

If I use Text to write the message and use input, the text doesn't show up either.

I can't figure out why. I also didn't put in CLS because my game is 3D and if I CLS, the game world disappears =/

Once I get this right, I wanna implement the top 10 feature as well =D

EDIT: By the way, I also tried changing the variable name to name$ (I also declared it as a STRING in the beginning of the program)
Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 14th Sep 2010 02:21 Edited at: 14th Sep 2010 02:23
I told you that you need to put entry in a loop.
Try this, just edited your code. It works now, i tested it.


My computer surpasses all the technologies of the day. What computer do I have?

DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 14th Sep 2010 11:07
@Madscientist

Oh I thought I mentioned that in my reply to yours. Sorry about that. Yeah I did place the code inside the do loop but it still didn't work.

But just on a side note, initially that piece of code was in a function called highscore() which is called from the do loop, so I think that still constantly refreshed it right?

Well anyway, I inserted the new code and it works! Thanks very much for the help.

I might try working on implementing a top ten feature now through Igglepud's code now.

Thanks all ^^
DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 14th Sep 2010 11:17 Edited at: 14th Sep 2010 11:34
Oh by the way... this doesn't matter for me, but if anyone cares...

While inputting letters, although it only shows up to X amount of characters (where X is the number you chose)... if you kept typing and then tried to delete letters, it will delete the "invisible" letters first.

For example with the current code, it's up to 8 right? So if I typed in 20 letters, only 8 will show but I would need to backspace at least 12 times before it starts deleting the 8 visible letters. Looking at the code, it shouldn't do that, but it's happening to me (unless I misunderstand the code)

Anyway thanks again for the help ^^
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 14th Sep 2010 15:24
If you use my plug-ins, then you can replace this line:


with these lines to avoid that problem:


Utility plug-ins (26-JUL-2010)
I'm applying terms of use that require you to wear a red nose and honk a horn whenever you use the Internet
DVader
22
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 14th Sep 2010 15:43
@ Db newbie looks like you fixed it but in case you didn't notice the difference, it was because you were using a standard float not a string to save the entry$ into. Eg

name=entry$(1)
instead of
name$=entry$(1)

http://s6.bitefight.org/c.php?uid=103081
DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 15th Sep 2010 08:11
Usually when I make strings, I declare them in the beginning:



I mean, the fact that people put the $ in front of a variable is to show that it is a string right? I assume also that putting a $ in front of a variable automatically makes that a string? But I usually just declare it.
DVader
22
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 16th Sep 2010 16:17
I never use that, don't really see the point. For one it's nice to see instantly if the variable is a string float or integer. Secondly it seems redundant code. Eg.

names$="Darth Vader"
players=2
playerX#=0

etc

instead of using

name as string
players as float
playerX as integer

name="Darth Vader"
players=2
playerX=0

But I rarely use functions and stick to gosubs, so it is just my style of programming. Still even if I do declare global variables I still use the $ symbol at the end etc, to help readability.

http://s6.bitefight.org/c.php?uid=103081
Spritzen
16
Years of Service
User Offline
Joined: 12th Aug 2009
Location:
Posted: 16th Sep 2010 16:47
That's defiantly a case of personal style, I find that declaring globals and locals at the top/function/gosub etc.. helps make sure you don't use the same variable twice by mistake. However I can see the value of using the short hand version.
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 16th Sep 2010 19:41
Quote: "For one it's nice to see instantly if the variable is a string float or integer. "


I'm the same way it's better to see $ and # symbols in code. The only time I don't is when it's in a UDT. But I only use functions and never use GOTO or GOSUB anymore unless I'm helping a newbie.

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 18th Sep 2010 05:40
@IanM
I was looking for a command exactly like that but there was none.

My computer surpasses all the technologies of the day. What computer do I have?

Login to post a reply

Server time is: 2026-07-24 23:12:37
Your offset time is: 2026-07-24 23:12:37