21tmccauley wrote:
Will outputting a character where something already is cause a domain error? That is the only thing that I can think about for why my program is giving an error:DOMAIN. Thanks.


Nope! If you are drawing something at a position that is off of the screen, or isn't a whole, positive integer, then you will get the error.
_iPhoenix_ wrote:
21tmccauley wrote:
Will outputting a character where something already is cause a domain error? That is the only thing that I can think about for why my program is giving an error:DOMAIN. Thanks.


Nope! If you are drawing something at a position that is off of the screen, or isn't a whole, positive integer, then you will get the error.

Thanks. Now that crosses off one potential cause for the bug. Would any of this code allow for a negative integer? I thought I programmed it so that it wouldn't allow negative outputs.

Code:

randInt(1,10)->R
   If R<5
   Then
      randInt(1,4)->Z
      If Z=1 and (H+1!=26) and (G+1!=10) and (G-1!=1) and (H-1!=1)
      // Move up enemy
      Then
         Output(G,H,"
         G-1->G
         Output(G,H,"+
      End
      If Z=2 and (H+1!=26) and (G+1!=10) and (G-1!=1) and (H-1!=1)
      // Move Down enemy
      Then
         Output(G,H,"
         G+1->G
         Output(G,H,"+
      End
      If Z=3 and (H+1!=26) and (G+1!=10) and (G-1!=1) and (H-1!=1)
      // Move left enemy
      Then
         Output(G,H,"
         H-1->H
         Output(G,H,"+
      End
      If Z=4 and (H+1!=26) and (G+1!=10) and (G-1!=1) and (H-1!=1)
      // Move Right enemy
      Then
         Output(G,H,"
         H+1->H
         Output(G,H,"+
      End


EDIT
I added an additional condition that would only allow for a positive number, and that leads to it not outputting anything. Whiles this obviously means it is somehow changing either G or H to a negative number, which is leading to the domain errors.
I think this is where the error is coming from
NEW CODE:

Code:

Repeat G=45
   getKey->G
   randInt(1,10)->R
   If R<5
   Then
      randInt(1,4)->Z
      If Z=1 and (H+1!=26) and (G+1!=10) and (G-1!=1) and (H-1!=1) and (G!=abs(int(G)
      // Move up enemy
      Then
         Output(G,H,"
         G-1->G
         Output(G,H,"+
      End
      If Z=2 and (H+1!=26) and (G+1!=10) and (G-1!=1) and (H-1!=1) and (G!=abs(int(G)
      // Move Down enemy
      Then
         Output(G,H,"
         G+1->G
         Output(G,H,"+
      End
      If Z=3 and (H+1!=26) and (G+1!=10) and (G-1!=1) and (H-1!=1) and (H!=abs(int(H)
      // Move left enemy
      Then
         Output(G,H,"
         H-1->H
         Output(G,H,"+
      End
      If Z=4 and (H+1!=26) and (G+1!=10) and (G-1!=1) and (H-1!=1) and (H!=abs(int(H)
      // Move Right enemy
      Then
         Output(G,H,"
         H+1->H
         Output(G,H,"+
      End
      If G=45
      Output(D,C,*
      If G=24
      // Move left player
      Then
         Output(D,C,"
         C-1->C
         Output(D,C,"*
      End
      If G=25
      // Move Up player
      Then
         Output(D,C,"
         D-1->D
         Output(D,C,"*
      End
      If G=26
      // Move Right player
      Then
         Output(D,C,"
         C+1->C
         Output(D,C,"*
      End
      If G=34
      // Move Down Player
      Then
         Output(D,C,"
         D+1->D
         Output(D,C,"*
      End
21tmccauley wrote:
_iPhoenix_ wrote:
21tmccauley wrote:
Will outputting a character where something already is cause a domain error? That is the only thing that I can think about for why my program is giving an error:DOMAIN. Thanks.


Nope! If you are drawing something at a position that is off of the screen, or isn't a whole, positive integer, then you will get the error.

Thanks. Now that crosses off one potential cause for the bug. Would any of this code allow for a negative integer? I thought I programmed it so that it wouldn't allow negative outputs.

Code:

randInt(1,10)->R
   If R<5
   Then
      randInt(1,4)->Z
      If Z=1 and (H+1!=26) and (G+1!=10) and (G-1!=1) and (H-1!=1)
      // Move up enemy
      Then
         Output(G,H,"
         G-1->G
         Output(G,H,"+
      End
      If Z=2 and (H+1!=26) and (G+1!=10) and (G-1!=1) and (H-1!=1)
      // Move Down enemy
      Then
         Output(G,H,"
         G+1->G
         Output(G,H,"+
      End
      If Z=3 and (H+1!=26) and (G+1!=10) and (G-1!=1) and (H-1!=1)
      // Move left enemy
      Then
         Output(G,H,"
         H-1->H
         Output(G,H,"+
      End
      If Z=4 and (H+1!=26) and (G+1!=10) and (G-1!=1) and (H-1!=1)
      // Move Right enemy
      Then
         Output(G,H,"
         H+1->H
         Output(G,H,"+
      End


EDIT
I added an additional condition that would only allow for a positive number, and that leads to it not outputting anything. Whiles this obviously means it is somehow changing either G or H to a negative number, which is leading to the domain errors.
I think this is where the error is coming from
NEW CODE:

Code:

Repeat G=45
   getKey->G
   randInt(1,10)->R
   If R<5
   Then
      randInt(1,4)->Z
      If Z=1 and (H+1!=26) and (G+1!=10) and (G-1!=1) and (H-1!=1) and (G!=abs(int(G)
      // Move up enemy
      Then
         Output(G,H,"
         G-1->G
         Output(G,H,"+
      End
      If Z=2 and (H+1!=26) and (G+1!=10) and (G-1!=1) and (H-1!=1) and (G!=abs(int(G)
      // Move Down enemy
      Then
         Output(G,H,"
         G+1->G
         Output(G,H,"+
      End
      If Z=3 and (H+1!=26) and (G+1!=10) and (G-1!=1) and (H-1!=1) and (H!=abs(int(H)
      // Move left enemy
      Then
         Output(G,H,"
         H-1->H
         Output(G,H,"+
      End
      If Z=4 and (H+1!=26) and (G+1!=10) and (G-1!=1) and (H-1!=1) and (H!=abs(int(H)
      // Move Right enemy
      Then
         Output(G,H,"
         H+1->H
         Output(G,H,"+
      End
      If G=45
      Output(D,C,*
      If G=24
      // Move left player
      Then
         Output(D,C,"
         C-1->C
         Output(D,C,"*
      End
      If G=25
      // Move Up player
      Then
         Output(D,C,"
         D-1->D
         Output(D,C,"*
      End
      If G=26
      // Move Right player
      Then
         Output(D,C,"
         C+1->C
         Output(D,C,"*
      End
      If G=34
      // Move Down Player
      Then
         Output(D,C,"
         D+1->D
         Output(D,C,"*
      End

You don't have to use this code, but it is the best help I can give right now.
NOTE: var=x returns 1 if var=x (true) and 0 if var≠x (false). The same is true with any inequality or If statement, so 1>2 returns 0, and 1<2 returns 1.

Code:

0→K
1→X //it really could be anything from 1 to 10
1→Y // it really could be anything from 1 to 26
10→D //it really could be anything from 1 to 10
26→E // it really could be anything from 1 to 26
Repeat K=45
Output(Y,X,"*" // put player
Output(D,E,"+" //put enemy
Repeat K:getKey→K:End //I usually put this one one line, but you dont have to :P
Output(Y,X," " // erase player
Output(Y,X," " // erase player
If RandInt(1,10)<5  //you don't need an extra variable if you will only use it once.
RandInt(1,4→R //you need a variable here so that it doesn't change through the next two lines
min(max(D+(R=4)-(R=3),1),26→D
//If R=4, then add one (up). If R=3, then subtract one (down).
//max gets the maximum of X and 1, so If X<1, then it returns 1.
//min gets the minimum of X and 26, so If X>26, then it returns 26.
min(max(E+(R=1)-(R=2),1),10→E
//If R=1, then add one (right). If R=2, then subtract one (left).
//max gets the maximum of X and 1, so If X<1, then it returns 1.
//min gets the minimum of X and 10, so If X>10, then it returns 10.
End
min(max(X+(K=26)-(K=24),1),26→X
//if K=26, add one to X. If K=24, subtract one from X.
min(max(Y+(K=34)-(K=25),1),10→Y
//if K=34, add one to Y. If K=25, subtract one from Y.
End

It may look large at first, but coding should be a lot easier with quotes. Wink
Also: The quotes are like half of this program Razz
Hope this helps! Smile
EDIT:
P.S. A better algorithm for enemies is one that goes in the direction of the player, so:
(This code can be put in place of the movement randomization)

Code:

min(max(D+min(max(X-D,-1),1),1),26→D
min(max(E+min(max(Y-E,-1),1),1),10→E

As long as there are no walls Razz this will work.
Altogether:

Code:

0→K
1→X
1→Y
10→D
26→E
Repeat K=45
Output(Y,X,"*"
Output(D,E,"+"
Repeat K:getKey→K:End
Output(Y,X," "
Output(Y,X," "
D+min(max(X-D,-1),1→D
E+min(max(Y-E,-1),1→E
min(max(X+(K=26)-(K=24),1),26→X
min(max(Y+(K=34)-(K=25),1),10→Y
End
P.S. A better algorithm for enemies is one that goes in the direction of the player, so:
(This code can be put in place of the movement randomization)

Code:

min(max(D+min(max(X-D,-1),1),1),26→D
min(max(E+min(max(Y-E,-1),1),1),10→E

As long as there are no walls Razz this will work.
Altogether:

Code:

0→K
1→X
1→Y
10→D
26→E
Repeat K=45
Output(Y,X,"*"
Output(D,E,"+"
Repeat K:getKey→K:End
Output(Y,X," "
Output(Y,X," "
D+min(max(X-D,-1),1→D
E+min(max(Y-E,-1),1→E
min(max(X+(K=26)-(K=24),1),26→X
min(max(Y+(K=34)-(K=25),1),10→Y
End
[/quote]
Thanks soo much for this. It really helped shorten and clear up my program. It is already working better. Good Idea
EDIT: Do I need to put any number in the min and max lines, because right now it is giving me an error when I try to export it.
Next time you should just say thank you Wink. The code is pretty irrelevant to what you're saying. (You could also shorten the quote Wink)
  
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 2 of 2
» 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