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.
Also: The quotes are like half of this program
Hope this helps!
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 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