I am just getting to grips with tempest, and I\'m making a simple chat client. For some reason this seems to work fine whenever I remove scancode() or returnkey(), they seem to crash it, its really weird the display mode even changes when I haven\'t told it too. ARGH!
size = 26
Print \"1 - Host Chat Client:\"
Input \"2 - Join Chat Client: \", choice
if (choice > 2) OR (choice < 1) then END
if choice = 1 then GOSUB _host
if choice = 2 then GOSUB _join
OURID = TGetThisID() `Stores the ID of the user
dim CHATLOG(size,1) AS STRING `This holds the strings sent my other players, so that the messages may \"move up the screen\" msn messenger stylie (or like pretty much any other chat program). The dimension (x,0) holds the name of the user who sent the message. And dimension (x,1) holds the message itself.
index = 0 `this indicates the slot that the chatlogs have got to thus far
x = 0 `cursor x
y = 590 `cursor y
do
CLS
newmessage = TGetMessage()
if newmessage
from = TGetSender()
chatstring$ = TGetString()
`dump message data into chatlog
CHATLOG(index,0) = TGetPlayername(from)
CHATLOG(index,1) = chatstring$
inc index `increment index
if index = size then index = 0 `if the end of the array is reached, go back to the start
endif
y = y - 20 `sets y so that the line below prints above where the user enters their message
set CURSOR x,y
`print aforementioned line
PRINT \"- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \"
y = y - 15 `move cursor up
set CURSOR x,y
if index <> 0
for i = index to 0 STEP -1
`if there is a string in the current slot of the log
if (CHATLOG(i,0)<> \"\") and (CHATLOG(i,1)<> \"\")
`set the cursor up and print in the format name: message
set CURSOR x,y
PRINT CHATLOG(i,0);\": \";
PRINT CHATLOG(i,1)
`move cursor y up for next string
y = y - 20
endif
next i
endif
x = 0
y = 590
set cursor x,y
`this was originally intended to add to a string as keys where pressed, and printing the string so far where the user is entering their message, giving the illusion of an INPUT TEXT,VARIABLE command, only the system doesn\'t need to pause in order for this to happen. Then when the return key is pressed, this message is sent out to all the other users, and dumped into the chat log, and the string storage variable is cleared (though not all of this code is here, as I never got that far)
`outstring$ = outstring$ + INKEY$()
PRINT SCANCODE()
`if RETURNKEY()
` TPutString outstring$
` CHATLOG(index,0) = TGetPlayername(OURID)
` CHATLOG(index,1) = outstring$
` inc index
` if index = size then index = 0
` TSendAll
`Endif
TSync
SYNC
loop
_host:
input \"Enter Max Users: \", MAXPLAYERS
input \"Enter Name: \", nick$
input \"Enter IP: \", ip$
result = THost(ip$, MAXPLAYERS, nick$)
host = 1
`If hosting failed then report to user and quit
if not result
print \"Failed to host game\"
wait key
end
endif
RETURN
_join:
host = 0
input \"Enter Name: \", nick$
input \"Enter IP: \", ip$
result = TJoin(ip$, nick$)
`If hosting failed then report to user and quit
if not result
print \"Failed to join game\"
wait key
end
endif
RETURN
<img src="http://www.freewebs.com/equilibrium-movie/crazyanimationshiit7yq.gif">