Jump to content
IGNORED

Need some XB help


Sinphaltimus

Recommended Posts

I'm asking but I'm going to go try anyway to see what happens...

 

Can you gosub out of a subprogram? I'm guessing yes of course, as long as you "return" to it.

 

There nothing to say against that. You could have two subprograms with a common routine both are sharing. You could then either pack that into another subroutine that you can CALL, or you GOSUB there.

Link to comment
Share on other sites

The difference between calls in Extended Basic and C++:

 

#include <stdio.h>

void subroutine(int first, int& second);

int main() {
   int myvar = 42;
   int anotherone = 74;
   subroutine(myvar, anotherone);
   printf("Values are %d and %d\n", myvar, anotherone);
}
 
void subroutine(int first, int& second) {
    first = 13;
    second = 31;
}
 
$ g++ testref.cpp -o testref
$./testref
Values are 42 and 31

You see that in C++ the subroutine determines whether we have a call-by-value or a call-by-reference.

Edited by mizapf
Link to comment
Share on other sites

On TIdBiT..... Just do this: :D

 

 

 

 
 
Code In:
 
 
 
//Tidbit source code for a toggle program
//This program asks for user input, then toggles the screen
//between blank and stars.
 
 
 
     CALL CLEAR:: CALL SCREEN(9) :: X=0
     GOSUB MESSAGE
 
     
// START is the main loop.  we will be branching to other subs from here, but we will always returns
// and we will always branch out.  We can add as many comments as we want to anywhere we want
// and they will not be stored in memory, especially because when we translate the code, it strips
// all of it out and allows us to copy and paste only line numbers.
START:
     GOSUB KEYCHECK
     IF X=1 THEN GOSUB STARS
     IF X=2 THEN GOSUB BLANK
     GOSUB MESSAGE
     GOTO START
     
     
// "STARS" fills the screen with stars
STARS:
     FOR I=1 TO 24
     CALL HCHAR(I,1,42,32)
     NEXT I
     RETURN
     
     
// "BLANK" blanks the screen out
BLANK:
     FOR I=1 TO 24
     CALL HCHAR(I,1,32,32)
     NEXT I
     RETURN
     
// "MESSAGE" types the message "CLICK A BUTTON"
MESSAGE:
     DISPLAY AT(24,5):"CLICK A BUTTON";
     RETURN
     
     
// "KEYCHECK" checks for any keypress, then returns back to the main loop to allow program
// to continue.  If no key is pressed, it holds here.
KEYCHECK:
     CALL KEY(0,K,S) :: IF S<1 THEN KEYCHECK
     X=X+1 :: IF X>2 THEN X=1
     RETURN
 
 
 
 
Code Out:
 
 

100 CALL CLEAR:: CALL SCREEN(9) :: X=0
110 GOSUB 250
120 GOSUB 270
130 IF X=1 THEN GOSUB 170
140 IF X=2 THEN GOSUB 210
150 GOSUB 250
160 GOTO 120
170 FOR I=1 TO 24
180 CALL HCHAR(I,1,42,32)
190 NEXT I
200 RETURN
210 FOR I=1 TO 24
220 CALL HCHAR(I,1,32,32)
230 NEXT I
240 RETURN
250 DISPLAY AT(24,5):"CLICK A BUTTON";
260 RETURN
270 CALL KEY(0,K,S) :: IF S<1 THEN 270
280 X=X+1 :: IF X>2 THEN X=1
290 RETURN

 
 
  • Like 2
Link to comment
Share on other sites

 

That would defeat the purpose of a subroutine/function. If you could do that, it would defeat its portability.

 

...lee

 

Yes I get that. And portability is wonderful. I'm kind of working backwards. My ZOMBI game is already written. Mostly. So I want to get it done before I have to rewrite. It takes a real long time to load so with subprograms being left out of the pre-scan, I want to at least take advantage of that. I don't expect any of them to be portable outside of Zombi.

 

For me to do a complete rewrite, the way I work, I'd have to print it out, literally use scissors and tape and pencil notes all over before I could attempt to rewrite it in text. And I'm not motivated more to do that than I am to get the game finished.Once the game is done, I won't be able to sleep until it is rewritten.

 

And at that point I would kill any gosubs from subs and really tighten it all up nicely.

 

I just started a little thing and am running with it but the performance and load times are killing the fun.

Edited by Sinphaltimus
Link to comment
Share on other sites

The difference between calls in Extended Basic and C++:

 

#include <stdio.h>

void subroutine(int first, int& second);

int main() {
   int myvar = 42;
   int anotherone = 74;
   subroutine(myvar, anotherone);
   printf("Values are %d and %d\n", myvar, anotherone);
}
 
void subroutine(int first, int& second) {
    first = 13;
    second = 31;
}
 
$ g++ testref.cpp -o testref
$./testref
Values are 42 and 31

You see that in C++ the subroutine determines whether we have a call-by-value or a call-by-reference.

 

 

Yeah, I don't know C so looking at your C code is foreign to me. I get the structure and kind of what's going on but I still can't write C to get a result out of tidbit if that's what is required.

Link to comment
Share on other sites

 

On TIdBiT..... Just do this: :D

 
 
Code In:
 
 
 
//Tidbit source code for a toggle program
//This program asks for user input, then toggles the screen
//between blank and stars.
 
 
 
     CALL CLEAR:: CALL SCREEN(9) :: X=0
     GOSUB MESSAGE
 
     
// START is the main loop.  we will be branching to other subs from here, but we will always returns
// and we will always branch out.  We can add as many comments as we want to anywhere we want
// and they will not be stored in memory, especially because when we translate the code, it strips
// all of it out and allows us to copy and paste only line numbers.
START:
     GOSUB KEYCHECK
     IF X=1 THEN GOSUB STARS
     IF X=2 THEN GOSUB BLANK
     GOSUB MESSAGE
     GOTO START
     
     
// "STARS" fills the screen with stars
STARS:
     FOR I=1 TO 24
     CALL HCHAR(I,1,42,32)
     NEXT I
     RETURN
 
 SNIP
 
Code Out:
 
 

100 CALL CLEAR:: CALL SCREEN(9) :: X=0
110 GOSUB 250
120 GOSUB 270
130 IF X=1 THEN GOSUB 170
140 IF X=2 THEN GOSUB 210
SNIP
250 DISPLAY AT(24,5):"CLICK A BUTTON";
260 RETURN
270 CALL KEY(0,K,S) :: IF S<1 THEN 270
280 X=X+1 :: IF X>2 THEN X=1
290 RETURN

 
 

OK, that's making more sense to me because what you input is XB specific as far as commands, and I get structure - similar to how batch files are written in dos. Alright I may be able to use tidbit at some moment after all. When I have time to play around.

Link to comment
Share on other sites

 

There nothing to say against that. You could have two subprograms with a common routine both are sharing. You could then either pack that into another subroutine that you can CALL, or you GOSUB there.

 

You can GOSUB out of a sub program and execute code from within another subprogram or the main program, provided you do not use variables. You can GOTO and GOSUB into the main program with similar restrictions. You can even turn off prescan to trick the interpreter into accepting things like combining FOR..NEXT loops and IF..THEN statements. Good practices? Probably not ;)

  • Like 1
Link to comment
Share on other sites

It's temporary. I feel like this game is more of a prototype and I want to see it through. I'm just slapping it together. I never really though it could evolve in to what it is becoming. So once I know I can do it, I'll go back and do it better.

Edited by Sinphaltimus
Link to comment
Share on other sites

This is all great stuff. Before I can go just using subprograms, I better learn all the ins and outs first. I can't slowly convert my program. I'm running out of memory and I bet it's because of gosubbing out of subprograms with variables involved.

So, back to my gosubs for now.

There's gold in this topic.

Link to comment
Share on other sites

 

You can GOSUB out of a sub program and execute code from within another subprogram or the main program, provided you do not use variables. You can GOTO and GOSUB into the main program with similar restrictions. You can even turn off prescan to trick the interpreter into accepting things like combining FOR..NEXT loops and IF..THEN statements. Good practices? Probably not ;)

No! Don't do it! That would be utterly evil and guarantee you a place in hell. If two subs share some common code then make that common code a sub and CALL it, don't branch to it with a goto or gosub. I'm going to have nightmares about this tonight ;-)

  • Like 2
Link to comment
Share on other sites

I jumped the gun and delved straight in to sudprograms street about 80 of ny current project was written. With a complete understanding of it and preplanning, it quickly became a nightmare.

 

So for the time being, I'm writing the rest as I started it, spaghetti code, bloat and all.

 

I'll optimize as need until all core game Britannica are in place and working.

 

At that time, I will take the time and plan the rewrite properly.

 

I absolutely want to recompile with xb257 (maybe I got the name wrong) and then create a bin for fr99. I am aware of some

Considerations line my if/then/else statements and the compiler.

 

Are there other things I have to keep in mind if I want the recompile to work for me in regards to subprograms and the like?

Link to comment
Share on other sites

The compiler is one thing. XB256 is another. You can use XB256 to create your program and then compile it, IF your program conforms to the compiler's format requirements. XB256 is a pretty amazing piece of kit. :) as is the compiler.

 

 

 

If you plan to compile, do yourself a favor and start reworking your code now to fit the compiler format. It is really tough to go backwards.

  • Like 1
Link to comment
Share on other sites

You can add and insert as many pieces as you want to a section of code... No worries about line numbers or resequencing to fit more code in, etc. Just point the program to a label and it will translate all your free-form code into line numbers. Look at the example I posted. TIdBiT did not change any of my code... Just assigned it line numbers. :)

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...