Main Menu

Help on Tic Tac Toe Game

Started by servogod85, October 14, 2005, 07:13:17 PM

Previous topic - Next topic

servogod85

Anyone can tell me what I am doing wrong? It's only supposed to delete the last character if the player presses BackSpace Key. I posted the surce and the interface :huh:



; PROJECT : GetName
; AUTHOR  : Salvatore Servodio
; CREATED : 10/14/2005
; EDITED  : 10/14/2005
; ---------------------------------------------------------------------


OpenScreen 800,600,16,1

MaxX= 800
MaxY= 600

ScreenName= 1
LoadImage "C:\Documents and Settings\Salvatore Servodio\Desktop\Get Name\EnterName.PNG", ScreenName

RenderToScreen
DrawImage ScreenName,0,0,0

LoadFont "Ariel",1,60,0
MakeBitmapFont 1,RGB(0,0,255)
SetFont 1
Text RoundUp(MaxX*0.05),RoundUp(MaxY*0.70),"Player 1"
Text RoundUp(MaxX*0.05),RoundUp(MaxY*0.80),"Enter name"


;Set Player Input Color..why doesn't the White show up??
MakeBitmapFont 1,RGB(255,255,255)
Sync

;Get Player One's Name
Name1$= ""
Temp$= ""
Lung= Len(Name1$)

Repeat
WaitKey
If KeyState(14)= 1
  Temp$= Name1$
  Lung= Len(Name1$)
 ;Here is the problem...why doesn't it just delete the last char..
 ;On the screen it deletes everything....what to do?? :(
  Name1$= CutRight$(Temp$,Lung-1)
  BoxC RoundUp(MaxX* 0.15),RoundUp(MaxY* 0.31),RoundUp(MaxX* 0.85),RoundUp(MaxY* 0.50), 1, RGB(0,0,0)
  Text RoundUp(MaxX* 0.15), RoundUp(MaxY* 0.30),Name1$
  Sync
EndIf
If Len(Name1$) < 20
  Name1$= Name1$ + Inkey$()
  BoxC RoundUp(MaxX* 0.15),RoundUp(MaxY* 0.31),RoundUp(MaxX* 0.85),RoundUp(MaxY* 0.50), 1, RGB(0,0,0)
  Text RoundUp(MaxX* 0.15), RoundUp(MaxY* 0.30),Name1$
  Sync
EndIf
Until EnterKey()



kevin

#1
Well after a quick loook, It appear to be a logic problem.

As when you hit then delete key.  The first IF/then segment will run.  This routine will remove the last chr as you wish.     But,  it will then fall through to the next IF/Then statement, which checks if the length of the Name string is bellow 20.  This will also be true.  So it will then attempt to add the backspace CHR (which doesn't have one) to your name string.    Which is obviously not what you want.

Another small issue is the delete chr code, should really check the length before deleteing a chr. And when deleting the chr you should use the left$() function for ease.

Although the best solution be to use one of the posted input routines in the source code forum.

servogod85

#2
:) Thanks for the advice, but I decided to leave the name part out and just keep "Player 1" and "Player 2" due to the lack of time. I still need to finish the A.I. part which is pretty much a MOUNTAIN of IF...THENS. I need to post a game on this forum just to show everyone that I got the skills. As soon as I am done I'll send it in. It's not a side scroller, but it's a start. If I have any problems I'll let you know. Thanks!

Salvatore

servogod85

#3
Duh!! Oh wow I tried it out and it is so true..Darn it, I am so tired when I come home from work, I guess that's  why I miss these details out...Thanks Alot once again.

Salvatore