News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_AMSDOS

BASIC Platform Demostration

Started by AMSDOS, 02:56, 02 May 15

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

AMSDOS

I've come up with a simple demonstration for a platform game:




10 MODE 0:DIM board(8,9)
20 GOSUB 1000 : GOSUB 1210
30 WHILE INKEY(18)=-1
40 GOSUB 1310
50 WEND:MODE 2:END
1000 RESTORE 1100
1010 FOR y=1 TO 8
1020 FOR x=1 TO 9
1030 READ b
1040 board(y,x)=b
1050 LOCATE x,y
1060 IF board(y,x)=1 THEN PRINT CHR$(143);
1070 NEXT x
1080 NEXT y
1090 RETURN
1100 DATA 0,0,0,0,0,0,0,0,0
1110 DATA 0,0,0,0,0,0,0,0,0
1120 DATA 0,0,0,0,0,0,0,0,0
1130 DATA 1,1,1,1,0,0,0,0,0
1140 DATA 0,0,0,0,1,1,0,0,0
1150 DATA 0,0,0,0,0,0,0,0,0
1160 DATA 0,0,0,0,0,0,1,1,0
1170 DATA 1,1,1,1,1,1,0,0,0
1200 ' Initialise Position for Man
1210 x=1: y=1
1220 RETURN
1300 ' Print & Move Man also test Array
1310 LOCATE x,y:PRINT CHR$(249);
1320 IF board(y+1,x)<>1 THEN oldy=y:y=y+1:LOCATE x,oldy:PRINT" ";
1330 IF INKEY(1)<>-1 AND x<8 AND board(y,x+1)<>1 THEN oldx=x:x=x+1:LOCATE oldx,y:PRINT" ";
1340 IF INKEY(8)<>-1 AND x>1 AND board(y,x-1)<>1 THEN oldx=x:x=x-1:LOCATE oldx,y:PRINT" ";
1350 IF INKEY(0)<>-1 AND board(y-1,x)<>1 THEN oldy=y:y=y-1:LOCATE x,oldy:PRINT" ";
1360 RETURN



For the man I'm using Left/Right & the Up Arrow and everything was working until I got to the Jumping Sequence and am having problems because I can't Jump up - Left, Jump up - Right for example and am assuming I need a subroutine to determine where to move.


Help?  :D
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

AMSDOS

#1
I've addressed the issue of the first version:




10 MODE 0:DIM board%(9,20)
20 GOSUB 1000 : GOSUB 1210
30 WHILE INKEY(18)=-1
40 GOSUB 1310
50 WEND:WHILE INKEY$<>"":WEND:MODE 2:END
1000 RESTORE 1100
1010 FOR y%=1 TO 9
1020 FOR x%=1 TO 20
1030 READ b%
1040 board%(y%,x%)=b%
1050 LOCATE x%,y%
1060 IF board%(y%,x%)=1 THEN PRINT CHR$(143);
1070 NEXT x%
1080 NEXT y%
1090 RETURN
1100 DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0
1110 DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0
1120 DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0
1130 DATA 1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0
1140 DATA 0,0,0,0,1,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0
1150 DATA 0,0,0,0,0,0,1,1,1,0,0,1,1,0,0,0,0,0,0,0
1160 DATA 0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0
1170 DATA 1,1,1,1,1,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0
1180 DATA 0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0
1200 ' Initialise Position for Man
1210 x%=1: y%=1
1220 RETURN
1300 ' Print & Move Man also test Array
1310 LOCATE x%,y%:PRINT CHR$(249);:CALL &BD19:CALL &BD19
1320 IF board%(y%+1,x%)<>1 THEN oldy%=y%:y%=y%+1:LOCATE x%,oldy%:PRINT" ";
1330 IF INKEY(1)<>-1 AND x%<20 AND board%(y%,x%+1)<>1 THEN oldx%=x%:x%=x%+1:LOCATE oldx%,y%:PRINT" ";
1340 IF INKEY(8)<>-1 AND x%>1 AND board%(y%,x%-1)<>1 THEN oldx%=x%:x%=x%-1:LOCATE oldx%,y%:PRINT" ";
1350 IF INKEY(0)<>-1 AND y%>1 AND board%(y%-1,x%)<>1 THEN oldy%=y%:y%=y%-1:GOSUB 2010
1360 ' IF board%(y%+1,x%)<>1 THEN oldy%=y%:y%=y%+1:LOCATE x%,oldy%:PRINT" ";
1370 RETURN
2000 ' Jump Left or Right
2010 IF INKEY(8)<>-1 AND x%>1 AND board%(y%,x%-1)<>1 THEN oldx%=x%:x%=x%-1:LOCATE oldx%,oldy%:PRINT" ";:RETURN
2020 IF INKEY(1)<>-1 AND x%<20 AND board%(y%,x%+1)<>1 THEN oldx%=x%:x%=x%+1:LOCATE oldx%,oldy%:PRINT" ";:RETURN
2030 LOCATE x%,oldy%:PRINT" ";
2040 RETURN



But now it feels like I have a Superbeing who jump anywhere, when they reach top areas on the screen. I think I know how to sort that out, obviously what I've done here is when the Up key is detected it then checks if Left or Right key is being pressed, but it really needs to have the person jump up and fall down - even when the Up Arrow is being pressed.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

alex76gr

This is so cool man! So cool! :o
Excellent job.
I still believe that i got my myopia from the green GT-65 monitor, but i can't prove it! :)

ronaldo

Quote from: AMSDOS on 07:40, 02 May 15
But now it feels like I have a Superbeing who jump anywhere, when they reach top areas on the screen. I think I know how to sort that out, obviously what I've done here is when the Up key is detected it then checks if Left or Right key is being pressed, but it really needs to have the person jump up and fall down - even when the Up Arrow is being pressed.

One possible solution is creating a status variable. For instance, say that status=0 means staying at the floor, status>0 means that you have jumped N cells already and status<0 means -N cells already falled (and falling). You can use it to control the vertical movement of the character, and preventing user from jumping when falling. You just have to code something like this (S%=status):

IF S%>-1 AND S%<3 AND INKEY(0)<>-1 AND y%>1 AND board%(y%-1,x%)<>1 THEN oldy%=y%:y%=y%-1:GOSUB 2010 ELSE IF S%>0 THEN S%=-S%


You let the user jump more or less and, at the same time you control the change from jumping to falling, preventing the user to jumping again when in falling status. You can construct lots of similar solutions to this.

AMSDOS

Quote from: ronaldo on 09:43, 04 May 15
One possible solution is creating a status variable. For instance, say that status=0 means staying at the floor, status>0 means that you have jumped N cells already and status<0 means -N cells already falled (and falling). You can use it to control the vertical movement of the character, and preventing user from jumping when falling. You just have to code something like this (S%=status):

IF S%>-1 AND S%<3 AND INKEY(0)<>-1 AND y%>1 AND board%(y%-1,x%)<>1 THEN oldy%=y%:y%=y%-1:GOSUB 2010 ELSE IF S%>0 THEN S%=-S%


You let the user jump more or less and, at the same time you control the change from jumping to falling, preventing the user to jumping again when in falling status. You can construct lots of similar solutions to this.


Yes that's one of the possibilities I was considering and perhaps the easier approach. The other way I thought about do it was to have a means for the person to come back to earth at the end of the jumping sequence kind of simulating what Line 1320 is doing, but is more coding.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

ronaldo

Technically, it depends on your goal. If you want it to be just for this single character, the status approach is good. If you want to apply it to a lot of entities, I would consider redesigning it to make an entity manager code that takes into account forces and collisions, plus user keyboard input.

However, it usually is better to start easy and grow as required :)

AMSDOS

Quote from: ronaldo on 12:06, 04 May 15
Technically, it depends on your goal. If you want it to be just for this single character, the status approach is good. If you want to apply it to a lot of entities, I would consider redesigning it to make an entity manager code that takes into account forces and collisions, plus user keyboard input.

However, it usually is better to start easy and grow as required :)


At the moment I was only playing with the idea of creating some platforms and having the person land on them, but writing it in a more structured manner, which works quite well. There is a BASIC game where a person has to dodge a series of balls, a little bit like Home Runner, but a little bit easier, though the programming of it I thought could be improved (as the author of it wrote).
I think this way of using Data statements to define the screen seems to have more advantage - different objects can have different values that depend on how your character interacts.


Will just need to get on my other computer and test some possibilities with the jumping sequence, kind of wondering that I might need to separate Printing the man and having the character inputs separately?
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

AMSDOS


Okay, so I've rearranged the array so now there's a couple of distinct platforms, but I'm having problems writing a suitable jumping routine. What I had in mind was something where your character can jump to those platforms from below.


I had a go at trying to implement a status variable (which I kind of have down there), but the trouble is arising when I want to jump the character more than one character, I had variations of this and in one case I had the person jumping a few squares, but had trouble with the animating sequence.


The other little danger is there needs to be a way to check if the y% goes past 1 to prevent an error. Would be more problematic if character is near the top of the screen.



10 MODE 0:DIM board%(9,20)
20 GOSUB 1000 : GOSUB 1210
30 WHILE INKEY(18)=-1
31 GOSUB 1410
40 GOSUB 1310
50 WEND:WHILE INKEY$<>"":WEND:MODE 2:END
1000 RESTORE 1100
1010 FOR y%=1 TO 9
1020 FOR x%=1 TO 20
1030 READ b%
1040 board%(y%,x%)=b%
1050 LOCATE x%,y%
1060 IF board%(y%,x%)=1 THEN PRINT CHR$(143);
1070 NEXT x%
1080 NEXT y%
1090 RETURN
1100 DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
1110 DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
1120 DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
1130 DATA 1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0
1140 DATA 0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0
1150 DATA 0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0
1160 DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0
1170 DATA 0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0
1180 DATA 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0
1200 ' Initialise Position for Man
1210 x%=1: y%=1
1220 RETURN
1300 ' Move Man & test Array
1310 ' LOCATE x%,y%:PRINT CHR$(249);:CALL &BD19:CALL &BD19
1320 IF board%(y%+1,x%)<>1 THEN oldy%=y%:y%=y%+1:LOCATE x%,oldy%:PRINT" ";
1330 IF INKEY(1)<>-1 AND x%<19 AND board%(y%,x%+1)<>1 THEN oldx%=x%:x%=x%+1:LOCATE oldx%,y%:PRINT" ";
1340 IF INKEY(8)<>-1 AND x%>1 AND board%(y%,x%-1)<>1 THEN oldx%=x%:x%=x%-1:LOCATE oldx%,y%:PRINT" ";
1350 IF INKEY(0)<>-1 AND y%>1 AND board%(y%-1,x%)<>1 THEN s%=1:oldx%=x%:oldy%=y%:y%=y%-1:GOSUB 1410:GOSUB 1510:GOSUB 2010
1360 IF s%=1 AND board%(y%+1,x%)<>1 THEN s%=0:oldy%=y%:y%=y%+1:LOCATE x%,oldy%:PRINT" ";
1370 RETURN
1400 ' Print Man
1410 LOCATE x%,y%:PRINT CHR$(249);:CALL &BD19:CALL &BD19
1420 RETURN
1500 ' Delete Man
1510 LOCATE oldx%,y%:PRINT" ";
1520 RETURN
2000 ' Jump Left or Right
2010 IF INKEY(8)<>-1 AND x%>1 AND board%(y%,x%-1)<>1 THEN oldx%=x%:x%=x%-1:LOCATE oldx%,oldy%:PRINT" ";:RETURN
2020 IF INKEY(1)<>-1 AND x%<19 AND board%(y%,x%+1)<>1 THEN oldx%=x%:x%=x%+1:LOCATE oldx%,oldy%:PRINT" ";:RETURN
2030 LOCATE x%,oldy%:PRINT" ";:s%=0
2040 RETURN
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

AMSDOS

At the moment, I've come up with a Jumping Simulator, just to get the gist of it:




10 x%=10: y%=25: p%=0
20 MODE 1
30 WHILE INKEY$<>"":WEND
40 WHILE INKEY(18)=-1
50  GOSUB 1210
60  IF INKEY(0)<>-1 THEN GOSUB 1010
70 WEND
80 WHILE INKEY$<>"":WEND
90 MODE 2:END
1000 ' Jump Routine
1010 p%=0
1020 WHILE p%<4
1030  oldy%=y% : y%=y%-1
1040  GOSUB 1210
1050  GOSUB 1310
1060  p%=p%+1
1070 WEND
1080 WHILE p%>0
1090  oldy%=y% : y%=y%+1
1100  GOSUB 1210
1110  GOSUB 1310
1120  p%=p%-1
1130 WEND
1140 RETURN
1200 ' Print Man
1210 LOCATE x%,y% : PRINT CHR$(249);
1220 RETURN
1300 ' Delete Man
1310 LOCATE x%,oldy% : PRINT" ";
1320 RETURN



All I need to do now is jam the thing in so the person can move left/right with this. The good news is this routine will return the character to where they were, though I don't think it tests the top of the screen.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

ronaldo

#9
I've taken the license to create a modified version of your code to show you what I meant with respect to the status variable. Status variable should control the flow of your program, impeding jump to be performed when you are already jumping, and when you are falling. Gravity should not be applied when you are jumping also.

I've also made some modifications following this logic: Drawing should be done only once, in the drawing routine, and not in many places in the code. The rest of the code takes responsibility for updating logic only. Also, control of the jump has been moved to a subroutine, to make use of it whenever needed. When drawing, it is preferably to wait for VSYNC first, then quickly draw.

You can improve drawing and processing a lot applying several optimization tecniques. Namely:

       
  • Single string drawing
  • Using default integers
  • Single character variable names
  • Reducing lines
  • IF-THEN-IF condition checking instead of logic operators
  • Removing comments from code
  • Removing unnecesary spaces.
If have only applied some of them for illustration purposes, and for not making the code more complex.

Please, let me know if this is what you wanted and if you have any doubt about my proposal. Hope this helps.


10 MODE 0:DIM board%(9,20)
20 GOSUB 1000 : GOSUB 1210
30 WHILE INKEY(18)=-1
31 GOSUB 1410
40 GOSUB 1310
50 WEND:WHILE INKEY$<>"":WEND:MODE 2:END
1000 RESTORE 1100
1010 FOR y%=1 TO 9
1020 FOR x%=1 TO 20
1030 READ b%
1040 board%(y%,x%)=b%
1050 LOCATE x%,y%
1060 IF board%(y%,x%)=1 THEN PRINT CHR$(143);
1070 NEXT x%
1080 NEXT y%
1090 RETURN
1100 DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
1110 DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
1120 DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
1130 DATA 1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0
1140 DATA 0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0
1150 DATA 0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0
1160 DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0
1170 DATA 0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0
1180 DATA 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0
1200 ' Initialise Position for Man
1210 oldx%=1:oldy%=1:x%=1: y%=1
1220 RETURN
1300 ' Move Man & test Array
1310 ' LOCATE x%,y%:PRINT CHR$(249);:CALL &BD19:CALL &BD19
1320 IF s%>0 THEN GOSUB 3000:GOTO 1350
' Control gravity
1330 IF board%(y%+1,x%)=0 THEN y%=y%+1:GOTO 1350
' Jumping only allowed when not falling
1340 IF NOT INKEY(0) THEN IF y%>1 AND board%(y%-1,x%)=0 THEN GOSUB 3000
' User keyboard input
1350 IF NOT INKEY(1) THEN IF x%<19 AND board%(y%,x%+1)=0 THEN x%=x%+1
1360 IF NOT INKEY(8) THEN IF x%>1 AND board%(y%,x%-1)=0 THEN x%=x%-1
1370 RETURN
1400 ' Print Man
' Only redraw if there is movement
1410 IF oldx%=x% AND oldy%=y% THEN RETURN
' Wait for VSYNC
1420 CALL &BD19
' Redraw
1430 LOCATE oldx%,oldy%:PRINT " ";
1440 LOCATE x%,y%:PRINT CHR$(249);
' Update coordinates
1450 oldx%=x%:oldy%=y%
1460 RETURN
'
' Control Jumping status
'
3000 s%=s%+1
' Check for jump-status ending conditions (max jump, collision, screen top)
3010 IF s%>3 OR y%=1 OR board%(y%-1,x%)=1 THEN s%=0:RETURN
3020 y%=y%-1
3030 RETURN

AMSDOS

Quote from: ronaldo on 19:17, 06 May 15
I've taken the license to create a modified version of your code to show you what I meant with respect to the status variable. Status variable should control the flow of your program, impeding jump to be performed when you are already jumping, and when you are falling. Gravity should not be applied when you are jumping also.

I've also made some modifications following this logic: Drawing should be done only once, in the drawing routine, and not in many places in the code. The rest of the code takes responsibility for updating logic only. Also, control of the jump has been moved to a subroutine, to make use of it whenever needed. When drawing, it is preferably to wait for VSYNC first, then quickly draw.

You can improve drawing and processing a lot applying several optimization tecniques. Namely:

       
  • Single string drawing
  • Using default integers
  • Single character variable names
  • Reducing lines
  • IF-THEN-IF condition checking instead of logic operators
  • Removing comments from code
  • Removing unnecesary spaces.
If have only applied some of them for illustration purposes, and for not making the code more complex.

Please, let me know if this is what you wanted and if you have any doubt about my proposal. Hope this helps.


This is great.


I was tinkering around with this - namely the GOTOs, though there playing a critical role for this routine. The approach I was trying to do with the WHILE jump routine is going to require code for moving Left & Right within it, I tried changing it around a little by making the controls it's own routine (similar to your approach), but had heaps of problems, I think because of the nature of how I'm drawing/deleting the character use of LOCATE varies.


I was trying to write it structurally so I could port it to Pascal. I have got GOTO available in it and your routine seems to be using one Procedure which is fortunate.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

ronaldo

Quote from: AMSDOS
I was tinkering around with this - namely the GOTOs, though there playing a critical role for this routine.

GOTOs used heres are not "propper GOTOs". You can see them as IF-THEN-ELSE branching. As Locomotive BASIC hasn't got ability for multi-line IFs, you have to simulate them with GOTOs. However, you can get rid of the GOTOs in this code, gaining performance but loosing readability. Some comments can make this structure clearer:


' IF s%>0
    1320 IF s%>0 THEN GOSUB 3000:GOTO 1350
' ELSE IF board%(y%+1,x%)=0
    1330 IF board%(y%+1,x%)=0 THEN y%=y%+1:GOTO 1350
' ELSE
    1340 IF NOT INKEY(0) THEN IF y%>1 AND board%(y%-1,x%)=0 THEN GOSUB 3000
' ENDIF


Optimizing it for speed, we can rewrite everything as:


1310IF s%>0THEN GOSUB 3000ELSE IF board%(y%+1,x%)=0THEN y%=y%+1ELSE IF NOT INKEY(0)THEN IF y%>1AND board%(y%-1,x%)=0THEN GOSUB 3000


Getting rid of unneeded spaces and placing everything in one line gives you much better performance in Locomotive BASIC. To get even more in this line, you should rename board% to b% and use DEFINT A-Z and get rid of '%'s. That will save you some memory and CPU cycles.You also can improve performance changing your 1's into -1's in the collision matrix and then changing previous line into:


1310IF s>0THEN GOSUB 3000ELSE IF b(y+1,x)THEN y=y+1ELSE IF NOT INKEY(0)THEN IF y>1AND b(y-1,x)THEN GOSUB 3000


Doing this, you loose readability but you win memory and performance.

AMSDOS

Thanks I should of realised.


Unfortunately I liked to use excessive amounts of code to do the job at the same time having it look nice and readable (with unnecessarily spaces). Was under the impression that a "%" is just as good as a DEFINT a-z, though better because it's only using the variables you need rather than defining the whole table as that.


Guess this wouldn't be an issue in a BASIC Compiler?
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

ronaldo

Quote from: AMSDOS on 23:01, 08 May 15
Unfortunately I liked to use excessive amounts of code to do the job at the same time having it look nice and readable (with unnecessarily spaces). Was under the impression that a "%" is just as good as a DEFINT a-z, though better because it's only using the variables you need rather than defining the whole table as that.

Guess this wouldn't be an issue in a BASIC Compiler?
Unnecesary spaces shouldn't be an issue when compiling. However, I wouldn't risk my neck. Best you can do is running some tests to be sure. You may have FaBaCom for instance, do several versions of your code, compile them and measure results. I wrote a post on FaBaCom monts ago (In spanish). It's an average opcion for compiling Locomotive BASIC and win some performance.

Definitely, using % in BASIC slows down performance. Locomotive BASIC parser goes character by character when interpreting anything that is not a BASIC token. Moreover, when speaking of symbol names (variables) this is even worse, because it has to do a search in the symbol table every time it finds a variable in the code. Because of this, it is always preferible to use short variable names (1 character where possible) and get rid of any unnecesary character. This is the reason why DEFINT is much better. Also, you have to take into account that variable names a and a% are different even when you use DEFINT.

AMSDOS

Quote from: ronaldo on 00:12, 09 May 15
Unnecesary spaces shouldn't be an issue when compiling. However, I wouldn't risk my neck. Best you can do is running some tests to be sure. You may have FaBaCom for instance, do several versions of your code, compile them and measure results. I wrote a post on FaBaCom monts ago (In spanish). It's an average opcion for compiling Locomotive BASIC and win some performance.

I've only used the Windows program CPC BASIC 3 which handles Integers as a Default variable type, though handles decimal through RSX routines. Output is very well done according to @Trebmint, Quicker or equal to any C Compiler on the Z80. I have noticed that this code is faster than my Hisoft Pascal 4T code, though todays compilers are going to beat something from 1984.  ;D  CPC BASIC 3 Vs. Assembly stacks up well, my Assembly using Firmware appears the same with Assembly being able to generate smaller code.

QuoteDefinitely, using % in BASIC slows down performance. Locomotive BASIC parser goes character by character when interpreting anything that is not a BASIC token. Moreover, when speaking of symbol names (variables) this is even worse, because it has to do a search in the symbol table every time it finds a variable in the code. Because of this, it is always preferible to use short variable names (1 character where possible) and get rid of any unnecesary character. This is the reason why DEFINT is much better. Also, you have to take into account that variable names a and a% are different even when you use DEFINT.


Okay.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Powered by SMFPacks Menu Editor Mod