forums

TNT Basic Forums > Programming Q&A
user ask ?
< Last Thread     Next Thread >
Author
Thread        Post A Reply

12-22-2003 02:37

Posted by:
Leorik The Creator

Location:
Montréal,Québec(canada)

Find more posts by Leorik The Creator

'is it possible to ask something to the user like:
print "whats is your name ? "
'and to keep the information after...
'how the user will answer ?


Thanks
leorik totally confused...

12-22-2003 07:16

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

Yeah, you can do it. It's a bit complicated, but I'll try to give a basic outline.

What you have to do is make a loop:
1) Read the keyboard to see if a key is pressed
2) See if it is a printable character or something else like an arrow key.
3) If it is a printable character, check to see which modifiers are pressed.
4) Modify the character according to the modifier keys
5) Put the character in a string where the cursor is
(to keep track of the cursor, just keep track of which letter the cursor is in front of. Then use the "right str" and "left str" commands to insert the new character.
6) Draw the string and draw the cursor after a specific number of frames.

12-22-2003 07:57

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

Ok, I made an example. For some reason the filter commands created errors in TNT so I made the example without them.

quote:
print "INPUT"
ReadInput("Default")
str nameStr=result str

procedure ReadInput(str inputString)
keyboard repeat on 'makes it so that if a key is held down it repeats
clear keyboard 'clears the queue
int rawKey
int cursorPosition
int keyScancode
str char

repeat
rawKey=keyboard raw key
keyScancode=raw key scancode(rawKey)
'THIS DOESN'T SEEM TO WORK if raw key filter navigation(rawKey)=true 'if the key is a directional key
if not(rawKey=0)
if keyScancode=126 'if up, put the cursor at the front
cursorPosition=0
else if keyScancode=123 'if left, move the cursor back
cursorPosition=cursorPosition-1
else if keyScancode=125 'if down, put the cursor at the end
cursorPosition=str length(inputString)
else if keyScancode=124 'if right, move the cursor forward
cursorPosition=cursorPosition+1
else if keyScancode=51 'if delete
if cursorPosition>0
inputString=left str(inputString,cursorPosition-1)+right str(inputString,str length(inputString)-cursorPosition)
cursorPosition=cursorPosition-1
end if
'THIS DOESN'T SEEM TO WORK else if raw key filter printable(rawKey)=true 'if the key is one that can be printed
else if not(raw key char(rawKey)="") 'if it's a printable character
if cursorPosition<0 then cursorPosition=0 'the cursor can't be behind zero
if cursorPosition>str length(inputString) then cursorPosition=str length(inputString) 'the cursor can't be any farther than the end
inputString=left str(inputString,cursorPosition)+Raw key char(rawKey)+right str(inputString,str length(inputString)-cursorPosition) 'this adds the letters left of the cursor, the new letter, and the letters right of the cursor
cursorPosition=cursorPosition+1 'moves the cursor up
end if
end if
DrawInput(inputString,cursorPosition)
until pressed(36)'until return
end proc(inputString)

procedure DrawInput(str theString,int cursor)
str printString
printString=left str(theString,cursor)+"|"+right str(theString,str length(theString)-cursor)
print printString
end proc

12-22-2003 17:34

Posted by:
Leorik The Creator

Location:
Montréal,Québec(canada)

Find more posts by Leorik The Creator

ok

Yea its a bit to complicated for what it does but i understand the logic...

12-22-2003 19:13

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

All you need to do is adapt the draw procedure to your game.

12-23-2003 13:20

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

Hey, didn't the latest version of TNT include an input function?

12-23-2003 16:31

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

It's not just one command, it's many. I guess it's to give more flexibility. There's the new key queue and the raw key system now, so the game catches all the key presses. There are also filters, which seem to cause errors now, and the string editor.

01-01-2004 19:45

Posted by:
Mark Tully

Location:
TNT HQ, England

Click Here to Email Mark Tully   Find more posts by Mark Tully

The string editor does what you want, read:

http://www.tntbasic.com/learn/help/guides/keyboard_guide.htm#stringeditor

As for the raw key filtering commands, they are indeed broken in this release, I'll have them fixed by the next version.

Mark

01-03-2004 00:28

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

Oh, I didn't realize that there was a "string editor input" command! That makes the string editor a lot more useful...I thought it was simply a string and and integer for the cursor position.

01-11-2004 01:14

Posted by:
Leorik The Creator

Location:
Montréal,Québec(canada)

Find more posts by Leorik The Creator

ok thanks

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.