GLBasic forum

Main forum => Bug Reports => Topic started by: Szantai on 2012-Feb-10

Title: INKEY$() problem ?
Post by: Szantai on 2012-Feb-10
        ...   
        in$=INKEY$()
        ...

        // - - - SAVE
   IF mb1
   IF BOXCOLL( mx, my, 0, 0, 1175, 716, 114, 25) // save gomb kattintás érzékelés
   GRABSPRITE 100,4,39,668,707
   SAVESPRITE txt$+".bmp",100
   load = 1
   ENDIF
   ENDIF
   //----------------------------------------------------------------------------

The save sprite command does not execute, there is no saved sprite file afterwards.
Title: Re: INKEY$() problem ?
Post by: MrTAToad on 2012-Feb-10
Does the box collision section get called ?

If so, is the filename correct ? Can you actually save to the path ?  What platform is it for ?
Title: Re: INKEY$() problem ?
Post by: Szantai on 2012-Feb-10
Does the box collision section get called ?

If so, is the filename correct ? Can you actually save to the path ?  What platform is it for ?

Everything is ok.
The platform is XP.

The "txt$" variable is empty.

Title: Re: INKEY$() problem ?
Post by: Szantai on 2012-Feb-10
it works with input command
Title: Re: INKEY$() problem ?
Post by: Szantai on 2012-Feb-10
Maybe the problem is caused by an added closing character at the end of the variable.
Title: Re: INKEY$() problem ?
Post by: Slydog on 2012-Feb-10
Did you get your 'INKEY' code from the help file?
Are you appending the 'in$' variable to the 'txt$' variable, such as:
Code (glbasic) Select
in$ = INKEY$()
IF in$<>"" THEN txt$ = txt$ + in$


Or try hard coding the file name to make sure the save command is at least correct:
Code (glbasic) Select
txt$ = "test"
SAVESPRITE txt$ + ".bmp",100


If you are trying to get the user to input the filename, you could try this command:
QuoteINPUT in$, x#, y#
Waits with a blinking carret for a user input at location x#, y#.
Title: Re: INKEY$() problem ?
Post by: spacefractal on 2012-Feb-10
IF BOXCOLL( mx, my, 0, 0, 1175, 716, 114, 25)

should property been:
IF BOXCOLL( mx, my, 1, 1, 1175, 716, 114, 25)

you cannot give 0 px in width and height and hence its cannot check the collosiion.
Title: Re: INKEY$() problem ?
Post by: Szantai on 2012-Feb-11
Bixcoll is correctly work is "0,0"
Title: Re: INKEY$() problem ?
Post by: Szantai on 2012-Feb-11
here is code (simply version)

Code (glbasic) Select

txt$=""
a = 0

WHILE TRUE

  IF KEY(14)
  clear$ = INKEY$() // buffer clear
    IF a > 0
      a = a - 1
      txt$=MID$(txt$, 0, LEN(txt$)-1) // Backspace

    ENDIF

  ELSE

    IF a<10
      in$=INKEY$()

        IF in$<>""
         txt$=txt$+in$
           a = a + 1

       ENDIF
      clear$ = INKEY$() // buffer clear
    ENDIF
  clear$ = INKEY$() // buffer clear
  ENDIF

PRINT txt$, 50, 100

         IF KEY(28)
          GRABSPRITE 100,4,39,668,707
SAVESPRITE txt$+".bmp",100
PRINT "saved",10,10
SHOWSCREEN
KEYWAIT
ENDIF

  SHOWSCREEN
WEND

END


I will not run  :(

Edit: Inserted code blocks for easy reading /Moru
Title: Re: INKEY$() problem ?
Post by: Szantai on 2012-Feb-11
If the code is such:

...
SAVESPRITE "test.bmp",100
...

is work...hmmm
Title: Re: INKEY$() problem ?
Post by: Slydog on 2012-Feb-11
Try changing:
Code (glbasic) Select
      txt$=MID$(txt$, 0, LEN(txt$)-1) // Backspace
to:
Code (glbasic) Select
      txt$=MID$(txt$, 0, a) // Backspace

...since 'a' holds the size of 'txt$'.

or change to:
Code (glbasic) Select
      txt$=MID$(txt$, 0, LEN(txt$)-2) // Backspace
it may not be removing the last character.
Title: Re: INKEY$() problem ?
Post by: Slydog on 2012-Feb-11
Change to this:
Code (glbasic) Select
PRINT ">" + txt$ + "<", 50, 100
to see range/size of string.  It may have garbage in it.
Title: Re: INKEY$() problem ?
Post by: Szantai on 2012-Feb-11
NICE THANKS  :nw:
is correctly code:

Code (glbasic) Select

txt$=""
a = 0

WHILE TRUE
SLEEP 25
  IF KEY(14)
  clear$ = INKEY$() // buffer clear
    IF a > 0
      a = a - 1
txt$=MID$(txt$, 0, a) // Backspace

    ENDIF

  ELSE

    IF a<10
      in$=INKEY$()

        IF in$<>""
         txt$=txt$+in$
           a = a + 1

       ENDIF
      clear$ = INKEY$() // buffer clear
    ENDIF
  clear$ = INKEY$() // buffer clear
  ENDIF

PRINT txt$, 0, 100

         IF KEY(28)
         txt$=MID$(txt$, 0, a-1) // Backspace
          GRABSPRITE 100,4,39,668,707
SAVESPRITE txt$+".bmp",100
PRINT "saved",10,10
SHOWSCREEN
KEYWAIT
ENDIF

  SHOWSCREEN
WEND

END


[EDIT] Added CODE tags - makes reading code easier. Ian