japanese 2020-01-10 09:41
(move main char)
Is this collect?
was8bit 2020-01-10 10:49
(move main char)
was8bit 2020-01-10 11:00 (Edited)
(Use of parenthesis....)
IF you do not need to give the SUB information (usually because it is using GLOBAL defined variables) then the CALL SUBNAME and SUB SUBNAME should be plain, without parenthesis...
BUT, if you need to include either variables or raw values like
CALL MOVE_PLAYER (PLAYERX,PLAYERY,-1,0)
Then you just MUST use parenthesis and the number of data must match
SO, if the SUB is defined with parenethesis needing 4 data, the CALL SUB must also use parenthesis and must input 4 data
The CALL SUB can use any variable used by the main program, or raw data like 23 or "JOE"... but the defined SUB SUBNAME ..the variable types must match the inputed data, like NumberIn or StringIn$....
was8bit 2020-01-10 11:07 (Edited)
(Use of variables and data... may or may not change...)
..... notice that the names of the variables dont have to be the same... all variables used inside a sub (should they acidentally be the same as other variables in the main program) will NOT interfer with variables in the same program... all variables inside a SUB are private and secret to inside the SUB only..
So, for example, if PLAYERX is inputed as 5, then inside the sub, inputed X is now 5... but the SUB changes X, it become X=5-1=4.... since the variable PLAYERX was used in the CALL, and since the matching X variable has been changed, the SUB DOES change PLAYERX to match the new value, and PLAYERX in the main program is updated to be 4
If your main program also used X,Y... the inside SUB x,y will not change any X,Y used in your main program
was8bit 2020-01-10 11:13 (Edited)
(How to reuse SUB with different variables....)
If your enemies move identically to your player, you can actually reuse the SUB with different inputed variables... like...
Then reuse this sub for different things, like
IF RIGHT(0)THEN CALL MOVETANK(PLAYERX,PLAYERY,-1,0)
IF RND(10)=0 THEN CALL MOVETANK(ENEMYX,ENEMYY,-1,0)
Both calls input their own variables,,the same sub receives the data, processes the data, and returns data based on what variables where used in the CALL
So when PLAYERX,PLAYERY is used, these variables get updated
When ENEMYX,ENEMYY is used, these variables get updated
was8bit 2020-01-10 11:28 (Edited)
(Comparing GOSUB with SUB....)
When you use GOSUB LABELNAME then LABELNAME: RETURN then all variables used are the same variables, it is really no different than if you just typed code in directly.. the only use for GOSUB /RETURN is if you are typing in identical code several times, and to save typing the identical code many times you just type it once inside a LABEL: RETURN and use GOSUB LABEL
SUB is much more powerful... you can
1) reuse the same code to update different inputed variables
2) not worry that variables used inside your SUB will accidentally change an identical variables used elsewhere in your program
3) all variables used inside a SUB are temporary and once a SUB has finished it discards all values used inside the SUB (nothing inside a SUB is remembered)
IF you need a variable accessable both inside a SUB and outside a SUB, .... OR... you need a variable special to a SUB to not loose its value from one CALL to another CALL (like a setting) then you must use GLOBAL variables, defined at the beginning of your program...
was8bit 2020-01-10 11:38
was8bit 2020-01-10 11:45
... I know this is a lot of information, and I know I can ramble... so, please ask any questions to clarify anything :)
japanese 2020-01-10 13:35
Anyway, I will try it :)
was8bit 2020-01-10 15:23
Cool :) happy to help :)