So I'm having trouble with this multiplayer turned based BASIC program. I'm trying to make it so that each player selects an action from the menu and the selection is stored as the A variable for Calc 1's choice and the B variable for Calc 2's choice.

I started off by making the menu appear for Calc 1 and a waiting screen for Calc 2 until Calc 1 makes a selection.


Code:

DelVar A:DelVar B
GetCalc(θ
e(θ=π)+π(θ≠π→θ

ClrHome
If θ=π:Menu("CALC1","ATTACK",1A,"DEFEND",1D,"SKIP",1S

If θ=e
Then
Disp "WAITING...
While A=0
GetCalc(A
End

Lbl 1A: A→1:Goto 1θ

Lbl 1D: A→2:Goto 1θ

Lbl 1S: A→3:Goto 1θ

Lbl 1θ


Works great; both Calculator's A variables are the same (although Calc 1 experiences some major lag in the menu. If anyone knows a solution to that, that would help too).

Since this worked, I figured I could just copy the code and adjust it in order to use it for Calc 2's turn.


Code:

ClrHome
If θ=π:Menu("CALC1","ATTACK",1A,"DEFEND",1D,"SKIP",1S

If θ=e
Then
Disp "WAITING...
While A=0
GetCalc(A
End

Lbl 1A: A→1:Goto 1θ

Lbl 1D: A→2:Goto 1θ

Lbl 1S: A→3:Goto 1θ

Lbl 1θ
ClrHome
If θ=e:Menu("CALC2","ATTACK",2A,"DEFEND",2D,"SKIP",2S

If θ=π
Then
Disp "WAITING...
While B=0
GetCalc(B
End

Lbl 2A: B→1:Goto 2θ

Lbl 2D: B→2:Goto 2θ

Lbl 2S: B→3:Goto 2θ

Lbl 2θ


However, now Calc 2 never gets Calc 1's A, keeping Calc 2 stuck in its while loop. I tried deleting the A and B variables at the beginning of Lbl 1θ, but that didn't seem to have any effect.

I feel like there is a simple answer for this and I'm just not seeing it. Or maybe I need to do the waiting part in a different way.
I always love the wonky code structures that result from trying to do proper multiplayer in basic Razz
Flyer_95 wrote:
(although Calc 1 experiences some major lag in the menu. If anyone knows a solution to that, that would help too).

Unfortunately, there isn't anything you can do in pure basic to help this, because getCalc is really slow and laggy

First off, what is this supposed to do besides throw an error?

Code:
A→1

you should do the opposite like this:

Code:
1→A

Next up, when you use a loop, you always need an End statement after it, this isn't like If statements (or Java) where you can omit the braces if you only have one line. So this:

Code:
If θ=e
Then
Disp "WAITING...
While A=0
GetCalc(A
End

should be this:

Code:
If θ=e
Then
Disp "WAITING...
While A=0
GetCalc(A
End
End

Now, when the waiting calc exits the loop (once the other player has selected an option), the program should take the calc to the next label, which is either 1A or 2A depending on which calc was waiting. It will then set either A or B to 1, on the waiting calc after every turn, which is not desirable, so you should add a goto after the waiting if so that the waiting calculator skips the label area after the opponent has made a selection. The label area should then look like this:

Code:

If θ=e
Goto 1θ
Lbl 1A: 1→A:Goto 1θ

Lbl 1D: 2→A:Goto 1θ

Lbl 1S: 3→A:Goto 1θ

Note that I added a new If, rather than putting the goto in the first If, to prevent a memory leak.
Then simply do the same for the 2nd part, and you should be good to go.
Implemented the changes and it worked great! I also had to remove the DelVar A and DelVar B and replace them with 0 -> A and 0 -> B.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement