GLBasic forum

Main forum => GLBasic - en => Topic started by: shaf on 2007-Nov-09

Title: New to GLbasic but used to older lsanguages
Post by: shaf on 2007-Nov-09
Hello,

I was expecting GLbasic to be similar to Basic but with Structured commands and similar syntax.
Currently I'm converting some very old Basic Programs (Circa 1983).

Is there a table comparing ANSI Basic Commands with GLBasic equivalents?

Thanks

Shaf

p.s. Gernot it's your postings on RetroRemakes that got me interested in GLBasic.
Title: New to GLbasic but used to older lsanguages
Post by: x-tra on 2007-Nov-09
What is RR?
Raidr... ???

What posting?
Title: New to GLbasic but used to older lsanguages
Post by: Kitty Hello on 2007-Nov-09
The main difference between GLBasic and old-school basic is the working with arrays:
old school:
Code (glbasic) Select
DIM arr(0 TO 9)
arr(0) = 5
GLBasic
Code (glbasic) Select
DIM arr[10]
arr[0] = 5
Title: New to GLbasic but used to older lsanguages
Post by: shaf on 2007-Nov-10
I did figure out how to use the array function the one i don't understand is how to read data

Basic Example
 For I = 1 to 10
  read rm$(i)
  next i
data 2,0,0,0,0,0,0

GLbasic example
 for I = 1 to 10
  ????? rm$(i)
  next
????? 2,0,0,0,0,0,0
Title: New to GLbasic but used to older lsanguages
Post by: bigsofty on 2007-Nov-10
Boom... one command...

Code (glbasic) Select
DIMDATA rm$[], 2,0,0,0,0,0,0GLBasic is not the same, it is superior in many ways.

Post any more conversions problem here, Ill try to help...
Title: New to GLbasic but used to older lsanguages
Post by: Kitty Hello on 2007-Nov-10
Right. The DIMDATA command allows to generate READ commands at _compile_ time. Very fast.
Title: New to GLbasic but used to older lsanguages
Post by: shaf on 2007-Nov-10
That was very helpful, I thingK i can nowe complete the program that I am  working on. It's a very simple Text adventure based on something i found on an old Compute! book.

I'll post it into showcase if anyone is interested.
Title: New to GLbasic but used to older lsanguages
Post by: bigsofty on 2007-Nov-10
Yeah, please do, I go a soft spot for the old interactive fiction...
Title: New to GLbasic but used to older lsanguages
Post by: Brice Manuel on 2007-Nov-11
QuoteGLBasic is not the same, it is superior in many ways.
Sorry, but how is this supposed to replace 100s or even 1000s of lines of traditional DATA?

I still miss traditional read/data/restore and that is the ONLY reason that I only use GLBasic for prototyping and not for final projects.
Title: New to GLbasic but used to older lsanguages
Post by: bigsofty on 2007-Nov-11
Quote from: Brice Manuel
QuoteGLBasic is not the same, it is superior in many ways.
Sorry, but how is this supposed to replace 100s or even 1000s of lines of traditional DATA?

I still miss traditional read/data/restore and that is the ONLY reason that I only use GLBasic for prototyping and not for final projects.
Really?

No program nowadays should have 100s or 1000s of data lines, if you require a similar functionality, then create your own binary file format/editor, write your 'data' to it and read it back into arrays when required. This is the way most modern languages handle large blocks of reusable static data.

GLBasic can easily fill and array from a file or write one back to it...

Code (glbasic) Select
OPENFILE() WRITEBYTE(), WRITEWORD(), WRITEWORD(). WRITEIEEE(), WRITESTR(), WRITELONG(), CLOSEFILE()

OPENFILE(), READBYTE(), READWORD(), READIEEE(), READSTR(), READLINE(), READLONG(), CLOSEFILE()
Quicker to compile, more compact, portable and you don't waste dynamic memory with two copies of the same data (1 in the array and one sitting as a reference).
Title: New to GLbasic but used to older lsanguages
Post by: Brice Manuel on 2007-Nov-11
I have always preferred not to store data externally ;)  For me, read/data/restore is part of what makes a BASIC a BASIC.

I enjoy using GLBasic for prototyping.  Extremely easy to quickly get an idea up and running.
Title: New to GLbasic but used to older lsanguages
Post by: bigsofty on 2007-Nov-11
I actually prefer Pascal... simple as basic and powerful as C++... everyone has their ideal language I suppose. ;)
Title: New to GLbasic but used to older lsanguages
Post by: shaf on 2007-Nov-12
I perferred the structuring of Pascal to Basic, COMAL had some interesting features and preferred Fortran for mathematics.
Title: New to GLbasic but used to older lsanguages
Post by: shaf on 2007-Nov-13
I think I understand how DIMDATA works but how would I use it for a 2 Dimensional array

What I've done currently is Split the array into multiple lines like so:

// --------------------------------- //
// Project: Tower of Mystery
// Start: Tuesday, November 06, 2007
// IDE Version: 5.062
//
// declare constants
//
// NR number of rooms
// NT number of things/items
// NP number of Pseudo-Objects (all other Objects)
// NO number of objects of all kinds
// NV number of verbs
//
// declare Flags
//
// CA Computer Active (in-game)
// CD Computer is Dead
// LI Character is logged into computer
// CP COPY of program is running on computer
// MF Computer Manual Found
// CF Coin Found
// WD Room description request flag
// RT Rats are Troublesome
// BT Bats are troublesome
// CT Time since computer was started
//
// General Variables
//
// C$  Command input
// C1$ First word of command
// C2$ Second Word of command
// C1  Verb token
// C2 Object token
// RM Room currently occupied
//
// Arrays
//
// AC[NR][6] Access Array
// VB$[NV] Verb array
// OB$[NO] Object Array
// RM$[NR] Room description array
// TD$[NT] Item description array
// VN[NV]  Verb token array
// TL[NT]  Item Location Array
// TF[NT]  Item Flag array (for can item be carried)
//
// Directions can be numeric or alpha
//
// 1 N  North
// 2 S  South
// 3 E  East
// 4 W  West
// 5 U  Up
// 6 D  Down
//
//
GLOBAL NR, NT, NP, NV, NO, RM, CT, CF, RT, CA, MF, CD, WD, LI, BT, VB$, OB$, RM$, TD$, VN, TL, TF
NR=14
NT=11
NP=11
NV=29
NO=NT+NP
DIM AC[NR][6]
DIM VB$[NV]
DIM OB$[NO]
DIM RM$[NR]
DIM TD$[NT]
DIM VN[NV]
DIM TL[NT]
DIM TF[NT]
// Initialization of Variables
RM= 1
CT= 0
CF= 0
RT= -1
CA= 0
MF= 0
CD= 0
WD= -1
LI= 0
BT= -1
FOR I = 1 TO NR
DIMDATA RM$[], "You are in the front of an old factory with a Clock tower." ,"You are at the bottom of a stairwell." ,"You are at the top of the basement steps." ,"You are in a damp cellar." ,"You are in a storeroom." ,"You are in the cafeteria." ,"You are at a landing on the stairs." ,"Around you is a manufacturing area." ,"You are at a landing on the third floor." ,"You are in the Computer room." ,"You are inside the Clock Tower." ,"You are at the top of the stairs." ,"You are in a long corridor going east." ,"You are at the east end of the corridor."
// DATA "You are in the front of an old factory with a Clock tower."
// DATA "You are at the bottom of a stairwell."
// DATA "You are at the top of the basement steps."
// DATA "You are in a damp cellar."
// DATA "You are in a storeroom."
// DATA "You are in the cafeteria."
// DATA "You are at a landing on the stairs."
// DATA "Around you is a manufacturing area."
// DATA "You are at a landing on the third floor."
// DATA "You are in the Computer room."
// DATA "You are inside the Clock Tower."
// DATA "You are at the top of the stairs."
// DATA "You are in a long corridor going east."
// DATA "You are at the east end of the corridor."
NEXT
FOR I = 1 TO NV
// READ VB$,VN;
DIMDATA VB$[], "N","S","E","W","U","D","GO","EAT","KICK","INSERT","DEPOSIT","TYPE","TAKE","GET","DROP","THROW","INVENTORY","I","INV","MOUNT","READ","FIGHT","KILL","START","POWER","OPEN","QUIT","LOOK","WIND","EXAMI","EXAMINE"
DIMDATA VN[], 1,2,3,4,5,6,7,8,9,10,10,11,12,12,13,13,14,14,14,15,16,17,17,18,18,19,20,21,22,23,23
// DATA N,1,S,2,E,3,W,4,U,5,D,6,"GO",7,"EAT",8,"KICK",9,"INSERT",10,"DEPOSIT",10,"TYPE",11
// DATA "TAKE",12,"GET",12,"DROP",13,"THROW",13,"INVENTORY",14,I,14,"INV",14,"MOUNT",15,"READ",16
// DATA "FIGHT",17,"KILL",17,"START",18,"POWER",18,"OPEN",19,"QUIT",20,"LOOK",21
// DATA "WIND",22,"EXAMI",23,"EXAMINE",23
 NEXT
FOR I = 1 TO NO;
// READ OB$;
DIMDATA OB$[], "RATS","TAPE","MACHINE","TERMINAL","COIN","CANDY","COMPUTER","BATS","DESK","MANUAL","CLOCK","ROAD","DIR","ADVEN","COPY","LOGOUT","NORTH","SOUTH","EAST","WEST","UP","DOWN"
// DATA "RATS","TAPE","MACHINE","TERMINAL","COIN","CANDY","COMPUTER","BATS","DESK","MANUAL","CLOCK","ROAD"
// DATA "DIR","ADVEN","COPY","LOGOUT","NORTH","SOUTH","EAST","WEST","UP","DOWN"
 NEXT
FOR I = 1 TO NT
// READ TD$,TL,TF
DIMDATA TD$[], "HUNGRY RATS", "COMPUTER TAPE", "VENDING MACHINE", "BROKEN-DOWN TERMINAL", "COIN", "CANDY BAR", "COMPUTER","BATS","DESK","COMPUTER MANUAL","ELABORATE CLOCKWORK"
DIMDATA TL[], 4,5,6,8,-1,-1,10,13,14,-1,11
DIMDATA FT[], 0,1,0,1,1,1,1,0,0,1,0
// DATA "HUNGRY RATS",4,0,"COMPUTER TAPE",5,1,"VENDING MACHINE",6,0
// DATA "BROKEN-DOWN TERMINAL",8,1,"COIN",-1,1,"CANDY BAR",-1,1,"COMPUTER",10,1
// DATA "BATS",13,0,"DESK",14,0,"COMPUTER MANUAL",-1,1,"ELABORATE CLOCKWORK",11,0
 NEXT
FOR I = 1 TO NR
// READ AC[1],AC[2],AC[3],AC[4],AC[5],AC[6]
// DIMDATA AC[NR][6], 2,0,0,0,0,0,3,1,0,0,7,0,0,2,0,0,0,4,0,0,5,0,3,0,0,0,0,4,0,0,0,0,7,0,0,0,0,0,10,0,12,7,0,0,0,9,0,0,0,12,0,0,0,0,11,0,13,0,0,9,0,0,14,12,0,0,0,0,0,13,0,0
DIMDATA AC[], 2,3,0,0,0,0,0,0,0,0,0,11,0,0
DIMDATA AC[], 0,1,2,0,0,0,0,0,0,0,12,0,0,0
DIMDATA AC[], 0,0,0,5,0,7,8,0,10,0,0,13,14,0
DIMDATA AC[], 0,0,0,0,4,0,6,7,0,9,0,0,12,13
DIMDATA AC[], 0,7,0,3,0,0,9,0,12.0,0,0,0,0
DIMDATA AC[], 0,0,4,0,0,0,2,0,7,0,0,9,0,0
// DATA 2,0,0,0,0,0
// DATA 3,1,0,0,7,0
// DATA 0,2,0,0,0,4
// DATA 0,0,5,0,3,0
// DATA 0,0,0,4,0,0
// DATA 0,0,7,0,0,0
// DATA 0,0,8,6,9,2
// DATA 0,0,0,7,0,0
// DATA 0,0,10,0,12,7
// DATA 0,0,0,9,0,0
// DATA 0,12,0,0,0,0
// DATA 11,0,13,0,0,9
// DATA 0,0,14,12,0,0
// DATA 0,0,0,13,0,0
 NEXT
Title: New to GLbasic but used to older lsanguages
Post by: bigsofty on 2007-Nov-14
Not too bad at all... :)
Title: New to GLbasic but used to older lsanguages
Post by: shaf on 2007-Nov-16
I think I'm going to write a Help file as soon as I get more familiar with GLBasic -comparing GLBasic to Basic.

Obviously arrays are handled slightly differently, as well as data calls.
I think I can Replace the Basic LEFT$ & RIGHT$ commands with MID$
Command separators are different Basic uses : and GLBasic uses ;

Is there an way to do this in GLBasic

ON C1 GOTO 1000,1000,1000,1000,1000,1100,1200,1300,1400

I'm thinking
IF C1 GOTO 1000, 1000 ... but GOTO only allows one call. Should I turn C1 into an array and do the following
For N = 1 to 9
IF C1[1} goto 1000
IF C1[2} goto 1000
IF C1[3} goto 1000
IF C1[4} goto 1000
IF C1[5} goto 1000
IF C1[6} goto 1100
IF C1[7} goto 1200
IF C1[8} goto 1300
IF C1[9} goto 1400
next
Title: New to GLbasic but used to older lsanguages
Post by: bigsofty on 2007-Nov-16
You dont need to turn N into an array or put it into a loop, the SELECT statement will select your correct value for c1 and ignore the other lines, hence its a lot quicker... so...

Code (glbasic) Select
SELECT c1
  CASE 0 GOTO 100
  CASE 1 GOTO 100
  CASE 2 GOTO 200
  CASE 3 GOTO 200
  CASE 4 GOTO 500
ENDSELECT
Not used in this example but the SELECT statement has extra commands for handling certain situations...

Code (glbasic) Select
CASE 6 TO 99 GOTO 200 // if C1 was between 6 and 99or

Code (glbasic) Select
CASE >100 GOTO 100 // if C1 was greater then 100or

Code (glbasic) Select
DEFAULT GOTO 300 // If C1 has a value that SELECT does not handle (eg... -10), same ELSE in an IF
Title: New to GLbasic but used to older lsanguages
Post by: Schranz0r on 2007-Nov-16
sorry, but thats a bad coding style!
I'll never use GOTO !
That looks like spagetticode, if you know what it is?!

GOTO is my last choose...
Title: New to GLbasic but used to older lsanguages
Post by: BumbleBee on 2007-Nov-16
GOTO is unpopular and still from the Basic-Stone Age.;) I usually don't use GOTO with the exception of

Code (glbasic) Select
 IF hungry=TRUE THEN GOTO McDonalds;)

Cheers
Title: New to GLbasic but used to older lsanguages
Post by: bigsofty on 2007-Nov-16
I'm not commenting on coding style, this is just a question of syntax.

For the record, I don't use GOTO either, but Shaf's original code is so old, he may have no option if he wishes to avoid a major rewrite.
Title: New to GLbasic but used to older lsanguages
Post by: shaf on 2007-Nov-17
Bigsofty is correct,
Ordinarily I wouldn't use goto but since I'm rewriting some very old Basic Programs (1983) unless I totally Restructure and rewrite the Program it's the only way to do it. Unfortunately I didn't save my Programming Flowcharts. If you think that's bad you should see some of my Assembler Coding I used to program ML for 8008, 1802, 6502 and 68000.

Shaf
Title: New to GLbasic but used to older lsanguages
Post by: shaf on 2007-Nov-17
BumbleBee

Although I have Children If Hungery & MCDonalds can't be used in the same statement.
;}

Shaf
Title: New to GLbasic but used to older lsanguages
Post by: shaf on 2007-Nov-20
Bigsofty,
I tried using the Select Method and got a syntax error immediately in the debugger.
CASE 0 GOTO Line100

OK I found the error GOTO doesn't work it preceeded by THEN
So CASE 0 THEN GOTO Line100 works
Title: New to GLbasic but used to older lsanguages
Post by: Schranz0r on 2007-Nov-20
Or:

Code (glbasic) Select
SELECT Var
    CASE 0
        GOTO Line100
    CASE 1
        GOTO Line101
ENDSELECT
Title: New to GLbasic but used to older lsanguages
Post by: Kitty Hello on 2007-Nov-20
CASE xxxx ; DoSomething()
The CASE line must be terminated by a newline (or ; charakter)
Title: New to GLbasic but used to older lsanguages
Post by: Kitty Hello on 2008-Mar-11
DATA is now included.
Title: New to GLbasic but used to older lsanguages
Post by: shaf on 2008-Mar-16
GernoT,

Thanks this will be a huge help to people trying to convert old code into GLBasic. Now where is my old Star Trek program  done on the C64.

Thanks

Shaf