Author Topic: Problem with locate command  (Read 4418 times)

0 Members and 1 Guest are viewing this topic.

Offline Phenominalprogrammer

  • Newbie
  • Posts: 1
    • View Profile
Problem with locate command
« on: August 26, 2020, 07:06:20 pm »
When I try code like this I get

Illegal function call





Code: QB64: [Select]
  1. Location_x = 100
  2. Location_y = 25
  3.  
  4. Locate location_x, location_y
  5.  
  6. Print "a nice test"
  7.  


Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Problem with locate command
« Reply #1 on: August 26, 2020, 07:12:43 pm »
You can only LOCATE within the character cells of the screen. One character is 8 X 16 pixels.
Default screen is 640 X 400? 640 /8 = 80 max cell column

400 / 16 = 25 rows

PLUS if you start to print past the last row or 2 the screen starts scrolling or will switch to _FONT 8 first.

Welcome to the forum @Phenominalprogrammer
« Last Edit: August 26, 2020, 07:14:45 pm by bplus »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Problem with locate command
« Reply #2 on: August 26, 2020, 09:42:09 pm »
You can only LOCATE within the character cells of the screen.

One point of quirkiness which you may not be aware of, Bplus: That statement isn't correct in 100% of all cases. 

LOCATE with a variable-width font, and there's no set character cells to reference.  Instead, you LOCATE X-pixels width, Y-rows down.   (It's not row/column, and it's not  pixel/pixel reference; it's a hybrid pixel/row reference.)

Of course, SCREEN 0 (which is all that's referenced by default in the original code) won't even work with variable-width fonts at all, so for most folks it's a moot distinction.  ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Problem with locate command
« Reply #3 on: August 27, 2020, 01:21:36 pm »
WHILE  Bplus AND SMcNeill give the right tecnical informations
 I must add this one
  your code posted is a QBasic/QB way to use screen mode in console state or in other words
your code
Code: QB64: [Select]
  1. Location_x = 100
  2. Location_y = 25
  3.  
  4. LOCATE location_x, location_y
  5.  
  6. PRINT "a nice test"
  7.  
is equal to
Code: QB64: [Select]
  1. Location_x = 100
  2. Location_y = 25
  3.  
  4. LOCATE location_x, location_y
  5.  
  6. PRINT "a nice test"
  7.  
because in QBasic/QB if you don't specify the screen mode that , for default, it  is the console screen only text 80x25, 31 foreground colors and 7 background colors (32 and 8 if you include the black). QB64 emulates QB so you get the same error!
But this syntax must be deprecated if we must give more importance to QB64 than Qbasic/QB, in fact in QB64
you should write so
Code: QB64: [Select]
  1. SCREEN _NEWIMAGE (80,25,0)
  2. Location_x = 100
  3. Location_y = 25
  4.  
  5. LOCATE location_x, location_y
  6.  
  7. PRINT "a nice test"
  8.  
and in this case it is obvious why you get the error!

WEND
Programming isn't difficult, only it's  consuming time and coffee

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Problem with locate command
« Reply #4 on: August 27, 2020, 01:45:34 pm »
Code: QB64: [Select]
  1. _TITLE "Locate Test in default screen, press spacebar for another 20, press esc to quit"
  2. T$ = "A nice test."
  3. lt = LEN(T$)
  4.     CLS
  5.     FOR i = 1 TO 20
  6.  
  7.         ' KEEPING Row and Col in bounds for LOCATE
  8.         row = INT(RND * 25) + 1: col = INT(RND * (80 - lt)) + 1
  9.         'LOCATE 1, 1: PRINT SPACE$(20) 'debug row and col
  10.         'LOCATE 1, 1: PRINT row, col
  11.  
  12.         LOCATE row, col: PRINT T$;
  13.     NEXT
  14.     SLEEP
  15.  
  16.  
  17.  

Offline MWheatley

  • Newbie
  • Posts: 64
    • View Profile
Re: Problem with locate command
« Reply #5 on: August 28, 2020, 10:54:10 am »
I'd add that LOCATE has for me always been a difficult command in terms of code compatibility: different BASICs implement it in different ways.  I once ported some regularly-used statistics calculations over to Liberty BASIC, in the days before QB64 (or at least, before I discovered QB64).

Liberty BASIC implements LOCATE the other way round -- ie, not LOCATE x, y but instead LOCATE y, x...!  Which to me is crazy.  When I gave up on Liberty BASIC (I felt ripped off on licensing too, which didn't help), I had to convert everything back.

So use LOCATE with caution, is my advice.

Malcolm


Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Problem with locate command
« Reply #6 on: August 28, 2020, 11:46:21 am »
None problems with LOCATE. First set your text screen to correct values. Locate use is LOCATE  ROW, COLUMN


Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(100, 25, 0)
  2.  
  3. Location_x = 100
  4. Location_y = 25
  5.  
  6. LOCATE Location_y, Location_x
  7.  
  8. PRINT "a nice test"
  9.